Skip to content

Commit

Permalink
Update UI to pull medication status from test-ehr not pharmacy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Virgulto committed Feb 12, 2024
1 parent 00a2fef commit 8120fc9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 220 deletions.
60 changes: 12 additions & 48 deletions src/views/Patient/MedReqDropDown/MedReqDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RefreshIcon from '@mui/icons-material/Refresh';
import Box from '@mui/material/Box';
import ListIcon from '@mui/icons-material/List';
import LocalPharmacyIcon from '@mui/icons-material/LocalPharmacy';
import { BundleEntry, Patient, MedicationRequest, Practitioner, Resource } from 'fhir/r4';
import { BundleEntry, Patient, MedicationRequest, Practitioner, Resource, MedicationDispense } from 'fhir/r4';
import Client from 'fhirclient/lib/Client';
import { ReactElement, useEffect, useState } from 'react';
import example from '../../../cds-hooks/prefetch/exampleHookService.json'; // TODO: Replace with request to CDS service
Expand All @@ -43,7 +43,6 @@ import sendRx from './rxSend/rxSend';
import axios from 'axios';
import MetRequirements from './etasuStatus/MetRequirements';
import RemsMetEtasuResponse from './etasuStatus/RemsMetEtasuResponse';
import DoctorOrder from './pharmacyStatus/DoctorOrder';

interface MedReqDropDownProps {
client: Client;
Expand Down Expand Up @@ -84,7 +83,7 @@ function MedReqDropDown({
const [checkedEtasuTime, setCheckedEtasuTime] = useState(0);
// Pharmacy
const [showPharmacy, setShowPharmacy] = useState<boolean>(false);
const [pimsResponse, setPimsResponse] = useState<DoctorOrder | null>(null);
const [testEhrResponse, setTestEhrResponse] = useState<BundleEntry<MedicationDispense> | null>(null);
const [checkedPharmacyTime, setCheckedPharmacyTime] = useState(0);
const [sendRxEnabled, setSendRxEnabled] = useState<boolean>(false);

Expand Down Expand Up @@ -208,47 +207,16 @@ function MedReqDropDown({
return `Last checked ${prefix} ago`;
};
const refreshPharmacyBundle = () => {
// setSpin(true);
const patientFirstName = patient?.name?.at(0)?.given?.at(0);
const patientLastName = patient?.name?.at(0)?.family;
const patientDOB = patient?.birthDate;
const rxDate = selectedMedicationCard?.authoredOn;
setCheckedPharmacyTime(Date.now());
let drugCodeableConcept = undefined;
if (selectedMedicationCard) {
drugCodeableConcept = getDrugCodeableConceptFromMedicationRequest(selectedMedicationCard);
}
const drugNames = drugCodeableConcept?.coding?.at(0)?.display;
console.log(
'refreshPharmacyBundle: ' +
patientFirstName +
' ' +
patientLastName +
' - ' +
patientDOB +
' - ' +
rxDate +
' - ' +
drugNames
);
const ndcDrugCoding = drugCodeableConcept?.coding?.find(
({ system }) => system === 'http://hl7.org/fhir/sid/ndc'
);
let queryString: string =
'rxDate=' + rxDate + '&drugNames=' + encodeURIComponent(drugNames || '');
if (ndcDrugCoding != undefined) {
queryString = queryString + '&drugNdcCode=' + ndcDrugCoding?.code;
}
const pharmacyUrl = `${env
.get('REACT_APP_PHARMACY_SERVER_BASE')
.asString()}/doctorOrders/api/getRx/${patientFirstName}/${patientLastName}/${patientDOB}?${queryString}`;
console.log(pharmacyUrl);
const rxId = selectedMedicationCard?.id;

const url = `${env.get('REACT_APP_DEFAULT_ISS').asString()}/MedicationDispense?prescription=${rxId}`;
axios({
method: 'get',
url: pharmacyUrl
url: url
}).then(
response => {
setPimsResponse(response.data);
setTestEhrResponse(response?.data?.entry ? response?.data?.entry[0] : null);
},
error => {
console.log(error);
Expand Down Expand Up @@ -343,14 +311,10 @@ function MedReqDropDown({
} else if (remsAdminResponse?.status === 'Pending') {
color = '#f0ad4e'; // orange
}
const pStatus = pimsResponse?.dispenseStatus;
let pColor = '#0c0c0c'; // white
if (pStatus === 'Approved') {
const pStatus = testEhrResponse?.resource?.status;
let pColor = '#0c0c0c'; // black
if (pStatus === 'completed') {
pColor = '#5cb85c'; // green
} else if (pStatus === 'Pending') {
pColor = '#f0ad4e'; // orange
} else if (pStatus === 'Picked Up') {
pColor = '#0275d8'; // blue
}

const etasuSx = {
Expand Down Expand Up @@ -462,7 +426,7 @@ function MedReqDropDown({
<div>
<LocalPharmacyIcon fontSize="large" />
<p className="etasuButtonText">Pharmacy: </p>
<p>{pimsResponse?.dispenseStatus || 'Not Started'}</p>
<p>{testEhrResponse?.resource?.status || 'Not Started'}</p>
</div>
</Button>
{renderTimestamp(checkedPharmacyTime)}
Expand Down Expand Up @@ -504,7 +468,7 @@ function MedReqDropDown({
<Box sx={modal_style}>
<PharmacyStatus
callback={refreshPharmacyBundle}
pimsResponse={pimsResponse}
testEhrResponse={testEhrResponse}
update={showPharmacy}
/>
</Box>
Expand Down
22 changes: 7 additions & 15 deletions src/views/Patient/MedReqDropDown/pharmacyStatus/PharmacyStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { Tooltip, IconButton, Grid } from '@mui/material';
import AutorenewIcon from '@mui/icons-material/Autorenew';

import { MedicationRequest, Patient } from 'fhir/r4';
import { BundleEntry, MedicationDispense } from 'fhir/r4';

import axios from 'axios';
import { useState, useEffect } from 'react';

import './PharmacyStatus.css';
import DoctorOrder from './DoctorOrder';
import { getDrugCodeableConceptFromMedicationRequest } from '../../../Questionnaire/questionnaireUtil';
import * as env from 'env-var';

interface PharmacyStatusProps {
callback: () => void;
pimsResponse: DoctorOrder | null;
testEhrResponse: BundleEntry<MedicationDispense> | null;
update: boolean;
}

Expand All @@ -26,14 +22,10 @@ const PharmacyStatus = (props: PharmacyStatusProps) => {
}
}, [props.update]);

const status = props.pimsResponse?.dispenseStatus;
let color = '#f7f7f7'; // white
if (status === 'Approved') {
const status = props.testEhrResponse?.resource?.status;
let color = '#0c0c0c'; // black
if (status === 'completed') {
color = '#5cb85c'; // green
} else if (status === 'Pending') {
color = '#f0ad4e'; // orange
} else if (status === 'Picked Up') {
color = '#0275d8'; // blue
}

return (
Expand All @@ -42,8 +34,8 @@ const PharmacyStatus = (props: PharmacyStatusProps) => {
<div className="status-icon" style={{ backgroundColor: color }}></div>
<Grid container columns={12}>
<Grid item xs={10}>
<div className="bundle-entry">ID: {props.pimsResponse?._id || 'N/A'}</div>
<div className="bundle-entry">Status: {props.pimsResponse?.dispenseStatus || 'N/A'}</div>
<div className="bundle-entry">ID: {props.testEhrResponse?.resource?.id|| 'N/A'}</div>
<div className="bundle-entry">Status: {props.testEhrResponse?.resource?.status || 'N/A'}</div>
</Grid>
<Grid item xs={2}>
<div className="bundle-entry">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,102 +1,43 @@
import { fireEvent, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Patient, MedicationRequest } from 'fhir/r4';
import nock from 'nock';
import { MedicationDispense, BundleEntry } from 'fhir/r4';

import PharmacyStatus from '../PharmacyStatus';
import DoctorOrder from '../DoctorOrder';
import MetRequirements from '../../etasuStatus/MetRequirements';

const pharmacy_server_base = 'http://localhost:5051';

const testPatient: Patient = {
resourceType: 'Patient',
id: 'pat017',
gender: 'male',
birthDate: '1996-06-01',
name: [
{
use: 'official',
family: 'Snow',
given: ['Jon', 'Stark']
}
]
};

const testMedicationRequest: MedicationRequest = {
resourceType: 'MedicationRequest',
id: 'pat017-mr-IPledge',
medicationCodeableConcept: {
coding: [
{
system: 'http://www.nlm.nih.gov/research/umls/rxnorm',
code: '6064',
display: 'Isotretinoin 20 MG Oral Capsule'
},
{
system: 'http://hl7.org/fhir/sid/ndc',
code: '0245-0571-01'
}
const testMedicationDispense: BundleEntry<MedicationDispense> = {
'resource': {
'resourceType': 'MedicationDispense',
'id': 'pat017-mr-turalio-dispense',
'meta': {
'versionId': '4',
'lastUpdated': '2024-02-08T16:02:57.850+00:00',
'source': '#pat017-mr-turali'
},
'status': 'completed',
'medicationCodeableConcept': {
'coding': [
{
'system': 'http://www.nlm.nih.gov/research/umls/rxnorm',
'code': '2183126',
'display': 'Turalio 200 MG Oral Capsule'
},
{
'system': 'http://hl7.org/fhir/sid/ndc',
'code': '65597-402-20'
}
]
},
'subject': {
'reference': 'Patient/pat017',
'display': 'Jon Snow'
},
'authorizingPrescription': [
{
'reference': 'MedicationRequest/pat017-mr-turalio'
}
]
},
status: 'active',
intent: 'order',
subject: {
reference: 'Patient/pat017',
display: 'Jon Snow'
},
authoredOn: '2020-07-11'
};

const generateDoctorOrder = () => {
const patientEnrollmentForm: MetRequirements = {
completed: true,
metRequirementId: 'asldkf23a',
requirementDescription: 'Submit Patient Enrollment form to the REMS Administrator',
requirementName: 'Patient Enrollment Form',
stakeholderId: 'dlksk2222'
};
const prescriberEnrollmentForm: MetRequirements = {
completed: false,
metRequirementId: 'asldkf23b',
requirementDescription: 'Submit Prescriber Enrollment form to the REMS Administrator',
requirementName: 'Prescriber Enrollment Form',
stakeholderId: 'dlksk2222'
};
const pharmacistEnrollmentForm: MetRequirements = {
completed: true,
metRequirementId: 'asldkf23c',
requirementDescription: 'Submit Pharmacist Enrollment form to the REMS Administrator',
requirementName: 'Pharmacist Enrollment Form',
stakeholderId: 'dlksk2222'
};
const doctorOrder: DoctorOrder = {
_id: '1234',
caseNumber: '2k3js',
patientName: 'Jon Snow',
patientFirstName: 'Jon',
patientLastName: 'Snow',
patientDOB: '1996-06-01',
patientCity: 'Winterfell',
patientStateProvince: 'Westeros',
patientPostalCode: '00008',
patientCountry: 'USA',
doctorName: 'Dr. Jane Doe',
doctorContact: '555-123-4567',
doctorID: 'sdk2kd991',
doctorEmail: '[email protected]',
drugNames: 'Medication',
simpleDrugName: 'Medication',
rxDate: '2023-03-04',
drugPrice: 35,
drugNdcCode: '0245-0571-01',
quanitities: '20',
total: 1,
pickupDate: '2023-04-04',
dispenseStatus: 'Pending',
metRequirements: [patientEnrollmentForm, prescriberEnrollmentForm, pharmacistEnrollmentForm]
};
return doctorOrder;
}
};
describe('Test the PharmacyStatus Component', () => {
function expectContains(value: string) {
Expand All @@ -108,7 +49,7 @@ describe('Test the PharmacyStatus Component', () => {
const update = false;

// render the module
render(<PharmacyStatus update={update} callback={() => {}} pimsResponse={null} />);
render(<PharmacyStatus update={update} callback={() => {}} testEhrResponse={null} />);

// test the status fields and headings are present
expectContains('Pharmacy Status');
Expand All @@ -120,11 +61,10 @@ describe('Test the PharmacyStatus Component', () => {
expect(refreshButton).toBeInTheDocument();
});
test('Renders order', async () => {
const doctorOrder = generateDoctorOrder();
render(<PharmacyStatus update={false} callback={() => {}} pimsResponse={doctorOrder} />);
render(<PharmacyStatus update={false} callback={() => {}} testEhrResponse={testMedicationDispense} />);

expect(await screen.findByText(`ID: ${doctorOrder._id}`)).toBeInTheDocument();
expect(await screen.findByText(`Status: ${doctorOrder.dispenseStatus}`)).toBeInTheDocument();
expect(await screen.findByText(`ID: ${testMedicationDispense.resource?.id}`)).toBeInTheDocument();
expect(await screen.findByText(`Status: ${testMedicationDispense.resource?.status}`)).toBeInTheDocument();
});

test('Loads data on start', () => {
Expand All @@ -134,7 +74,7 @@ describe('Test the PharmacyStatus Component', () => {
pimsResponse = true;
};
// render the module
render(<PharmacyStatus update={update} callback={callback} pimsResponse={null} />);
render(<PharmacyStatus update={update} callback={callback} testEhrResponse={null} />);
// verify that the values are updated from the call to get the Pharmacy Status
expect(pimsResponse).toBeTruthy();
});
Expand All @@ -146,7 +86,7 @@ describe('Test the PharmacyStatus Component', () => {
called = true;
};
// render the module
render(<PharmacyStatus update={update} callback={callback} pimsResponse={null} />);
render(<PharmacyStatus update={update} callback={callback} testEhrResponse={null} />);

// click the refresh button
const refreshButton = screen.getByTestId('refresh');
Expand All @@ -159,7 +99,7 @@ describe('Test the PharmacyStatus Component', () => {
test('Failed to load status', async () => {
const update = true;
// render the module
render(<PharmacyStatus update={update} callback={() => {}} pimsResponse={null} />);
render(<PharmacyStatus update={update} callback={() => {}} testEhrResponse={null} />);

// click the refresh button
const refreshButton = screen.getByTestId('refresh');
Expand Down
Loading

0 comments on commit 8120fc9

Please sign in to comment.