Skip to content

Commit

Permalink
Merge pull request #95 from mcode/rems-admin-lookup-table
Browse files Browse the repository at this point in the history
Send hook depending on medication & handle multiple REMS admins with patient-view hook
  • Loading branch information
plarocque4 authored May 23, 2024
2 parents ef3cfe9 + 3155775 commit f7d6ef1
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 41 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ REACT_APP_ETASU_STATUS_ENABLED = true
REACT_APP_PHARMACY_SERVER_BASE = http://localhost:5051
REACT_APP_PHARMACY_STATUS_ENABLED = true
REACT_APP_REMS_ADMIN_SERVER_BASE = http://localhost:8090
REACT_APP_REMS_HOOKS_PATH = /cds-services/rems-
REACT_APP_SEND_FHIR_AUTH_ENABLED = false
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Following are a list of modifiable paths:
| REACT_APP_PHARMACY_SERVER_BASE | `http://localhost:5051` |
| REACT_APP_PHARMACY_STATUS_ENABLED | `true` |
| REACT_APP_REMS_ADMIN_SERVER_BASE | `http://localhost:8090` |
| REACT_APP_REMS_HOOKS_PATH | `/cds-services/rems-` |
| REACT_APP_SEND_FHIR_AUTH_ENABLED | `false` |

_Note that .env values can only be accessed by the React app starting with `REACT_APP_`\_
Expand Down
2 changes: 1 addition & 1 deletion src/cds-hooks
92 changes: 92 additions & 0 deletions src/util/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { SupportedHooks } from '../cds-hooks/resources/HookTypes';

export const medicationRequestToRemsAdmins = Object.freeze([
{
rxnorm: 2183126,
display: 'Turalio 200 MG Oral Capsule',
hookEndpoints: [
{
hook: SupportedHooks.ORDER_SIGN,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-sign'
},
{
hook: SupportedHooks.ORDER_SELECT,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-select'
},
{
hook: SupportedHooks.PATIENT_VIEW,
remsAdmin: 'http://localhost:8090/cds-services/rems-patient-view'
},
{
hook: SupportedHooks.ENCOUNTER_START,
remsAdmin: 'http://localhost:8090/cds-services/rems-encounter-start'
}
]
},
{
rxnorm: 6064,
display: 'Isotretinoin 20 MG Oral Capsule',
hookEndpoints: [
{
hook: SupportedHooks.ORDER_SIGN,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-sign'
},
{
hook: SupportedHooks.ORDER_SELECT,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-select'
},
{
hook: SupportedHooks.PATIENT_VIEW,
remsAdmin: 'http://localhost:8090/cds-services/rems-patient-view'
},
{
hook: SupportedHooks.ENCOUNTER_START,
remsAdmin: 'http://localhost:8090/cds-services/rems-encounter-start'
}
]
},
{
rxnorm: 1237051,
display: 'TIRF 200 UG Oral Transmucosal Lozenge',
hookEndpoints: [
{
hook: SupportedHooks.ORDER_SIGN,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-sign'
},
{
hook: SupportedHooks.ORDER_SELECT,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-select'
},
{
hook: SupportedHooks.PATIENT_VIEW,
remsAdmin: 'http://localhost:8090/cds-services/rems-patient-view'
},
{
hook: SupportedHooks.ENCOUNTER_START,
remsAdmin: 'http://localhost:8090/cds-services/rems-encounter-start'
}
]
},
{
rxnorm: 1666386,
display: 'Addyi 100 MG Oral Tablet',
hookEndpoints: [
{
hook: SupportedHooks.ORDER_SIGN,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-sign'
},
{
hook: SupportedHooks.ORDER_SELECT,
remsAdmin: 'http://localhost:8090/cds-services/rems-order-select'
},
{
hook: SupportedHooks.PATIENT_VIEW,
remsAdmin: 'http://localhost:8090/cds-services/rems-patient-view'
},
{
hook: SupportedHooks.ENCOUNTER_START,
remsAdmin: 'http://localhost:8090/cds-services/rems-encounter-start'
}
]
}
]);
49 changes: 49 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { MedicationRequest } from 'fhir/r4';
import { SupportedHooks } from '../cds-hooks/resources/HookTypes';
import { getDrugCodeableConceptFromMedicationRequest } from '../views/Questionnaire/questionnaireUtil';
import { medicationRequestToRemsAdmins } from './data';

export const getMedicationSpecificRemsAdminUrl = (
request: MedicationRequest | undefined,
hook: SupportedHooks
) => {
// if empty request, just return
if (request && Object.keys(request).length === 0) {
return null;
}

const codeableConcept = getDrugCodeableConceptFromMedicationRequest(request);
const display = codeableConcept?.coding?.[0]?.display;
const rxnorm = codeableConcept?.coding?.[0]?.code;

if (!rxnorm) {
console.log("ERROR: unknown MedicationRequest code: '", rxnorm);
return null;
}

// This function never gets called with the PATIENT_VIEW hook, however.
if (
!(
hook === SupportedHooks.PATIENT_VIEW ||
hook === SupportedHooks.ORDER_SIGN ||
hook === SupportedHooks.ORDER_SELECT ||
hook === SupportedHooks.ENCOUNTER_START
)
) {
console.log(`ERROR: unknown hook type: ${hook}`);
return null;
}

const setting = medicationRequestToRemsAdmins.find(
value => Number(value.rxnorm) === Number(rxnorm)
);

const cdsUrl = setting?.hookEndpoints.find(endpoint => endpoint.hook === hook);

if (!cdsUrl) {
console.log(`Medication ${display} is not a REMS medication`);
return null;
}

return cdsUrl.remsAdmin;
};
39 changes: 21 additions & 18 deletions src/views/Patient/MedReqDropDown/MedReqDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ import EtasuStatus from './etasuStatus/EtasuStatus';
// Adding in Pharmacy
import PharmacyStatus from './pharmacyStatus/PharmacyStatus';
import axios from 'axios';
import { getMedicationSpecificRemsAdminUrl } from '../../../util/util';

interface MedReqDropDownProps {
client: Client;
getFhirResource: (token: string) => Promise<Resource>;
hooksCards: HooksCard[];
medication: MedicationBundle | null;
medicationBundle: MedicationBundle | null;
patient: Patient | null;
setHooksCards: React.Dispatch<React.SetStateAction<HooksCard[]>>;
tabCallback: (n: ReactElement, m: string, o: string) => void;
Expand All @@ -77,7 +78,7 @@ function MedReqDropDown({
client,
getFhirResource,
hooksCards,
medication,
medicationBundle,
patient,
setHooksCards,
tabCallback,
Expand All @@ -92,6 +93,7 @@ function MedReqDropDown({

//CDSHooks
const [cdsHook, setCDSHook] = useState<Hook | null>(null);
const [cdsUrl, setCDSUrl] = useState<string | null>(null);

//ETASU
const [showEtasu, setShowEtasu] = useState<boolean>(false);
Expand All @@ -106,7 +108,7 @@ function MedReqDropDown({

useEffect(() => {
if (cdsHook) {
submitToREMS(cdsHook, setHooksCards);
submitToREMS(cdsUrl, cdsHook, setHooksCards);
}
}, [cdsHook]);

Expand All @@ -126,7 +128,7 @@ function MedReqDropDown({
setShowPharmacy(false);
};

const [selectedMedicationCardBundle, setSelectedMedicationCardBundle] =
const [selectedMedicationCardBundleEntry, setSelectedMedicationCardBundleEntry] =
useState<BundleEntry<MedicationRequest>>();

const [selectedMedicationCard, setSelectedMedicationCard] = useState<MedicationRequest>();
Expand All @@ -136,7 +138,7 @@ function MedReqDropDown({
useEffect(() => {
if (selectedOption != '') {
setSelectedMedicationCard(
medication?.data.find(medication => medication.id === selectedOption)
medicationBundle?.data.find(medication => medication.id === selectedOption)
);
}
}, [selectedOption]);
Expand All @@ -148,23 +150,28 @@ function MedReqDropDown({
if (medName) {
setMedicationName(medName);
}
setSelectedMedicationCardBundle({ resource: selectedMedicationCard });
setSelectedMedicationCardBundleEntry({ resource: selectedMedicationCard });
}
}, [selectedMedicationCard]);

useEffect(() => {
if (patient && patient.id && user && selectedMedicationCardBundle) {
const resourceId = `${selectedMedicationCardBundle.resource?.resourceType}/${selectedMedicationCardBundle.resource?.id}`;
if (patient && patient.id && user && selectedMedicationCardBundleEntry) {
const request = selectedMedicationCardBundleEntry.resource;
const resourceId = `${request?.resourceType}/${request?.id}`;

const hook = new OrderSelect(
patient.id,
user,
{
resourceType: 'Bundle',
type: 'batch',
entry: [selectedMedicationCardBundle]
entry: [selectedMedicationCardBundleEntry]
},
[resourceId]
);
const cdsUrl = getMedicationSpecificRemsAdminUrl(request, hook.hookType);
setCDSUrl(cdsUrl);

let tempHook: OrderSelectHook;
if (env.get('REACT_APP_SEND_FHIR_AUTH_ENABLED').asBool()) {
tempHook = hook.generate(client);
Expand All @@ -175,7 +182,7 @@ function MedReqDropDown({
setCDSHook(tempHook);
});
}
}, [selectedMedicationCardBundle]);
}, [selectedMedicationCardBundleEntry]);

useEffect(() => {
refreshEtasuBundle();
Expand Down Expand Up @@ -329,13 +336,9 @@ function MedReqDropDown({
onChange={handleOptionSelect}
sx={{ '& #dropdown': { textWrap: 'wrap' } }}
>
{medication ? (
medication.data.map(medications => (
<MenuItem
key={medications.id}
value={medications.id}
sx={{ textWrap: 'wrap' }}
>
{medicationBundle ? (
medicationBundle.data.map(medications => (
<MenuItem key={medications.id} value={medications.id}>
{getDrugCodeFromMedicationRequest(medications)?.display}
</MenuItem>
))
Expand Down Expand Up @@ -381,7 +384,7 @@ function MedReqDropDown({
>
<IconButton
color="primary"
onClick={() => submitToREMS(cdsHook, setHooksCards)}
onClick={() => submitToREMS(cdsUrl, cdsHook, setHooksCards)}
size="large"
>
<RefreshIcon fontSize="large" />
Expand Down
Loading

0 comments on commit f7d6ef1

Please sign in to comment.