oro-sdk 2.1.4-dev1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -0
  3. package/dist/client.d.ts +464 -0
  4. package/dist/helpers/client.d.ts +23 -0
  5. package/dist/helpers/index.d.ts +4 -0
  6. package/dist/helpers/patient-registration.d.ts +16 -0
  7. package/dist/helpers/vault-grants.d.ts +20 -0
  8. package/dist/helpers/workflow.d.ts +23 -0
  9. package/dist/index.d.ts +11 -0
  10. package/dist/index.js +8 -0
  11. package/dist/models/client.d.ts +28 -0
  12. package/dist/models/consult.d.ts +102 -0
  13. package/dist/models/diagnosis.d.ts +122 -0
  14. package/dist/models/error.d.ts +26 -0
  15. package/dist/models/guard.d.ts +119 -0
  16. package/dist/models/index.d.ts +9 -0
  17. package/dist/models/practice.d.ts +353 -0
  18. package/dist/models/shared.d.ts +8 -0
  19. package/dist/models/vault.d.ts +124 -0
  20. package/dist/models/workflow.d.ts +106 -0
  21. package/dist/oro-sdk.cjs.development.js +7685 -0
  22. package/dist/oro-sdk.cjs.development.js.map +1 -0
  23. package/dist/oro-sdk.cjs.production.min.js +2 -0
  24. package/dist/oro-sdk.cjs.production.min.js.map +1 -0
  25. package/dist/oro-sdk.esm.js +7692 -0
  26. package/dist/oro-sdk.esm.js.map +1 -0
  27. package/dist/sdk-revision/client.d.ts +21 -0
  28. package/dist/sdk-revision/index.d.ts +1 -0
  29. package/dist/services/api.d.ts +11 -0
  30. package/dist/services/axios.d.ts +14 -0
  31. package/dist/services/consult.d.ts +54 -0
  32. package/dist/services/diagnosis.d.ts +44 -0
  33. package/dist/services/external/clinia.d.ts +82 -0
  34. package/dist/services/external/index.d.ts +1 -0
  35. package/dist/services/guard.d.ts +92 -0
  36. package/dist/services/index.d.ts +10 -0
  37. package/dist/services/practice.d.ts +100 -0
  38. package/dist/services/teller.d.ts +9 -0
  39. package/dist/services/vault.d.ts +54 -0
  40. package/dist/services/workflow.d.ts +21 -0
  41. package/package.json +63 -0
  42. package/src/client.ts +1843 -0
  43. package/src/helpers/client.ts +199 -0
  44. package/src/helpers/index.ts +4 -0
  45. package/src/helpers/patient-registration.ts +490 -0
  46. package/src/helpers/vault-grants.ts +51 -0
  47. package/src/helpers/workflow.ts +261 -0
  48. package/src/index.ts +61 -0
  49. package/src/models/client.ts +33 -0
  50. package/src/models/consult.ts +110 -0
  51. package/src/models/diagnosis.ts +141 -0
  52. package/src/models/error.ts +13 -0
  53. package/src/models/guard.ts +136 -0
  54. package/src/models/index.ts +9 -0
  55. package/src/models/practice.ts +411 -0
  56. package/src/models/shared.ts +6 -0
  57. package/src/models/vault.ts +158 -0
  58. package/src/models/workflow.ts +142 -0
  59. package/src/sdk-revision/client.ts +62 -0
  60. package/src/sdk-revision/index.ts +1 -0
  61. package/src/services/api.ts +77 -0
  62. package/src/services/axios.ts +91 -0
  63. package/src/services/consult.ts +265 -0
  64. package/src/services/diagnosis.ts +144 -0
  65. package/src/services/external/clinia.ts +133 -0
  66. package/src/services/external/index.ts +1 -0
  67. package/src/services/guard.ts +228 -0
  68. package/src/services/index.ts +10 -0
  69. package/src/services/practice.ts +537 -0
  70. package/src/services/teller.ts +39 -0
  71. package/src/services/vault.ts +178 -0
  72. package/src/services/workflow.ts +36 -0
@@ -0,0 +1,144 @@
1
+ import {
2
+ Drug,
3
+ TreatmentPlan,
4
+ TreatmentPlans,
5
+ TreatmentPlansRequest,
6
+ TreatmentPlansResponse,
7
+ Uuid,
8
+ } from '..'
9
+ import { Diagnosis, Treatment, DiagnosisRequest, TreatmentRequest, TreatmentAndDrugPrescriptionUpdateRequest } from '../models/diagnosis'
10
+ import { APIService } from './api'
11
+
12
+ export class DiagnosisService {
13
+ constructor(private api: APIService, private baseURL: string) {}
14
+
15
+ public getDiagnoses(): Promise<Diagnosis[]> {
16
+ return this.api.get<Diagnosis[]>(`${this.baseURL}/v1/diagnoses`)
17
+ }
18
+
19
+ /**
20
+ * Get a diagnosis by uuid that belongs to your practice
21
+ * @param uuidDiagnosis the uuid of the diagnosis
22
+ * @returns a diagnosis
23
+ */
24
+ public getDiagnosisByUuid(uuidDiagnosis: Uuid): Promise<Diagnosis> {
25
+ return this.api.get<Diagnosis>(
26
+ `${this.baseURL}/v1/diagnoses/${uuidDiagnosis}`
27
+ )
28
+ }
29
+
30
+ public createDiagnosis(diagnosis: DiagnosisRequest): Promise<Diagnosis> {
31
+ return this.api.post<Diagnosis>(
32
+ `${this.baseURL}/v1/diagnoses`,
33
+ diagnosis
34
+ )
35
+ }
36
+
37
+ public updateDiagnosis(
38
+ uuid: string,
39
+ diagnosis: DiagnosisRequest
40
+ ): Promise<Diagnosis> {
41
+ return this.api.put<Diagnosis>(
42
+ `${this.baseURL}/v1/diagnoses/${uuid}`,
43
+ diagnosis
44
+ )
45
+ }
46
+
47
+ public getTreatmentsFromDiagnosisUuid(
48
+ diagnosisUuid: Uuid
49
+ ): Promise<Treatment[]> {
50
+ return this.api.get<Treatment[]>(
51
+ `${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments`
52
+ )
53
+ }
54
+
55
+ /**
56
+ * This function returns treatment plans associated to a consult
57
+ * @param uuidConsult the consult uuid to fetch
58
+ * @returns an array of TreatmentPlan
59
+ */
60
+ public getTreatmentPlansFromConsultUuid(
61
+ uuidConsult: Uuid
62
+ ): Promise<TreatmentPlan[]> {
63
+ return this.api.get<TreatmentPlan[]>(
64
+ `${this.baseURL}/v1/treatment-plans/`,
65
+ { params: { uuidConsult } }
66
+ )
67
+ }
68
+
69
+ /**
70
+ * creates a new treatment for the diagnosis specified
71
+ * @param diagnosisUuid uuid of the diagnosis that is linked to the treatment
72
+ * @param treatmentRequest the treatment to be inserted
73
+ */
74
+ public createTreatment(diagnosisUuid: string, treatmentRequest: TreatmentRequest) {
75
+ return this.api.post<Treatment>(
76
+ `${this.baseURL}/v1/diagnoses/${diagnosisUuid}/treatments`,
77
+ treatmentRequest
78
+ )
79
+ }
80
+
81
+ /**
82
+ * This function returns populated treatment plans associated to a consult
83
+ * @param uuidConsult the consult uuid to fetch
84
+ * @returns a TreatmentPlans object
85
+ */
86
+ public getTreatmentPlansPopulatedFromConsultUuid(
87
+ uuidConsult: Uuid
88
+ ): Promise<TreatmentPlans> {
89
+ return this.api.get<TreatmentPlans>(
90
+ `${this.baseURL}/v1/treatment-plans/`,
91
+ { params: { uuidConsult, populated: true } }
92
+ )
93
+ }
94
+
95
+ public postPlans(
96
+ plans: TreatmentPlansRequest
97
+ ): Promise<TreatmentPlansResponse> {
98
+ return this.api.post<TreatmentPlansResponse>(
99
+ `${this.baseURL}/v1/treatment-plans`,
100
+ plans
101
+ )
102
+ }
103
+
104
+ public updateTreatmentPlan(
105
+ uuidPlan: string,
106
+ uuidConsult: string,
107
+ diagnosisRequest: DiagnosisRequest,
108
+ plan: TreatmentAndDrugPrescriptionUpdateRequest
109
+ ): Promise<TreatmentPlan> {
110
+ return this.api.put<TreatmentPlan>(
111
+ `${this.baseURL}/v1/treatment-plans/${uuidPlan}`,
112
+ {
113
+ uuidConsult,
114
+ diagnosis: diagnosisRequest,
115
+ plan
116
+ }
117
+ )
118
+ }
119
+
120
+ public acceptTreatmentPlan(
121
+ uuidPlan: string,
122
+ uuidConsult: string
123
+ ): Promise<TreatmentPlan> {
124
+ return this.api.put<TreatmentPlan>(
125
+ `${this.baseURL}/v1/treatment-plans/${uuidPlan}/accept`,
126
+ { uuidConsult }
127
+ )
128
+ }
129
+
130
+ /**
131
+ * retrieves all the drugs of the specified practice
132
+ * @param uuidPractice
133
+ */
134
+ public async getAllDrugs(
135
+ uuidPractice: string
136
+ ): Promise<Drug[] | undefined> {
137
+ const res = await this.api.get<{foundDrugs: Drug[]}>(
138
+ `${this.baseURL}/v1/drugs/practice/${uuidPractice}`,
139
+ )
140
+ if(res && res.foundDrugs)
141
+ return res.foundDrugs
142
+ return undefined
143
+ }
144
+ }
@@ -0,0 +1,133 @@
1
+ import { AxiosService } from ".."
2
+
3
+ export type FacetFilter = 'type:PHARMACY' | 'type:CLINIC'
4
+
5
+ export interface CliniaResponse<T> {
6
+ facets: any
7
+ meta: {
8
+ query: string
9
+ page: number
10
+ numPages: number
11
+ perPage: number
12
+ total: number
13
+ }
14
+ records: T[]
15
+ }
16
+
17
+ export interface PlaceData {
18
+ id: string // The Clinia Id of the resource.
19
+ documentType: string // Type of document. This will always be set to health_facility.
20
+ type: string // The type of the resource. Possible Place types are detailed here.
21
+ name: string // The name of the resource.
22
+ address: AddressData // The address of the resource.
23
+ geoPoint: GeoPointData // The coordinates of the resource. Useful to locate resource on a map.
24
+ distance: number // The distance (in meters) the is from the location used to filter the query.
25
+ onlineBookingUrl: string // The url for the online booking system of the resource.
26
+ openingHours: Map<string, Array<IntervalData>> // The opening hours of the resource. This object has integers from 1 to 7 as keys, representing days of the week from Monday to Sunday as per ISO 8601.
27
+ phones: Array<PhoneData> // Phones associated with this resource.
28
+ socials: Array<SocialData> // The social links of the resource. Can be a website or a social media link.
29
+ note: string // Special notes on the resource.
30
+ services: Array<string> // The services offered by the resource.
31
+ owner: string // The owner of the resource in the Clinia ecosystem.
32
+ }
33
+
34
+ export interface AddressData {
35
+ streetAddress: string // Street number plus route name.
36
+ suiteNumber: string // Suite, door, appartment number.
37
+ postalCode: string // Postal code.
38
+ neighborhood: string // Neighborhood.
39
+ locality: string // Locality.
40
+ place: string // City.
41
+ region: string // Name of the region.
42
+ regionCode: string // ISO 3166-2 region code.
43
+ country: string // Name of the country.
44
+ countryCode: string // ISO 3166 country code
45
+ }
46
+
47
+ export interface PhoneData {
48
+ number: string //The phone number.
49
+ extension: string //The extension of the phone number.
50
+ countryCode: string //The country code associated with this phone number.
51
+ type:
52
+ | 'MAIN'
53
+ | 'ALTERNATE'
54
+ | 'RECEPTION'
55
+ | 'FAX'
56
+ | 'TEXT_TELEPHONE_TTY'
57
+ | 'INFO'
58
+ | 'OTHER' //The type of phone.
59
+ isTollFree: boolean //If the number is toll free or not.
60
+ }
61
+
62
+ export interface IntervalData {
63
+ start: string // Start time of the time interval. Format is HH:mm.
64
+ end: string // End time of the time interval. Format is HH:mm.
65
+ }
66
+
67
+ export interface GeoPointData {
68
+ lat: number // Latitude
69
+ lng: number // Longitude
70
+ }
71
+
72
+ export interface SocialData {
73
+ url: string // Url representing the link.
74
+ type: string // Type of link.
75
+ }
76
+
77
+ export class CliniaService {
78
+ private api: AxiosService
79
+
80
+ constructor(private url: string, apiKey: string, private locale?: string) {
81
+ this.api = new AxiosService({ headers: { 'X-Clinia-API-Key': apiKey } })
82
+ }
83
+
84
+ public placeSearch(searchOptions: {
85
+ locale?: string
86
+ query?: string
87
+ facetFilters?: FacetFilter[]
88
+ location?: string
89
+ aroundLatLng?: string
90
+ page?: number
91
+ }) {
92
+ const { locale, ...data } = searchOptions
93
+
94
+ return this.api.post<CliniaResponse<PlaceData>>(
95
+ `${this.url}/search/v1/indexes/health_facility/query`,
96
+ data,
97
+ {
98
+ params: { locale: locale ?? this.locale },
99
+ }
100
+ )
101
+ }
102
+
103
+ public placeMatch(
104
+ searchOptions: {
105
+ locale?: string
106
+ name?: string
107
+ address?: string
108
+ postalCode?: string
109
+ place?: string
110
+ region?: string
111
+ country?: string
112
+ },
113
+ type?: string
114
+ ) {
115
+ const { locale, ...data } = searchOptions
116
+
117
+ let request = this.api.post<PlaceData[]>(
118
+ `${this.url}/search/v1/matches`,
119
+ data,
120
+ {
121
+ params: { locale: locale ?? this.locale },
122
+ }
123
+ )
124
+
125
+ if (type) {
126
+ request = request.then((places) =>
127
+ places.filter((place) => place.type === type)
128
+ )
129
+ }
130
+
131
+ return request
132
+ }
133
+ }
@@ -0,0 +1 @@
1
+ export * from './clinia'
@@ -0,0 +1,228 @@
1
+ import { APIService } from './api'
2
+ import type { AxiosAuthRefreshRequestConfig } from 'axios-auth-refresh'
3
+ import {
4
+ AuthTokenRequest,
5
+ AuthTokenResponse,
6
+ AuthRecoverRequest,
7
+ IdentityCreateRequest,
8
+ IdentityUpdateRequest,
9
+ IdentityResponse,
10
+ QRCodeRequest,
11
+ QRCodeResponse,
12
+ Uuid,
13
+ WhoAmIResponse,
14
+ Base64String,
15
+ AuthenticationFailed,
16
+ IdentityCreationFailed,
17
+ AuthenticationBadRequest,
18
+ AuthenticationServerError,
19
+ IdentityCreationBadRequest,
20
+ IdentityCreationConflict,
21
+ Tokens
22
+ } from '../models'
23
+ import { AxiosError } from 'axios'
24
+
25
+ export interface GuardRequestConfig extends AxiosAuthRefreshRequestConfig {
26
+ useRefreshToken : boolean
27
+ }
28
+ export class GuardService {
29
+ private identityCache: Record<string, IdentityResponse>
30
+ private whoAmICache: Record<string, WhoAmIResponse>
31
+
32
+ constructor(private api: APIService, private baseURL: string) {
33
+ this.api.setAuthRefreshFn(this.authRefresh.bind(this))
34
+ this.identityCache = {}
35
+ this.whoAmICache = {}
36
+ }
37
+
38
+ /**
39
+ * Will replace access and refresh tokens with `tokens`
40
+ *
41
+ * Note:
42
+ * ```typescript
43
+ * setTokens({accessToken: undefined, refreshToken: 'aTokenValue'}) // will erase accessToken and set refreshToken with 'aTokenValue'
44
+ * setTokens({refreshToken: 'aTokenValue'}) // will keep actual value of accessToken and set refreshToken with 'aTokenValue'
45
+ *
46
+ * ```
47
+ * @param tokens
48
+ */
49
+ public setTokens(tokens: Tokens) {
50
+ this.api.setTokens({...this.api.getTokens() , ...tokens })
51
+ }
52
+
53
+ /**
54
+ * Allow to retrieve an access token and a refresh token in order
55
+ * to do authenticated request afterward
56
+ *
57
+ * @param req The credentials required to get an access token
58
+ * @returns AuthTokenResponse
59
+ */
60
+ public async authToken(req: AuthTokenRequest): Promise<AuthTokenResponse> {
61
+ let resp : AuthTokenResponse
62
+
63
+ try {
64
+ let config: AxiosAuthRefreshRequestConfig = {
65
+ skipAuthRefresh: true
66
+ }
67
+
68
+ resp = await this.api.post<AuthTokenResponse>(`${this.baseURL}/v1/auth/token`, req, config)
69
+
70
+ this.api.setTokens({
71
+ accessToken: resp.accessToken,
72
+ refreshToken: resp.refreshToken
73
+ })
74
+ } catch(e) {
75
+ if((e as any).isAxiosError){
76
+ const code = (e as AxiosError).response?.status
77
+ switch (code) {
78
+ case 400:
79
+ throw new AuthenticationBadRequest()
80
+ case 500:
81
+ throw new AuthenticationServerError()
82
+ case 401:
83
+ default:
84
+ throw new AuthenticationFailed()
85
+ }
86
+ }
87
+ throw new AuthenticationFailed()
88
+
89
+ }
90
+ return resp
91
+ }
92
+
93
+ /**
94
+ * Get new access and refresh token
95
+ *
96
+ * @returns AuthTokenResponse
97
+ */
98
+ public async authRefresh(refreshToken?: string): Promise<AuthTokenResponse> {
99
+ let config: GuardRequestConfig = {
100
+ skipAuthRefresh: true,
101
+ useRefreshToken: true
102
+ }
103
+ return this.api.put<AuthTokenResponse>(`${this.baseURL}/v1/auth/token`, null, config)
104
+ }
105
+
106
+
107
+ /**
108
+ * Call guard to overwrite existing refresh token cookie
109
+ *
110
+ * @returns void
111
+ */
112
+ public async authLogout(): Promise<void> {
113
+ return this.api.get<void>(`${this.baseURL}/v1/auth/logout`)
114
+ }
115
+
116
+
117
+ /**
118
+ * Call guard to attempt account recovery
119
+ *
120
+ * @param req The email address / practice of the account to recover
121
+ * @returns void
122
+ */
123
+ public async authRecover(req: AuthRecoverRequest): Promise<void> {
124
+ return this.api.post<void>(`${this.baseURL}/v1/auth/recover`, req)
125
+ }
126
+
127
+
128
+ /**
129
+ * Allow to create a new identity. The identity will then need to be confirmed
130
+ * via an email link
131
+ *
132
+ * @param req the information about the new identity to create
133
+ * @returns IdentityResponse
134
+ */
135
+ public async identityCreate(req: IdentityCreateRequest): Promise<IdentityResponse> {
136
+ let resp : IdentityResponse
137
+
138
+ try {
139
+ resp = await this.api.post<IdentityResponse>(`${this.baseURL}/v1/identities`, req)
140
+ this.api.setTokens({
141
+ refreshToken: resp.refreshToken
142
+ })
143
+ } catch (e) {
144
+ if((e as any).isAxiosError){
145
+ const code = (e as AxiosError).response?.status
146
+ switch (code) {
147
+ case 400:
148
+ throw new IdentityCreationBadRequest()
149
+ case 409:
150
+ throw new IdentityCreationConflict()
151
+ case 500:
152
+ default:
153
+ throw new IdentityCreationFailed()
154
+ }
155
+ }
156
+ throw new IdentityCreationFailed()
157
+ }
158
+ return resp
159
+ }
160
+
161
+
162
+ /**
163
+ * Retrieve an identity. Will return public fields only when requested
164
+ * without authentication
165
+ *
166
+ * @param identityID Unique id of the identity to retrieve
167
+ * @returns IdentityResponse
168
+ */
169
+ public async identityGet(
170
+ identityID: Uuid
171
+ ): Promise<IdentityResponse> {
172
+ const tokens = this.api.getTokens()
173
+ const cacheKey = (tokens.accessToken ?? '') + (tokens.refreshToken ?? '') + identityID
174
+
175
+ if (!tokens.accessToken || !this.identityCache[cacheKey]) {
176
+ this.identityCache[cacheKey] = await this.api.get<IdentityResponse>(
177
+ `${this.baseURL}/v1/identities/${identityID}`
178
+ )
179
+ }
180
+ return this.identityCache[cacheKey]
181
+ }
182
+
183
+
184
+ /**
185
+ * Get information about the current authenticated user
186
+ *
187
+ * @param refreshCache if true it will refresh the whoAmI cache (default: false)
188
+ * @returns WhoAmIResponse
189
+ */
190
+ public async whoAmI(refreshCache: boolean = false): Promise<WhoAmIResponse> {
191
+ const cacheKey = this.api.getTokens().accessToken ?? ''
192
+ if (!this.whoAmICache[cacheKey] || refreshCache) {
193
+ this.whoAmICache[cacheKey] = await this.api.get<WhoAmIResponse>(`${this.baseURL}/v1/auth/whoami`)
194
+ }
195
+ return this.whoAmICache[cacheKey]
196
+ }
197
+
198
+ /**
199
+ * Update an existing identity
200
+ *
201
+ * @param identityID unique id of identity to update
202
+ * @param req update request
203
+ * @returns IdentityResponse
204
+ */
205
+ public async identityUpdate(
206
+ identityID: Uuid,
207
+ req: IdentityUpdateRequest
208
+ ): Promise<IdentityResponse> {
209
+ return this.api.put<IdentityResponse>(`${this.baseURL}/v1/identities/${identityID}`, req)
210
+ }
211
+
212
+ /**
213
+ * Return base64 data representing a QR code that the
214
+ * current identity need in order to use MFA
215
+ *
216
+ * @param identityID unique id of the identity
217
+ * @param password the identity password (already hashed and in base64)
218
+ * @returns QRCodeResponse
219
+ */
220
+ public async identityMFAQRCode(
221
+ identityID: Uuid,
222
+ password: Base64String
223
+ ): Promise<QRCodeResponse> {
224
+ const req: QRCodeRequest = { password }
225
+ return this.api.post<QRCodeResponse>(`${this.baseURL}/v1/identities/${identityID}/mfa`, req, { headers: { 'Accept': 'application/json' } })
226
+ }
227
+ }
228
+
@@ -0,0 +1,10 @@
1
+ export * from './axios'
2
+ export * from './api'
3
+ export * from './consult'
4
+ export * from './diagnosis'
5
+ export * from './guard'
6
+ export * from './practice'
7
+ export * from './teller'
8
+ export * from './vault'
9
+ export * from './workflow'
10
+ export * from './external'