Skip to content

Commit

Permalink
Implement CSIRO pre-pop
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed May 19, 2024
1 parent cba0928 commit 0f731f2
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 10 deletions.
90 changes: 86 additions & 4 deletions components/QuestionnairePrepopTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@

<script lang="ts">
import { Questionnaire, QuestionnaireResponse, Parameters } from "fhir/r4b";
import { Questionnaire as QuestionnaireR4, Patient as PatientR4, Practitioner as PractitionerR4, Encounter as EncounterR4 } from "fhir/r4";
import { Component, Prop, Vue } from "vue-property-decorator";
import "ace-builds";
Expand All @@ -132,6 +133,8 @@ import { settings } from "~/helpers/user_settings";
import { loadFhirResource } from "~/helpers/searchFhir";
import { BaseResourceData } from "~/models/BaseResourceTableData";
import { json } from "express";
import { FetchResourceCallback, populateQuestionnaire } from "@aehrc/sdc-populate";
import axios from "axios";
interface LaunchContextData {
id: string | undefined;
Expand All @@ -147,19 +150,19 @@ export default class QuestionnaireExtractTest extends Vue {
// https://github.com/LHNCBC/lforms-fhir-app/blob/157be10a006eb6886c5421c5dd2606e795d8d9d8/source/js/fhir.service.js#L135C55-L136C43
/*
From the NLM render component
From the NLM render component
* var fhirContext = FHIR.client(settings.getFhirServerExamplesUrl());
var fhirContextVars = { LaunchPatient: "Patient/123" };
LForms.Util.setFHIRContext(fhirContext, fhirContextVars);
this.lforms_error = undefined;
await LForms.Util.addFormToPage(this.questionnaire, "myFormContainer", {
prepopulate: false,
}).catch((e: any) => {
console.error("Breaking news:", e);
this.lforms_error = e.toString();
});
*/
// Properties visible to the local template
Expand Down Expand Up @@ -351,8 +354,87 @@ export default class QuestionnaireExtractTest extends Vue {
}
}
// Note: No way to POST batch bundles yet, the populate library will individually process each batch entry
static fetchResourceCallbackCSIROPrePopulation: FetchResourceCallback =
async (query: string, requestConfig: { sourceFhirServer: string }) => {
let { sourceFhirServer } = requestConfig;
const headers = {
Accept: "application/json;charset=utf-8",
};
if (!sourceFhirServer.endsWith("/")) {
sourceFhirServer += "/";
}
// When query is an absolute URL, use it as is
if (/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/.test(query)) {
return axios.get(query, {
headers: headers,
});
}
// When query is a relative URL, append it to the client endpoint
return axios.get(sourceFhirServer + query, {
headers: headers,
});
};
async runCSIROPrePopulation(): Promise<QuestionnaireResponse | undefined> {
console.log('Running CSIRO pre-pop');
let patientResource: PatientR4 | undefined = undefined;
let userResource: PractitionerR4 | undefined = undefined;
let encounterResource: EncounterR4 | undefined = undefined;
for (let [, value] of this.launchContextValues) {
if (value && value.data) {
try {
const resource = JSON.parse(value.data);
switch (resource.resourceType) {
case "Patient":
patientResource = resource as PatientR4;
break;
case "Practitioner":
userResource = resource as PractitionerR4;
break;
case "Encounter":
encounterResource = resource as EncounterR4;
break;
}
} catch (err) {
console.log(err);
}
}
}
if (!this.questionnaire) {
console.log("No patient resource provided");
return;
}
if (!patientResource) {
console.log("No patient resource provided");
return;
}
const { populateSuccess, populateResult } = await populateQuestionnaire({
questionnaire: this.questionnaire as QuestionnaireR4,
fetchResourceCallback:
QuestionnaireExtractTest.fetchResourceCallbackCSIROPrePopulation,
requestConfig: {
sourceFhirServer: this.sourceFhirServer,
},
patient: patientResource as PatientR4,
user: userResource ? (userResource as PractitionerR4) : undefined,
encounter: encounterResource ? (encounterResource as EncounterR4) : undefined,
});
if (!populateSuccess || !populateResult) {
console.log("Failed to populate the questionnaire");
return;
}
this.$emit("response", populateResult.populatedResponse);
return undefined;
}
Expand Down
52 changes: 46 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dockerize": "docker build -t fhirpath-lab ."
},
"dependencies": {
"@aehrc/sdc-populate": "^2.0.1",
"@aehrc/smart-forms-renderer": "^0.25.2",
"@nuxtjs/applicationinsights": "^1.2.2",
"@types/ace": "0.0.48",
Expand Down

0 comments on commit 0f731f2

Please sign in to comment.