Skip to content

Commit

Permalink
Merge pull request #90 from mcode/rems-case-save
Browse files Browse the repository at this point in the history
Rems case save
  • Loading branch information
plarocque4 authored May 9, 2024
2 parents 2a31d15 + 8610ce6 commit 90c8803
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ describe('Test the EtasuStatus Component', () => {
remsAdminResponse={etasu.parameter[0].resource}
/>
);

// verify that the values are updated from the call to get the ETASU
expect(
await screen.findByText('Status: ' + etasu.parameter[0].resource.status)
).toBeInTheDocument();
expect(await screen.findByText('Status: Pending')).toBeInTheDocument();
expect(await screen.findAllByTestId('etasu-item')).toHaveLength(3);
}
});
Expand Down
44 changes: 42 additions & 2 deletions src/views/Questionnaire/QuestionnaireForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Meta,
Organization,
Parameters,
Patient,
Questionnaire,
QuestionnaireItem,
QuestionnaireResponse,
Expand Down Expand Up @@ -44,7 +45,7 @@ import Client from 'fhirclient/lib/Client';
import ConfigData from '../../config.json';
import { SelectPopup } from './components/SelectPopup';
import AlertDialog from './components/AlertDialog';

import { RemsAdminResponse } from './components/RemsInterface/RemsInterface';
import { PrepopulationResults } from './SmartApp';
import { v4 as uuid } from 'uuid';
import axios, { AxiosResponse } from 'axios';
Expand Down Expand Up @@ -116,11 +117,16 @@ export function QuestionnaireForm(props: QuestionnaireProps) {
const [formLoaded, setFormLoaded] = useState<string>('');
const [showRxAlert, setShowRxAlert] = useState<RxAlert>({ open: false });
const [formValidationErrors, setFormValidationErrors] = useState<any[]>([]);
const [patient, setPatient] = useState<Patient | undefined>(undefined);
const partialForms: PartialForms = {};
const LForms = window.LForms;
const questionnaireFormId = `formContainer-${props.questionnaireForm.id}-${props.tabIndex}`;

useEffect(() => {
const patientId = getPatient();
props.smartClient.request(patientId).then(res => {
setPatient(res);
});
// search for any partially completed QuestionnaireResponses
if (props.response) {
const response = props.response;
Expand Down Expand Up @@ -1649,8 +1655,42 @@ export function QuestionnaireForm(props: QuestionnaireProps) {
};
axios
.post('http://localhost:8090/etasu/met', specialtyRxBundle, options)
.then(response => {
.then((response: RemsAdminResponse) => {
const remsCaseUrl = 'http://hl7.org/fhir/sid/rems-case'; // placeholder
const proceedToRems = () => {
const caseNumber = response.data?.case_number;
if (caseNumber && patient) {
patient.identifier = patient.identifier?.filter(iden => {
if (iden.system === remsCaseUrl && iden.period) {
if (iden.period?.end) {
const endDate = new Date(iden.period.end);
if (endDate.getMilliseconds() < Date.now()) {
return false; // filter out old identifiers
}
}
}
return true;
});
const endDate = new Date(Date.now() + 86400000); // 86400000 is 1 day in milliseconds
patient.identifier?.push({
value: caseNumber,
system: remsCaseUrl,
period: {
start: new Date(Date.now()).toISOString(),
end: endDate.toISOString()
}
});
// update patient
props.smartClient.request({
url: patient.resourceType + '/' + patient.id,
method: 'PUT',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(patient)
});
}

props.setSpecialtyRxBundle(specialtyRxBundle);
props.setRemsAdminResponse(response);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import './RemsInterface.css';
import Paper from '@mui/material/Paper';
import Button from '@mui/material/Button';
import { Bundle } from 'fhir/r4';
import { AxiosResponse } from 'axios';

interface RemsInterfaceProps {
remsAdminResponse: RemsAdminResponse;
specialtyRxBundle: Bundle;
}
interface RemsAdminResponse {
export interface RemsAdminResponse extends AxiosResponse {
data: JsonData;
}

Expand Down

0 comments on commit 90c8803

Please sign in to comment.