Skip to content

Commit

Permalink
Added doc-needed DTR system action launch support
Browse files Browse the repository at this point in the history
  • Loading branch information
bstewartlg committed May 17, 2024
1 parent adf37c2 commit 7406c5e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/components/DisplayBox/DisplayBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
87 changes: 79 additions & 8 deletions src/components/RequestBox/RequestBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -309,6 +375,8 @@ export default class RequestBox extends Component {
appContext += `response=${response}`
}

appContext += additionalContext;

const link = {
appContext: encodeURIComponent(appContext),
type: "smart",
Expand Down Expand Up @@ -398,11 +466,14 @@ export default class RequestBox extends Component {
</div>
</div>
</div>
<button className={"submit-btn btn btn-class "} onClick={this.relaunch} disabled={disableLaunchDTR}>
{/* <button className={"submit-btn btn btn-class "} onClick={this.relaunch} disabled={disableLaunchDTR}>
Relaunch DTR
</button>
</button> */}
<button className={"submit-btn btn btn-class "} onClick={this.submit} disabled={disableSendToCRD}>
Submit to CRD
Submit to CRD and Display Cards
</button>
<button className={"submit-btn btn btn-class "} onClick={this.submitAction} disabled={disableSendToCRD}>
Submit to CRD and Launch DTR
</button>
</div>
);
Expand Down
62 changes: 44 additions & 18 deletions src/containers/RequestBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand Down

0 comments on commit 7406c5e

Please sign in to comment.