Skip to content

Commit

Permalink
Add encounter param in pop function
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed May 19, 2024
1 parent 4365a73 commit f7e0a3a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 41 deletions.
4 changes: 2 additions & 2 deletions apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 5 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdc-populate/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// PopulateInputParameter private functions
import type {
Encounter,
FhirResource,
Parameters,
ParametersParameter,
Expand All @@ -33,12 +34,13 @@ import type {

export function createPopulateInputParameters(
questionnaire: Questionnaire,
patient: Patient,
user: Practitioner,
launchContexts: LaunchContext[],
sourceQueries: SourceQuery[],
questionnaireLevelVariables: QuestionnaireLevelXFhirQueryVariable[],
context: Record<string, any>
context: Record<string, any>,
patient: Patient,
user?: Practitioner,
encounter?: Encounter
): Parameters | null {
const patientSubject = createPatientSubject(questionnaire, patient);
if (!patientSubject) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -139,9 +147,10 @@ function createLocalParam(): ParametersParameter {

function createLaunchContextParam(
launchContext: LaunchContext,
context: Record<string, any>,
patient: Patient,
user: Practitioner,
context: Record<string, any>
user?: Practitioner,
encounter?: Encounter
): ParametersParameter | null {
const name = launchContext.extension[0].valueId ?? launchContext.extension[0].valueCoding?.code;
if (!name) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import type {
Encounter,
Extension,
OperationOutcome,
Patient,
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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<string, any> = {};

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/smart-forms-renderer/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/smart-forms-renderer/src/stories/PrePopWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f7e0a3a

Please sign in to comment.