Skip to content

Commit

Permalink
Revert "Update UI to not check with pharmacy for status of medication"
Browse files Browse the repository at this point in the history
This reverts commit b1a856f.
  • Loading branch information
Ariel Virgulto committed Feb 12, 2024
1 parent b1a856f commit 8b51b6f
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 96 deletions.
66 changes: 47 additions & 19 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, MedicationDispense } from 'fhir/r4';
import { BundleEntry, Patient, MedicationRequest, Practitioner, Resource } 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,6 +43,7 @@ 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 @@ -83,7 +84,7 @@ function MedReqDropDown({
const [checkedEtasuTime, setCheckedEtasuTime] = useState(0);
// Pharmacy
const [showPharmacy, setShowPharmacy] = useState<boolean>(false);
const [testEhrResponse, setTestEhrResponse] = useState<BundleEntry<MedicationDispense> | null>(null);
const [pimsResponse, setPimsResponse] = useState<DoctorOrder | null>(null);
const [checkedPharmacyTime, setCheckedPharmacyTime] = useState(0);
const [sendRxEnabled, setSendRxEnabled] = useState<boolean>(false);

Expand Down Expand Up @@ -207,18 +208,47 @@ 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());
const rxId = selectedMedicationCard?.id;
console.log('selected medication card -- > ', rxId);

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

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

import { BundleEntry, MedicationDispense } from 'fhir/r4';
import { MedicationRequest, Patient } 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;
testEhrResponse: BundleEntry<MedicationDispense> | null;
pimsResponse: DoctorOrder | null;
update: boolean;
}

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

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

return (
Expand All @@ -34,8 +42,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.testEhrResponse?.resource?.id || 'N/A'}</div>
<div className="bundle-entry">Status: {props.testEhrResponse?.resource?.status || 'N/A'}</div>
<div className="bundle-entry">ID: {props.pimsResponse?._id || 'N/A'}</div>
<div className="bundle-entry">Status: {props.pimsResponse?.dispenseStatus || '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,43 +1,102 @@
import { fireEvent, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { MedicationDispense, BundleEntry } from 'fhir/r4';
import { Patient, MedicationRequest } from 'fhir/r4';
import nock from 'nock';

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

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

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'
}
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'
}
]
}
},
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 @@ -49,7 +108,7 @@ describe('Test the PharmacyStatus Component', () => {
const update = false;

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

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

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

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

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

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

0 comments on commit 8b51b6f

Please sign in to comment.