Skip to content

Commit

Permalink
Merge pull request #86 from mcode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
smalho01 authored Apr 8, 2024
2 parents dd0e0b3 + 41a712e commit 266f9c0
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 550 deletions.
71 changes: 17 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
You can add web fonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
Expand Down
2 changes: 1 addition & 1 deletion src/cds-hooks
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import ReactDOM from 'react-dom/client';

import './index.css';
Expand Down
115 changes: 58 additions & 57 deletions src/views/Patient/MedReqDropDown/MedReqDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ 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, Resource, MedicationDispense } from 'fhir/r4';
import {
BundleEntry,
Patient,
MedicationRequest,
Resource,
MedicationDispense,
Parameters,
GuidanceResponse
} 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 Down Expand Up @@ -51,6 +59,22 @@ interface MedReqDropDownProps {
user: string | null;
}

export interface etasuStatus {
color: string;
display: string | undefined;
}
export function getStatus(etasuResource: GuidanceResponse | null | undefined): etasuStatus {
let color = '#0c0c0c'; // gray
let display;
if (etasuResource?.status === 'success') {
color = '#5cb85c'; // green
display = 'Approved';
} else if (etasuResource?.status === 'data-required') {
color = '#f0ad4e'; // orange
display = 'Pending';
}
return { color, display };
}
function MedReqDropDown({
client,
getFhirResource,
Expand All @@ -73,7 +97,7 @@ function MedReqDropDown({

//ETASU
const [showEtasu, setShowEtasu] = useState<boolean>(false);
const [remsAdminResponse, setRemsAdminResponse] = useState<RemsMetEtasuResponse | null>(null);
const [remsAdminResponse, setRemsAdminResponse] = useState<GuidanceResponse | null>(null);
const [checkedEtasuTime, setCheckedEtasuTime] = useState(0);
// Pharmacy
const [showPharmacy, setShowPharmacy] = useState<boolean>(false);
Expand Down Expand Up @@ -203,53 +227,35 @@ function MedReqDropDown({
};

const refreshEtasuBundle = () => {
// setSpin(true);
const patientFirstName = patient?.name?.at(0)?.given?.at(0);
const patientLastName = patient?.name?.at(0)?.family;
const patientDOB = patient?.birthDate;
let drugCode = undefined;
setCheckedEtasuTime(Date.now());
if (selectedMedicationCard) {
drugCode = getDrugCodeFromMedicationRequest(selectedMedicationCard)?.code;
}
console.log(
'refreshEtasuBundle: ' +
patientFirstName +
' ' +
patientLastName +
' - ' +
patientDOB +
' - ' +
drugCode
);
const etasuUrl = `${env
.get('REACT_APP_REMS_ADMIN_SERVER_BASE')
.asString()}/etasu/met/patient/${patientFirstName}/${patientLastName}/${patientDOB}/drugCode/${drugCode}`;

axios({
method: 'get',
url: etasuUrl
}).then(
response => {
// Sorting an array mutates the data in place.
const remsMetRes = response.data as RemsMetEtasuResponse;
if (remsMetRes.metRequirements) {
remsMetRes.metRequirements.sort((first: MetRequirements, second: MetRequirements) => {
// Keep the other forms unsorted.
if (second.requirementName.includes('Patient Status Update')) {
// Sort the Patient Status Update forms in descending order of timestamp.
return second.requirementName.localeCompare(first.requirementName);
}
return 0;
});
if (patient && selectedMedicationCard) {
setCheckedEtasuTime(Date.now());
const params: Parameters = {
resourceType: 'Parameters',
parameter: [
{
name: 'patient',
resource: patient
},
{
name: 'medication',
resource: selectedMedicationCard
}
]
};
axios({
method: 'post',
url: `${env
.get('REACT_APP_REMS_ADMIN_SERVER_BASE')
.asString()}/4_0_0/GuidanceResponse/$rems-etasu`,
data: params
}).then(res => {
const resParams = res.data as Parameters;
const etasu = resParams.parameter?.find(e => e.name === 'rems-etasu');
if (etasu && etasu.resource?.resourceType === 'GuidanceResponse') {
setRemsAdminResponse(etasu.resource);
}
console.log(response.data);
setRemsAdminResponse(response.data);
},
error => {
console.log(error);
}
);
});
}
};
const renderTimestamp = (checkedTime: number) => {
return (
Expand Down Expand Up @@ -283,12 +289,7 @@ function MedReqDropDown({
: false;

const label = 'Select Medication Request';
let color = '#0c0c0c'; // gray
if (remsAdminResponse?.status === 'Approved') {
color = '#5cb85c'; // green
} else if (remsAdminResponse?.status === 'Pending') {
color = '#f0ad4e'; // orange
}
const eStatus = getStatus(remsAdminResponse);

const pStatus = testEhrResponse?.resource?.status;
const getMedicationStatus = (status: string | undefined) => {
Expand All @@ -306,8 +307,8 @@ function MedReqDropDown({
}

const etasuSx = {
backgroundColor: color,
':hover': { filter: 'brightness(110%)', backgroundColor: color }
backgroundColor: eStatus.color,
':hover': { filter: 'brightness(110%)', backgroundColor: eStatus.color }
};
const pharmSx = {
backgroundColor: pColor,
Expand Down Expand Up @@ -397,7 +398,7 @@ function MedReqDropDown({
<div>
<ListIcon fontSize="large" />
<p className="etasuButtonText">ETASU: </p>
<p>{remsAdminResponse?.status || 'Not Started'}</p>
<p>{eStatus.display || 'Not Started'}</p>
</div>
</Button>
{renderTimestamp(checkedEtasuTime)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, ReactElement } from 'react';
import { useState, useEffect, ReactElement } from 'react';
import { Button, Card, CardActions, CardContent, Grid, Typography } from '@mui/material';

import axios from 'axios';
Expand Down
Loading

0 comments on commit 266f9c0

Please sign in to comment.