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

Merging main into acdc-pilot #859

Merged
merged 10 commits into from
Jun 13, 2024
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
Loading