Skip to content

Commit

Permalink
Merge pull request #72 from mcode/598-dispense-status
Browse files Browse the repository at this point in the history
598 dispense status
  • Loading branch information
plarocque4 authored Feb 16, 2024
2 parents 8b51b6f + ebc0fde commit 80c9e39
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 239 deletions.
88 changes: 35 additions & 53 deletions src/views/Patient/MedReqDropDown/MedReqDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ 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
import { hydrate } from '../../../cds-hooks/prefetch/PrefetchHydrator';
import { Hook, Card as HooksCard, OrderSelectHook } from '../../../cds-hooks/resources/HookTypes';
import OrderSelect from '../../../cds-hooks/resources/OrderSelect';
import {
getDrugCodeFromMedicationRequest,
getDrugCodeableConceptFromMedicationRequest
} from '../../Questionnaire/questionnaireUtil';
import { getDrugCodeFromMedicationRequest } from '../../Questionnaire/questionnaireUtil';
import './MedReqDropDown.css';
import * as env from 'env-var';
import { MedicationBundle, submitToREMS } from '../PatientView';
Expand All @@ -43,7 +47,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 +87,9 @@ 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 +213,18 @@ 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 +319,20 @@ 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;
const getMedicationStatus = (status: string | undefined) => {
if (status === 'completed') {
return 'Picked Up';
} else if (status === 'unknown') {
return 'Not Started';
} else {
return 'N/A';
}
};
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 @@ -461,8 +443,8 @@ function MedReqDropDown({
>
<div>
<LocalPharmacyIcon fontSize="large" />
<p className="etasuButtonText">Pharmacy: </p>
<p>{pimsResponse?.dispenseStatus || 'Not Started'}</p>
<p className="etasuButtonText">Medication: </p>
<p>{getMedicationStatus(pStatus)}</p>
</div>
</Button>
{renderTimestamp(checkedPharmacyTime)}
Expand Down Expand Up @@ -504,7 +486,7 @@ function MedReqDropDown({
<Box sx={modal_style}>
<PharmacyStatus
callback={refreshPharmacyBundle}
pimsResponse={pimsResponse}
testEhrResponse={testEhrResponse}
update={showPharmacy}
/>
</Box>
Expand Down
35 changes: 18 additions & 17 deletions src/views/Patient/MedReqDropDown/pharmacyStatus/PharmacyStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { Tooltip, IconButton, Grid } from '@mui/material';
import AutorenewIcon from '@mui/icons-material/Autorenew';

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

import axios from 'axios';
import { BundleEntry, MedicationDispense } from 'fhir/r4';
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,24 +21,30 @@ const PharmacyStatus = (props: PharmacyStatusProps) => {
}
}, [props.update]);

const status = props.pimsResponse?.dispenseStatus;
let color = '#f7f7f7'; // white
if (status === 'Approved') {
const getMedicationStatus = (status: string | undefined) => {
if (status === 'completed') {
return 'Picked Up';
} else if (status === 'unknown') {
return 'Not Started';
} else {
return 'N/A';
}
};

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 (
<div>
<h1>Pharmacy Status</h1>
<h1>Medication Status</h1>
<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: {getMedicationStatus(status)}</div>
</Grid>
<Grid item xs={2}>
<div className="bundle-entry">
Expand Down
Loading

0 comments on commit 80c9e39

Please sign in to comment.