forked from FHIR/Gravity-Patient-App-RI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
203 lines (178 loc) · 6.72 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import React, { useEffect } from "react";
import { NavigationContainer, createNavigationContainerRef } from "@react-navigation/native";
import { createNativeStackNavigator, NativeStackScreenProps } from "@react-navigation/native-stack";
import Home from "./screens/Home";
import Referrals from "./screens/Referrals";
import Assessments from "./screens/Assessments";
import Auth from "./screens/Auth";
import { useRecoilState } from "recoil";
import { Button, LogBox, View } from "react-native";
import { Server, serversState } from "./recoil/servers";
import { discoverAuthEndpoints } from "./utils/auth";
import { Icon, NativeBaseProvider, Link } from "native-base";
import LoginForm from "./screens/LoginForm";
import role from "./recoil/roleState/atom";
import AsyncStorage from "@react-native-async-storage/async-storage";
import * as Linking from "expo-linking";
import ClinicalStaff from "./screens/ClinicalStaff";
import Caregivers from "./screens/Caregivers";
import Organizations from "./screens/Organizations";
import Insurances from "./screens/Insurances";
import { RecoilRootWithPersisance } from "./recoil";
import ServerList from "./components/ServerList";
import PatientInfo from "./screens/PatientInfo";
import PatientProfile from "./screens/PatientProfile";
import ServerView from "./screens/ServerView";
import AddServer from "./screens/AddServer";
import ReferralView from "./screens/ReferralView";
import Assessment from "./screens/Assessment";
import { pendingServerImport, ImportServerRequest } from "./recoil/pendingServerImport";
import Locations from "./screens/Locations";
// todo: temporary recoil fix, should be fixed in expo sdk that support react-native 0.64+, probably sdk 43
// https://github.com/facebookexperimental/Recoil/issues/1030
// https://github.com/facebookexperimental/Recoil/issues/951
LogBox && LogBox.ignoreLogs(["Setting a timer", "Can't perform a React state update on an unmounted component"]);
const App = () => (
<NativeBaseProvider>
<RecoilRootWithPersisance>
<MainContainer />
</RecoilRootWithPersisance>
</NativeBaseProvider>
);
export type RootStackParamList = {
Home: undefined,
Auth: { serverId: string },
LoginForm: undefined,
Caregivers: undefined,
ClinicalStaff: undefined,
Organizations: undefined,
Insurances: undefined,
Hub: undefined,
ServerList: undefined,
PatientInfo: undefined,
PatientProfile: undefined,
Referrals: undefined,
Assessments: undefined,
Assessment: { assessmentId: [string, string] },
ServerView: { serverId: string },
AddServer: undefined
ReferralView: { referralId: string | undefined }
Locations: { serverId: string, healthcareServiceId: string }
};
const Stack = createNativeStackNavigator<RootStackParamList>();
const navigationRef = createNavigationContainerRef<RootStackParamList>();
const logicaParams = {
title: "Logica",
fhirUri: "https://api.logicahealth.org/GravitySandboxNew/data",
clientId: "e501d8e5-d742-462b-bf27-669e385ec243"
};
const importServerLinkingPath = "import-server";
const linkingUrl = Linking.createURL(importServerLinkingPath, { queryParams: logicaParams });
console.log("linking url:", linkingUrl);
const MainContainer = () => {
const [pendingImport, setPendingImport] = useRecoilState(pendingServerImport);
useEffect(() => {
Linking.addEventListener("url", ({ url }) => onGotLinked(url));
}, []);
useEffect(() => {
Linking.getInitialURL().then(url => url && onGotLinked(url));
}, []);
const onGotLinked = (url: string) => {
const { path, queryParams } = Linking.parse(url);
const { title, fhirUri, clientId } = queryParams;
if (path === importServerLinkingPath && typeof title === "string" && typeof fhirUri === "string" && typeof clientId === "string") {
setPendingImport({ title, fhirUri, clientId });
}
};
const [roleState] = useRecoilState(role);
const [servers, setServers] = useRecoilState(serversState);
useEffect(() => {
if (roleState && pendingImport) {
onImportServerInvokedFromOutside(pendingImport);
}
}, [roleState, pendingImport]);
const onImportServerInvokedFromOutside = async (params: ImportServerRequest) => {
const { title, fhirUri, clientId } = params;
const id = title;
const { authUri, tokenUri } = await discoverAuthEndpoints(fhirUri);
const newServer: Server = {
id,
title,
fhirUri,
authConfig: {
authUri,
tokenUri,
clientId
},
session: undefined
};
setServers(oldServers => ({
...oldServers,
[id]: newServer
}));
setPendingImport(undefined);
navigationRef.navigate("Auth", { serverId: id });
};
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator
initialRouteName="Home"
screenOptions={{
headerTitleAlign: "center"
}}
>
{ roleState === null ? (
<Stack.Screen options={{ headerShown: false }} name="LoginForm" component={LoginForm} />
) : (
<>
<Stack.Screen name="Home" component={Home} options={{ title: "Patient Dashboard" }} />
<Stack.Screen name="ClinicalStaff" component={ClinicalStaff} options={{ title: "Clinical Staff" }} />
<Stack.Screen name="Caregivers" component={Caregivers} />
<Stack.Screen name="Organizations" component={Organizations} />
<Stack.Screen name="Insurances" component={Insurances} />
<Stack.Screen name="PatientInfo" component={PatientInfo} options={{ title: "Patient Information" }} />
<Stack.Screen name="PatientProfile" component={PatientProfile} options={{ title: "Patient Profile" }} />
<Stack.Screen name="Auth" component={Auth} options={{ headerShown: false }} />
<Stack.Screen name="ServerView" component={ServerView} options={{ title: "" }} />
<Stack.Screen name="AddServer" component={AddServer} options={{ title: "New Server" }} />
<Stack.Screen name="ServerList" component={ServerList} />
<Stack.Screen name="Hub" component={Hub} />
<Stack.Screen name="Referrals" component={Referrals} />
<Stack.Screen name="ReferralView" component={ReferralView} />
<Stack.Screen name="Assessments" component={Assessments} />
<Stack.Screen name="Assessment" component={Assessment} />
<Stack.Screen name="Locations" component={Locations} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;
const Hub = ({ navigation }: NativeStackScreenProps<RootStackParamList, "Hub">) => {
return (
<View style={{
flex: 1,
alignItems: "center",
justifyContent: "space-around",
padding: 20
}}>
<Button
title="Home"
onPress={() => navigation.navigate("Home")}
/>
<Button
title="Servers"
onPress={() => navigation.navigate("ServerList")}
/>
<Button
title="Assessments"
onPress={() => navigation.navigate("Assessments")}
/>
<Button
title="clear async store"
onPress={() => AsyncStorage.clear()}
/>
</View>
);
}