Skip to content

Commit 79fa941

Browse files
committed
fix launch
1 parent 630ba0d commit 79fa941

5 files changed

Lines changed: 81 additions & 121 deletions

File tree

launch.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
To create a production bundle, use `npm run build` or `yarn build`.
3434
-->
3535
</body>
36-
<script type="module" src="/src/launch.jsx"></script>
36+
<script type="module" src="/src/launch.js"></script>
3737
</html>

src/containers/LaunchContainer.jsx

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/launch.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import FHIR from "fhirclient";
2+
import { queryNeedPatientBanner, queryPatientIdKey } from "@consts";
3+
import { fetchEnvData, getEnv } from "@util";
4+
5+
const fetchContextJson = async (authURL) => {
6+
if (!authURL) {
7+
// default, if no auth url provided
8+
return {
9+
clientId: "hpai_sof_client",
10+
scope: "profile roles email patient/*.read",
11+
// default to not show patient banner, can be overridden
12+
// cannot seem to override this when testing against SMART healthIT launcher though
13+
need_patient_banner: false,
14+
};
15+
}
16+
const response = await fetch(authURL, {
17+
// include cookies in request
18+
credentials: "include",
19+
}).catch((e) => {
20+
console.log(e);
21+
throw new Error("Error retrieving context json via auth url. See console for detail.");
22+
});
23+
24+
if (!response.ok) {
25+
console.log(response.status, response.statusText);
26+
throw new Error(`Error launch application: Server returned status ${response.status.toString()}`);
27+
}
28+
29+
const contextJson = await response.json().catch((e) => {
30+
console.log(e);
31+
throw new Error("Context json parsing error. See console for detail.");
32+
});
33+
34+
return contextJson;
35+
};
36+
37+
fetchEnvData().then((results) => {
38+
console.log("environment variables ", results);
39+
const backendURL = getEnv("REACT_APP_CONF_API_URL");
40+
const authURL = backendURL ? `${backendURL}/auth/auth-info` : "";
41+
const urlParams = new URLSearchParams(window.location.search);
42+
const patientId = urlParams.get("patient");
43+
console.log("patient id from url query string: ", patientId);
44+
const needPatientBanner = urlParams.get("need_patient_banner");
45+
console.log("need_patient_banner from url query string: ", needPatientBanner);
46+
console.log("Auth url ", authURL);
47+
48+
fetchContextJson(authURL)
49+
.then((json) => {
50+
if (patientId) {
51+
json.patientId = patientId;
52+
sessionStorage.setItem(queryPatientIdKey, patientId);
53+
}
54+
55+
if (needPatientBanner !== null) {
56+
json.need_patient_banner = needPatientBanner;
57+
sessionStorage.setItem(queryNeedPatientBanner, needPatientBanner);
58+
}
59+
60+
// allow client id to be configurable
61+
const envClientId = getEnv("REACT_APP_CLIENT_ID");
62+
if (envClientId) json.clientId = envClientId;
63+
64+
// allow auth scopes to be updated via environment variable
65+
// see https://build.fhir.org/ig/HL7/smart-app-launch/scopes-and-launch-context.html
66+
const envAuthScopes = getEnv("REACT_APP_AUTH_SCOPES");
67+
if (envAuthScopes) json.scope = envAuthScopes;
68+
69+
sessionStorage.setItem("launchContextJson", JSON.stringify(json));
70+
71+
console.log("launch context json ", json);
72+
FHIR.oauth2
73+
.authorize(json)
74+
.catch((e) => {
75+
console.log("FHIR auth error ", e);
76+
});
77+
})
78+
.catch((error) => console.log(error));
79+
});

src/launch.jsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/layout/Header.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function Header(props) {
4141
}
4242
e.target.classList.remove("ghost");
4343
};
44-
const shouldHideReturnButton = () => !returnURL || inEHR;
44+
const shouldHideReturnButton = () => !returnURL;
4545

4646
const renderTitle = () => {
4747
const appTitle = getEnvAppTitle();

0 commit comments

Comments
 (0)