From 7406c5ea01f9c93cd7bff8985d91faea9e0cfc9c Mon Sep 17 00:00:00 2001
From: bstewartlg <114590619+bstewartlg@users.noreply.github.com>
Date: Fri, 17 May 2024 13:35:52 -0400
Subject: [PATCH] Added doc-needed DTR system action launch support
---
src/components/DisplayBox/DisplayBox.js | 2 +-
src/components/RequestBox/RequestBox.js | 87 ++++++++++++++++++++++---
src/containers/RequestBuilder.js | 62 +++++++++++++-----
3 files changed, 124 insertions(+), 27 deletions(-)
diff --git a/src/components/DisplayBox/DisplayBox.js b/src/components/DisplayBox/DisplayBox.js
index 7c3021ab..28594d08 100644
--- a/src/components/DisplayBox/DisplayBox.js
+++ b/src/components/DisplayBox/DisplayBox.js
@@ -104,7 +104,7 @@ export default class DisplayBox extends Component{
}
if (suggestion.label) {
- if (suggestion.uuid) {
+ if (!!suggestion.uuid && !!url) {
axios({
method: 'POST',
url: `${url}/analytics/${suggestion.uuid}`,
diff --git a/src/components/RequestBox/RequestBox.js b/src/components/RequestBox/RequestBox.js
index 1c4375b2..f8b82288 100644
--- a/src/components/RequestBox/RequestBox.js
+++ b/src/components/RequestBox/RequestBox.js
@@ -65,18 +65,84 @@ export default class RequestBox extends Component {
return preppedResources;
}
- submit = () => {
+ submit = async () => {
if (!_.isEmpty(this.state.request)) {
- this.props.submitInfo(
+ let response = await this.props.submitInfo(
this.prepPrefetch(),
this.state.request,
this.state.patient,
"order-sign",
- this.state.deidentifyRecords
+ this.state.deidentifyRecords,
+ true
);
}
};
+ submitAction = async () => {
+ console.log("submitAction", this.state.request);
+ if (!_.isEmpty(this.state.request)) {
+ let response = await this.props.submitInfo(
+ this.prepPrefetch(),
+ this.state.request,
+ this.state.patient,
+ "order-sign",
+ this.state.deidentifyRecords,
+ false
+ );
+
+ console.log("submitAction response", response);
+
+ if (!!response.systemActions && response.systemActions.length > 0) {
+ console.log("submitAction systemActions", response.systemActions);
+
+ // find a resource in the system actions with the CRD coverage information extension
+ let resource = null;
+ for (let action of response.systemActions) {
+
+ if (!action.resource || !action.resource.extension || action.resource.extension.length === 0) {
+ continue;
+ }
+ if (action.resource.extension.findIndex(e => e.url === "http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information") > -1) {
+ resource = action.resource;
+ break;
+ }
+ }
+
+ // check if doc-needed and questionnaire extensions are present in the resource of any action
+ if (resource) {
+ console.log("submitAction resource", resource);
+ let extension = resource.extension.find(e => e.url === "http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information");
+
+ if (extension?.extension.findIndex(e => e.url === "doc-needed") > -1) {
+ let questionnaire = extension.extension.find(e => e.url === "questionnaire");
+
+ if (!questionnaire) {
+ console.log("Questionnaire not found when doc-needed is present");
+ return;
+ }
+
+ console.log("Questionnaire found", questionnaire);
+ console.log("Coverage:", resource.insurance[0]);
+
+ let launchLink = await this.buildLaunchLink(`&questionnaire=${questionnaire.valueCanonical}`);
+ console.log("launchLink", launchLink);
+ window.open(launchLink.url, "_blank");
+ }
+ else {
+ console.log("doc-needed extension not found");
+ }
+
+ }
+ else {
+ console.log("submitAction resource not found");
+ }
+ }
+ else {
+ console.log("No systemActions");
+ }
+ }
+ };
+
updateStateElement = (elementName, text) => {
this.setState({ [elementName]: text });
};
@@ -277,10 +343,10 @@ export default class RequestBox extends Component {
});
}
- buildLaunchLink() {
+ buildLaunchLink(additionalContext = "") {
// build appContext and URL encode it
let appContext = "";
- let order = undefined, coverage = undefined, response = undefined;
+ let order = undefined, coverage = undefined, response = undefined, questionnaire = undefined;
if (!this.isOrderNotSelected()) {
if (Object.keys(this.state.request).length > 0) {
@@ -309,6 +375,8 @@ export default class RequestBox extends Component {
appContext += `response=${response}`
}
+ appContext += additionalContext;
+
const link = {
appContext: encodeURIComponent(appContext),
type: "smart",
@@ -398,11 +466,14 @@ export default class RequestBox extends Component {
- */}
- Submit to CRD
+ Submit to CRD and Display Cards
+
+
+ Submit to CRD and Launch DTR
);
diff --git a/src/containers/RequestBuilder.js b/src/containers/RequestBuilder.js
index 68d3d797..494d6614 100644
--- a/src/containers/RequestBuilder.js
+++ b/src/containers/RequestBuilder.js
@@ -109,7 +109,7 @@ export default class RequestBuilder extends Component {
}
- submit_info(prefetch, request, patient, hook, deidentifyRecords) {
+ async submit_info(prefetch, request, patient, hook, deidentifyRecords, setResponseState) {
this.consoleLog("Initiating form submission", types.info);
this.setState({patient});
const hookConfig = {
@@ -135,25 +135,51 @@ export default class RequestBuilder extends Component {
});
this.consoleLog("Fetching response from " + cdsUrl, types.info);
try {
- fetch(cdsUrl, {
- method: "POST",
- headers: myHeaders,
- body: JSON.stringify(json_request)
- }).then(response => {
- this.consoleLog("Received response", types.info);
- response.json().then((fhirResponse) => {
- console.log(fhirResponse);
- if (fhirResponse && fhirResponse.status) {
- this.consoleLog("Server returned status "
- + fhirResponse.status + ": "
- + fhirResponse.error, types.error);
- this.consoleLog(fhirResponse.message, types.error);
- } else {
+ // fetch(cdsUrl, {
+ // method: "POST",
+ // headers: myHeaders,
+ // body: JSON.stringify(json_request)
+ // }).then(response => {
+ // this.consoleLog("Received response", types.info);
+ // response.json().then((fhirResponse) => {
+ // console.log(fhirResponse);
+ // if (fhirResponse && fhirResponse.status) {
+ // this.consoleLog("Server returned status "
+ // + fhirResponse.status + ": "
+ // + fhirResponse.error, types.error);
+ // this.consoleLog(fhirResponse.message, types.error);
+ // } else {
+ // this.setState({ response: fhirResponse });
+ // }
+ // this.setState({ loading: false });
+ // })
+ // }).catch(() => this.consoleLog("No response recieved from the server", types.error));
+
+ try {
+ let response = await fetch(cdsUrl, {
+ method: "POST",
+ headers: myHeaders,
+ body: JSON.stringify(json_request)
+ });
+ let fhirResponse = await response.json();
+
+ if (fhirResponse && fhirResponse.status) {
+ this.consoleLog("Server returned status "
+ + fhirResponse.status + ": "
+ + fhirResponse.error, types.error);
+ this.consoleLog(fhirResponse.message, types.error);
+ } else {
+ if (setResponseState) {
this.setState({ response: fhirResponse });
}
- this.setState({ loading: false });
- })
- }).catch(() => this.consoleLog("No response recieved from the server", types.error));
+ return fhirResponse;
+ }
+ } catch (error) {
+ this.consoleLog("No response recieved from the server", types.error);
+ } finally {
+ this.setState({ loading: false });
+ }
+
} catch (error) {
this.setState({ loading: false });
this.consoleLog("Unexpected error occured", types.error)