Skip to content

Commit 7406c5e

Browse files
committed
Added doc-needed DTR system action launch support
1 parent adf37c2 commit 7406c5e

File tree

3 files changed

+124
-27
lines changed

3 files changed

+124
-27
lines changed

src/components/DisplayBox/DisplayBox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class DisplayBox extends Component{
104104
}
105105

106106
if (suggestion.label) {
107-
if (suggestion.uuid) {
107+
if (!!suggestion.uuid && !!url) {
108108
axios({
109109
method: 'POST',
110110
url: `${url}/analytics/${suggestion.uuid}`,

src/components/RequestBox/RequestBox.js

+79-8
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,84 @@ export default class RequestBox extends Component {
6565
return preppedResources;
6666
}
6767

68-
submit = () => {
68+
submit = async () => {
6969
if (!_.isEmpty(this.state.request)) {
70-
this.props.submitInfo(
70+
let response = await this.props.submitInfo(
7171
this.prepPrefetch(),
7272
this.state.request,
7373
this.state.patient,
7474
"order-sign",
75-
this.state.deidentifyRecords
75+
this.state.deidentifyRecords,
76+
true
7677
);
7778
}
7879
};
7980

81+
submitAction = async () => {
82+
console.log("submitAction", this.state.request);
83+
if (!_.isEmpty(this.state.request)) {
84+
let response = await this.props.submitInfo(
85+
this.prepPrefetch(),
86+
this.state.request,
87+
this.state.patient,
88+
"order-sign",
89+
this.state.deidentifyRecords,
90+
false
91+
);
92+
93+
console.log("submitAction response", response);
94+
95+
if (!!response.systemActions && response.systemActions.length > 0) {
96+
console.log("submitAction systemActions", response.systemActions);
97+
98+
// find a resource in the system actions with the CRD coverage information extension
99+
let resource = null;
100+
for (let action of response.systemActions) {
101+
102+
if (!action.resource || !action.resource.extension || action.resource.extension.length === 0) {
103+
continue;
104+
}
105+
if (action.resource.extension.findIndex(e => e.url === "http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information") > -1) {
106+
resource = action.resource;
107+
break;
108+
}
109+
}
110+
111+
// check if doc-needed and questionnaire extensions are present in the resource of any action
112+
if (resource) {
113+
console.log("submitAction resource", resource);
114+
let extension = resource.extension.find(e => e.url === "http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information");
115+
116+
if (extension?.extension.findIndex(e => e.url === "doc-needed") > -1) {
117+
let questionnaire = extension.extension.find(e => e.url === "questionnaire");
118+
119+
if (!questionnaire) {
120+
console.log("Questionnaire not found when doc-needed is present");
121+
return;
122+
}
123+
124+
console.log("Questionnaire found", questionnaire);
125+
console.log("Coverage:", resource.insurance[0]);
126+
127+
let launchLink = await this.buildLaunchLink(`&questionnaire=${questionnaire.valueCanonical}`);
128+
console.log("launchLink", launchLink);
129+
window.open(launchLink.url, "_blank");
130+
}
131+
else {
132+
console.log("doc-needed extension not found");
133+
}
134+
135+
}
136+
else {
137+
console.log("submitAction resource not found");
138+
}
139+
}
140+
else {
141+
console.log("No systemActions");
142+
}
143+
}
144+
};
145+
80146
updateStateElement = (elementName, text) => {
81147
this.setState({ [elementName]: text });
82148
};
@@ -277,10 +343,10 @@ export default class RequestBox extends Component {
277343
});
278344
}
279345

280-
buildLaunchLink() {
346+
buildLaunchLink(additionalContext = "") {
281347
// build appContext and URL encode it
282348
let appContext = "";
283-
let order = undefined, coverage = undefined, response = undefined;
349+
let order = undefined, coverage = undefined, response = undefined, questionnaire = undefined;
284350

285351
if (!this.isOrderNotSelected()) {
286352
if (Object.keys(this.state.request).length > 0) {
@@ -309,6 +375,8 @@ export default class RequestBox extends Component {
309375
appContext += `response=${response}`
310376
}
311377

378+
appContext += additionalContext;
379+
312380
const link = {
313381
appContext: encodeURIComponent(appContext),
314382
type: "smart",
@@ -398,11 +466,14 @@ export default class RequestBox extends Component {
398466
</div>
399467
</div>
400468
</div>
401-
<button className={"submit-btn btn btn-class "} onClick={this.relaunch} disabled={disableLaunchDTR}>
469+
{/* <button className={"submit-btn btn btn-class "} onClick={this.relaunch} disabled={disableLaunchDTR}>
402470
Relaunch DTR
403-
</button>
471+
</button> */}
404472
<button className={"submit-btn btn btn-class "} onClick={this.submit} disabled={disableSendToCRD}>
405-
Submit to CRD
473+
Submit to CRD and Display Cards
474+
</button>
475+
<button className={"submit-btn btn btn-class "} onClick={this.submitAction} disabled={disableSendToCRD}>
476+
Submit to CRD and Launch DTR
406477
</button>
407478
</div>
408479
);

src/containers/RequestBuilder.js

+44-18
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class RequestBuilder extends Component {
109109

110110
}
111111

112-
submit_info(prefetch, request, patient, hook, deidentifyRecords) {
112+
async submit_info(prefetch, request, patient, hook, deidentifyRecords, setResponseState) {
113113
this.consoleLog("Initiating form submission", types.info);
114114
this.setState({patient});
115115
const hookConfig = {
@@ -135,25 +135,51 @@ export default class RequestBuilder extends Component {
135135
});
136136
this.consoleLog("Fetching response from " + cdsUrl, types.info);
137137
try {
138-
fetch(cdsUrl, {
139-
method: "POST",
140-
headers: myHeaders,
141-
body: JSON.stringify(json_request)
142-
}).then(response => {
143-
this.consoleLog("Received response", types.info);
144-
response.json().then((fhirResponse) => {
145-
console.log(fhirResponse);
146-
if (fhirResponse && fhirResponse.status) {
147-
this.consoleLog("Server returned status "
148-
+ fhirResponse.status + ": "
149-
+ fhirResponse.error, types.error);
150-
this.consoleLog(fhirResponse.message, types.error);
151-
} else {
138+
// fetch(cdsUrl, {
139+
// method: "POST",
140+
// headers: myHeaders,
141+
// body: JSON.stringify(json_request)
142+
// }).then(response => {
143+
// this.consoleLog("Received response", types.info);
144+
// response.json().then((fhirResponse) => {
145+
// console.log(fhirResponse);
146+
// if (fhirResponse && fhirResponse.status) {
147+
// this.consoleLog("Server returned status "
148+
// + fhirResponse.status + ": "
149+
// + fhirResponse.error, types.error);
150+
// this.consoleLog(fhirResponse.message, types.error);
151+
// } else {
152+
// this.setState({ response: fhirResponse });
153+
// }
154+
// this.setState({ loading: false });
155+
// })
156+
// }).catch(() => this.consoleLog("No response recieved from the server", types.error));
157+
158+
try {
159+
let response = await fetch(cdsUrl, {
160+
method: "POST",
161+
headers: myHeaders,
162+
body: JSON.stringify(json_request)
163+
});
164+
let fhirResponse = await response.json();
165+
166+
if (fhirResponse && fhirResponse.status) {
167+
this.consoleLog("Server returned status "
168+
+ fhirResponse.status + ": "
169+
+ fhirResponse.error, types.error);
170+
this.consoleLog(fhirResponse.message, types.error);
171+
} else {
172+
if (setResponseState) {
152173
this.setState({ response: fhirResponse });
153174
}
154-
this.setState({ loading: false });
155-
})
156-
}).catch(() => this.consoleLog("No response recieved from the server", types.error));
175+
return fhirResponse;
176+
}
177+
} catch (error) {
178+
this.consoleLog("No response recieved from the server", types.error);
179+
} finally {
180+
this.setState({ loading: false });
181+
}
182+
157183
} catch (error) {
158184
this.setState({ loading: false });
159185
this.consoleLog("Unexpected error occured", types.error)

0 commit comments

Comments
 (0)