Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/EtasuStatus/EtasuStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect, useContext } from 'react';
import { SettingsContext } from '../../containers/ContextProvider/SettingsProvider.jsx';
import { EtasuStatusComponent } from './EtasuStatusComponent.jsx';
import { standardsBasedGetEtasu, getMedicationSpecificEtasuUrl } from '../../util/util.js';
import { createMedicationFromMedicationRequest, getDrugCodeableConceptFromMedicationRequest } from '../../util/fhir.js';
import { createMedicationFromMedicationRequest } from '../../util/fhir.js';

// converts code into etasu for the component to render
// simplifies usage for applications that only know the code, not the case they want to display
Expand Down Expand Up @@ -49,7 +49,7 @@ export const EtasuStatus = props => {

return (
<>
{remsAdminResponse.contained ? (
{remsAdminResponse?.contained ? (
<EtasuStatusComponent
remsAdminResponseInit={remsAdminResponse}
data={etasuData}
Expand Down
34 changes: 23 additions & 11 deletions src/components/RequestBox/RequestBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ import buildNewRxRequest from '../../util/buildScript.2017071.js';
import MuiAlert from '@mui/material/Alert';
import Snackbar from '@mui/material/Snackbar';
import { shortNameMap, ORDER_SIGN, PATIENT_VIEW } from '../../util/data.js';
import { getAge, createMedicationDispenseFromMedicationRequest, createMedicationFromMedicationRequest, getDrugCodeableConceptFromMedicationRequest } from '../../util/fhir.js';
import { retrieveLaunchContext, prepPrefetch, getMedicationSpecificEtasuUrl } from '../../util/util.js';
import {
getAge,
createMedicationDispenseFromMedicationRequest,
createMedicationFromMedicationRequest,
getDrugCodeableConceptFromMedicationRequest
} from '../../util/fhir.js';
import {
retrieveLaunchContext,
prepPrefetch,
getMedicationSpecificEtasuUrl
} from '../../util/util.js';
import './request.css';
import axios from 'axios';

Expand All @@ -17,7 +26,7 @@ const RequestBox = props => {
response: {},
submittedRx: false
});
const [globalState,] = useContext(SettingsContext);
const [globalState] = useContext(SettingsContext);

const {
prefetchedResources,
Expand Down Expand Up @@ -56,7 +65,6 @@ const RequestBox = props => {
}
}, [prefetchCompleted]);


const renderPatientInfo = () => {
if (Object.keys(patient).length === 0) {
return <div className="demographics"></div>;
Expand Down Expand Up @@ -214,26 +222,30 @@ const RequestBox = props => {
*/
const sendRx = async () => {
console.log('Sending NewRx to: ' + pimsUrl);
console.log('Getting auth number ')
console.log('Getting auth number ');
const medication = createMedicationFromMedicationRequest(request);
const body = makeBody(medication);
const standardEtasuUrl = getMedicationSpecificEtasuUrl(getDrugCodeableConceptFromMedicationRequest(request), globalState);
const standardEtasuUrl = getMedicationSpecificEtasuUrl(
getDrugCodeableConceptFromMedicationRequest(request),
globalState
);
let authNumber = '';
await axios({
method: 'post',
url: standardEtasuUrl,
data: body
}).then(
response => {
if (response.data.parameter[0].resource && response.data.parameter?.[0].resource.contained) {
}).then(response => {
if (
response.data.parameter?.[0].resource &&
response.data.parameter?.[0].resource.contained
) {
response.data.parameter?.[0].resource?.contained[0]?.parameter.map(metRequirements => {
if (metRequirements.name === 'auth_number') {
authNumber = metRequirements.valueString;
}
});
}
}
);
});

// build the NewRx Message
var newRx = buildNewRxRequest(
Expand Down
27 changes: 20 additions & 7 deletions src/util/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import axios from 'axios';
import { getDrugCodeableConceptFromMedicationRequest } from './fhir';
import { ORDER_SIGN, ORDER_SELECT, PATIENT_VIEW, ENCOUNTER_START, CDS_SERVICE, serviceEndpoints, REMS_ETASU } from './data';
import {
ORDER_SIGN,
ORDER_SELECT,
PATIENT_VIEW,
ENCOUNTER_START,
serviceEndpoints,
REMS_ETASU
} from './data';

/**
* Retrieves a SMART launch context from an endpoint to append as a "launch" query parameter to a SMART app launch URL (see SMART docs for more about launch context).
Expand Down Expand Up @@ -87,7 +94,7 @@ function standardsBasedGetEtasu(etasuUrl, body, responseCallback) {
return 0;
});
}
responseCallback(response.data.parameter[0].resource, body);
responseCallback(response.data.parameter?.[0].resource, body);
},
error => {
console.log('error -- > ', error);
Expand All @@ -96,7 +103,6 @@ function standardsBasedGetEtasu(etasuUrl, body, responseCallback) {
}

const getMedicationSpecificRemsAdminUrl = (codeableConcept, globalState, endpointType) => {

var serverUrl = null;
if (globalState.useIntermediary) {
serverUrl = `${globalState.intermediaryUrl}/${serviceEndpoints[endpointType]}`;
Expand All @@ -110,7 +116,15 @@ const getMedicationSpecificRemsAdminUrl = (codeableConcept, globalState, endpoin
}

// This function never gets called with the PATIENT_VIEW hook, however.
if (!(endpointType === PATIENT_VIEW || endpointType === ORDER_SIGN || endpointType === ORDER_SELECT || endpointType === ENCOUNTER_START || endpointType === REMS_ETASU)) {
if (
!(
endpointType === PATIENT_VIEW ||
endpointType === ORDER_SIGN ||
endpointType === ORDER_SELECT ||
endpointType === ENCOUNTER_START ||
endpointType === REMS_ETASU
)
) {
console.log(`ERROR: unknown hook/endpoint type: ${endpointType}`);
return undefined;
}
Expand All @@ -125,17 +139,16 @@ const getMedicationSpecificRemsAdminUrl = (codeableConcept, globalState, endpoin
}
}
return serverUrl;
}
};

const getMedicationSpecificEtasuUrl = (codeableConcept, globalState) => {

var serverUrl = getMedicationSpecificRemsAdminUrl(codeableConcept, globalState, REMS_ETASU);
if (serverUrl != undefined) {
return serverUrl;
} else {
return undefined;
}
}
};

const getMedicationSpecificCdsHooksUrl = (request, globalState, hook) => {
// if empty request, just return
Expand Down