Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rems case save #90

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading