Skip to content

Commit

Permalink
Merge pull request #859 from aehrc/main
Browse files Browse the repository at this point in the history
Merging main into acdc-pilot
  • Loading branch information
fongsean authored Jun 13, 2024
2 parents 0db633d + fb52363 commit c02cb67
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 105 deletions.
2 changes: 1 addition & 1 deletion apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@sentry/tracing": "^7.101.0",
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-table": "^8.10.7",
"allotment": "^1.19.2",
"allotment": "^1.20.2",
"dayjs": "^1.11.10",
"fhirclient": "^2.5.2",
"fhirpath": "^3.7.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import type { ItemToRepopulate } from '@aehrc/smart-forms-renderer';
import { generateItemsToRepopulate, useQuestionnaireStore } from '@aehrc/smart-forms-renderer';
import RepopulateDialog from '../../../repopulate/components/RepopulateDialog.tsx';
import { useState } from 'react';
import type { Patient, Practitioner } from 'fhir/r4';
import type { Encounter, Patient, Practitioner } from 'fhir/r4';
import { useMutation } from '@tanstack/react-query';
import { readCommonLaunchContexts } from '../../../smartAppLaunch/utils/launch.ts';

interface RepopulateActionProps extends SpeedDialActionProps {
spinner: RendererSpinner;
Expand All @@ -40,7 +41,7 @@ interface RepopulateActionProps extends SpeedDialActionProps {
function RepopulateAction(props: RepopulateActionProps) {
const { spinner, isSpeedDial, onSpinnerChange, ...speedDialActionProps } = props;

const { smartClient, patient, user, encounter } = useSmartClient();
const { smartClient, patient, user } = useSmartClient();

const [itemsToRepopulate, setItemsToRepopulate] = useState<Record<string, ItemToRepopulate>>({});

Expand All @@ -64,15 +65,19 @@ function RepopulateAction(props: RepopulateActionProps) {
!!(sourceQuestionnaire.contained || sourceQuestionnaire.extension);

const { mutate: repopulateMutation } = useMutation({
mutationFn: (params: { newPatient: Patient; newUser: Practitioner }) => {
const { newPatient, newUser } = params;
mutationFn: (params: {
newPatient: Patient;
newUser: Practitioner;
newEncounter: Encounter | null;
}) => {
const { newPatient, newUser, newEncounter } = params;

return populateQuestionnaire(
sourceQuestionnaire,
smartClient!,
newPatient,
newUser,
encounter,
newEncounter,
fhirPathContext
);
},
Expand Down Expand Up @@ -131,10 +136,14 @@ function RepopulateAction(props: RepopulateActionProps) {
status: 'repopulate-fetch',
message: 'Retrieving latest information'
});
const newPatient = await smartClient.patient.read();
const newUser = (await smartClient.user.read()) as Practitioner;

repopulateMutation({ newPatient, newUser });
const { patient, user, encounter } = await readCommonLaunchContexts(smartClient);

repopulateMutation({
newPatient: patient as Patient,
newUser: user as Practitioner,
newEncounter: encounter
});
}

return (
Expand Down
Loading

0 comments on commit c02cb67

Please sign in to comment.