From f7e0a3a7eaa24c81b7ad56644f9c3a7eefb3256d Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Sun, 19 May 2024 11:46:47 +0930 Subject: [PATCH 1/3] Add encounter param in pop function --- apps/smart-forms-app/package.json | 4 +-- package-lock.json | 23 ++++------------- packages/sdc-populate/package.json | 2 +- .../utils/createInputParameters.ts | 25 +++++++++++++------ .../utils/populateQuestionnaire.ts | 20 +++++++++------ packages/smart-forms-renderer/package.json | 4 +-- .../src/stories/PrePopWrapper.tsx | 6 ++--- 7 files changed, 43 insertions(+), 41 deletions(-) diff --git a/apps/smart-forms-app/package.json b/apps/smart-forms-app/package.json index 92463d91b..78d96bc7f 100644 --- a/apps/smart-forms-app/package.json +++ b/apps/smart-forms-app/package.json @@ -26,8 +26,8 @@ "homepage": "https://github.com/aehrc/smart-forms#readme", "dependencies": { "@aehrc/sdc-assemble": "^1.2.0", - "@aehrc/sdc-populate": "^1.9.0", - "@aehrc/smart-forms-renderer": "^0.28.0", + "@aehrc/sdc-populate": "^2.0.1", + "@aehrc/smart-forms-renderer": "^0.29.0", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", "@fontsource/material-icons": "^5.0.16", diff --git a/package-lock.json b/package-lock.json index 6010ed3fd..3c79faf03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,8 +49,8 @@ "license": "Apache-2.0", "dependencies": { "@aehrc/sdc-assemble": "^1.2.0", - "@aehrc/sdc-populate": "^1.9.0", - "@aehrc/smart-forms-renderer": "^0.28.0", + "@aehrc/sdc-populate": "^2.0.1", + "@aehrc/smart-forms-renderer": "^0.29.0", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", "@fontsource/material-icons": "^5.0.16", @@ -142,19 +142,6 @@ "yui-lint": "^0.2.0" } }, - "apps/smart-forms-app/node_modules/@aehrc/sdc-populate": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@aehrc/sdc-populate/-/sdc-populate-1.9.0.tgz", - "integrity": "sha512-F4DDBF+KT+gjkmU9Hwee7LkIH/h/d/r3Vm4wCwMWCSxtMhzGqi02lkfeS6ObzFq9SYrbEIXh5+JbQtuDhN2XzQ==", - "dependencies": { - "dayjs": "^1.11.10", - "fhir-sdc-helpers": "^0.1.0", - "fhirclient": "^2.5.2", - "fhirpath": "^3.7.1", - "js-base64": "^3.7.7", - "moment": "^2.29.4" - } - }, "apps/smart-forms-app/node_modules/@aehrc/smart-forms-renderer/node_modules/html-react-parser": { "version": "4.2.10", "resolved": "https://registry.npmjs.org/html-react-parser/-/html-react-parser-4.2.10.tgz", @@ -43448,7 +43435,7 @@ }, "packages/sdc-populate": { "name": "@aehrc/sdc-populate", - "version": "2.0.0", + "version": "2.0.1", "license": "Apache-2.0", "dependencies": { "dayjs": "^1.11.10", @@ -43477,10 +43464,10 @@ }, "packages/smart-forms-renderer": { "name": "@aehrc/smart-forms-renderer", - "version": "0.28.0", + "version": "0.29.0", "license": "Apache-2.0", "dependencies": { - "@aehrc/sdc-populate": "^2.0.0", + "@aehrc/sdc-populate": "^2.0.1", "@iconify/react": "^4.1.1", "dayjs": "^1.11.10", "deep-diff": "^1.0.2", diff --git a/packages/sdc-populate/package.json b/packages/sdc-populate/package.json index 79870ab1b..6a0de9e74 100644 --- a/packages/sdc-populate/package.json +++ b/packages/sdc-populate/package.json @@ -1,6 +1,6 @@ { "name": "@aehrc/sdc-populate", - "version": "2.0.0", + "version": "2.0.1", "description": "Performs the $populate operation from the HL7 FHIR SDC (Structured Data Capture) specification: http://hl7.org/fhir/uv/sdc", "main": "lib/index.js", "scripts": { diff --git a/packages/sdc-populate/src/inAppPopulation/utils/createInputParameters.ts b/packages/sdc-populate/src/inAppPopulation/utils/createInputParameters.ts index b24f39f47..e4776516b 100644 --- a/packages/sdc-populate/src/inAppPopulation/utils/createInputParameters.ts +++ b/packages/sdc-populate/src/inAppPopulation/utils/createInputParameters.ts @@ -17,6 +17,7 @@ // PopulateInputParameter private functions import type { + Encounter, FhirResource, Parameters, ParametersParameter, @@ -33,12 +34,13 @@ import type { export function createPopulateInputParameters( questionnaire: Questionnaire, - patient: Patient, - user: Practitioner, launchContexts: LaunchContext[], sourceQueries: SourceQuery[], questionnaireLevelVariables: QuestionnaireLevelXFhirQueryVariable[], - context: Record + context: Record, + patient: Patient, + user?: Practitioner, + encounter?: Encounter ): Parameters | null { const patientSubject = createPatientSubject(questionnaire, patient); if (!patientSubject) { @@ -69,7 +71,13 @@ export function createPopulateInputParameters( // add launch contexts if (launchContexts.length > 0) { for (const launchContext of launchContexts) { - const launchContextParam = createLaunchContextParam(launchContext, patient, user, context); + const launchContextParam = createLaunchContextParam( + launchContext, + context, + patient, + user, + encounter + ); if (launchContextParam) { contexts.push(launchContextParam); } @@ -139,9 +147,10 @@ function createLocalParam(): ParametersParameter { function createLaunchContextParam( launchContext: LaunchContext, + context: Record, patient: Patient, - user: Practitioner, - context: Record + user?: Practitioner, + encounter?: Encounter ): ParametersParameter | null { const name = launchContext.extension[0].valueId ?? launchContext.extension[0].valueCoding?.code; if (!name) { @@ -152,8 +161,10 @@ function createLaunchContextParam( let resource: FhirResource | null; if (name === 'patient' && resourceType === 'Patient') { resource = patient; - } else if (name === 'user' && resourceType === 'Practitioner') { + } else if (name === 'user' && resourceType === 'Practitioner' && user) { resource = user; + } else if (name === 'encounter' && resourceType === 'Encounter' && encounter) { + resource = encounter; } else { return null; } diff --git a/packages/sdc-populate/src/inAppPopulation/utils/populateQuestionnaire.ts b/packages/sdc-populate/src/inAppPopulation/utils/populateQuestionnaire.ts index 84d3391fa..e2cc724e0 100644 --- a/packages/sdc-populate/src/inAppPopulation/utils/populateQuestionnaire.ts +++ b/packages/sdc-populate/src/inAppPopulation/utils/populateQuestionnaire.ts @@ -16,6 +16,7 @@ */ import type { + Encounter, Extension, OperationOutcome, Patient, @@ -49,19 +50,21 @@ export interface PopulateResult { /** * @param questionnaire - Questionnaire to populate - * @param patient - Patient resource as patient in context - * @param user - Practitioner resource as user in context * @param fetchResourceCallback - A callback function to fetch resources * @param requestConfig - Any request configuration to be passed to the fetchResourceCallback i.e. headers, auth etc. + * @param patient - Patient resource as patient in context + * @param user - Practitioner resource as user in context + * @param encounter - Encounter resource as encounter in context, optional * * @author Sean Fong */ export interface PopulateQuestionnaireParams { questionnaire: Questionnaire; - patient: Patient; - user: Practitioner; fetchResourceCallback: FetchResourceCallback; requestConfig: any; + patient: Patient; + user?: Practitioner; + encounter?: Encounter; } /** @@ -78,7 +81,7 @@ export async function populateQuestionnaire(params: PopulateQuestionnaireParams) populateSuccess: boolean; populateResult: PopulateResult | null; }> { - const { questionnaire, patient, user, fetchResourceCallback, requestConfig } = params; + const { questionnaire, fetchResourceCallback, requestConfig, patient, user, encounter } = params; const context: Record = {}; @@ -101,12 +104,13 @@ export async function populateQuestionnaire(params: PopulateQuestionnaireParams) // Define population input parameters from launch contexts, source queries and questionnaire-level variables const inputParameters = createPopulateInputParameters( questionnaire, - patient, - user, launchContexts, sourceQueries, questionnaireLevelVariables, - context + context, + patient, + user, + encounter ); if (!inputParameters) { diff --git a/packages/smart-forms-renderer/package.json b/packages/smart-forms-renderer/package.json index 605531e91..28da8d546 100644 --- a/packages/smart-forms-renderer/package.json +++ b/packages/smart-forms-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@aehrc/smart-forms-renderer", - "version": "0.28.0", + "version": "0.29.0", "description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms", "main": "lib/index.js", "scripts": { @@ -27,7 +27,7 @@ }, "homepage": "https://github.com/aehrc/smart-forms#readme", "dependencies": { - "@aehrc/sdc-populate": "^2.0.0", + "@aehrc/sdc-populate": "^2.0.1", "@iconify/react": "^4.1.1", "dayjs": "^1.11.10", "deep-diff": "^1.0.2", diff --git a/packages/smart-forms-renderer/src/stories/PrePopWrapper.tsx b/packages/smart-forms-renderer/src/stories/PrePopWrapper.tsx index d3fe0c39e..f92966dfc 100644 --- a/packages/smart-forms-renderer/src/stories/PrePopWrapper.tsx +++ b/packages/smart-forms-renderer/src/stories/PrePopWrapper.tsx @@ -50,13 +50,13 @@ function PrePopWrapper(props: PrePopWrapperProps) { populateQuestionnaire({ questionnaire: questionnaire, - patient: patient, - user: user, fetchResourceCallback: fetchResourceCallback, requestConfig: { clientEndpoint: fhirClient.state.serverUrl, authToken: null - } + }, + patient: patient, + user: user }).then(async ({ populateSuccess, populateResult }) => { if (!populateSuccess || !populateResult) { setIsPopulating(false); From cfee53dc79406a7b1293538536a0c6cbd4204176 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Sun, 19 May 2024 21:22:19 +0930 Subject: [PATCH 2/3] Complete pre-pop doc --- .../docs/sdc/advanced/fundamental.mdx | 14 +- documentation/docs/sdc/population.mdx | 254 +++++++++++++++++- documentation/docs/sdc/terminology.mdx | 2 +- 3 files changed, 262 insertions(+), 8 deletions(-) diff --git a/documentation/docs/sdc/advanced/fundamental.mdx b/documentation/docs/sdc/advanced/fundamental.mdx index d65aa8739..ff3419edc 100644 --- a/documentation/docs/sdc/advanced/fundamental.mdx +++ b/documentation/docs/sdc/advanced/fundamental.mdx @@ -137,14 +137,24 @@ Multiple initial values can be used in repeating items. There can only be one in #### Basic Usage - +