diff --git a/src/components/EtasuStatus/EtasuStatus.jsx b/src/components/EtasuStatus/EtasuStatus.jsx index aeda631..a9277e5 100644 --- a/src/components/EtasuStatus/EtasuStatus.jsx +++ b/src/components/EtasuStatus/EtasuStatus.jsx @@ -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 @@ -49,7 +49,7 @@ export const EtasuStatus = props => { return ( <> - {remsAdminResponse.contained ? ( + {remsAdminResponse?.contained ? ( { response: {}, submittedRx: false }); - const [globalState,] = useContext(SettingsContext); + const [globalState] = useContext(SettingsContext); const { prefetchedResources, @@ -56,7 +65,6 @@ const RequestBox = props => { } }, [prefetchCompleted]); - const renderPatientInfo = () => { if (Object.keys(patient).length === 0) { return
; @@ -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( diff --git a/src/util/util.js b/src/util/util.js index 73986e8..1e5a5d1 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -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). @@ -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); @@ -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]}`; @@ -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; } @@ -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