@metriport/api-sdk 6.0.1-alpha.1 → 6.0.1-alpha.2

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 (53) hide show
  1. package/package.json +9 -3
  2. package/.eslintignore +0 -4
  3. package/.eslintrc.js +0 -7
  4. package/src/devices/client/metriport.ts +0 -261
  5. package/src/devices/client/models/get-connect-token-response.ts +0 -3
  6. package/src/devices/client/models/get-connected-users-response.ts +0 -5
  7. package/src/devices/client/models/get-metriport-user-id-response.ts +0 -3
  8. package/src/devices/client/models/settings-response.ts +0 -5
  9. package/src/devices/client/models/webhook-status-response.ts +0 -6
  10. package/src/devices/client/util/date-util.ts +0 -17
  11. package/src/devices/models/activity.ts +0 -22
  12. package/src/devices/models/biometrics.ts +0 -17
  13. package/src/devices/models/body.ts +0 -12
  14. package/src/devices/models/common/activity-durations.ts +0 -20
  15. package/src/devices/models/common/activity-log.ts +0 -33
  16. package/src/devices/models/common/activity-movement.ts +0 -15
  17. package/src/devices/models/common/aminos.ts +0 -22
  18. package/src/devices/models/common/blood-glucose.ts +0 -6
  19. package/src/devices/models/common/blood-pressure.ts +0 -10
  20. package/src/devices/models/common/connected-user-info.ts +0 -5
  21. package/src/devices/models/common/energy-expenditure.ts +0 -6
  22. package/src/devices/models/common/food.ts +0 -15
  23. package/src/devices/models/common/heart-rate-variability.ts +0 -12
  24. package/src/devices/models/common/heart-rate.ts +0 -9
  25. package/src/devices/models/common/lat-lon.ts +0 -4
  26. package/src/devices/models/common/macros.ts +0 -13
  27. package/src/devices/models/common/metadata.ts +0 -10
  28. package/src/devices/models/common/micros.ts +0 -27
  29. package/src/devices/models/common/provider-source.ts +0 -11
  30. package/src/devices/models/common/respiration.ts +0 -16
  31. package/src/devices/models/common/sample.ts +0 -7
  32. package/src/devices/models/common/sex.ts +0 -1
  33. package/src/devices/models/common/source-info.ts +0 -8
  34. package/src/devices/models/common/source-type.ts +0 -4
  35. package/src/devices/models/common/temperature.ts +0 -13
  36. package/src/devices/models/metriport-data.ts +0 -5
  37. package/src/devices/models/nutrition.ts +0 -10
  38. package/src/devices/models/sleep.ts +0 -29
  39. package/src/devices/models/user.ts +0 -14
  40. package/src/index.ts +0 -60
  41. package/src/medical/client/metriport.ts +0 -328
  42. package/src/medical/models/common/address.ts +0 -20
  43. package/src/medical/models/common/base-update.ts +0 -11
  44. package/src/medical/models/common/medical-data-source.ts +0 -3
  45. package/src/medical/models/common/us-data.ts +0 -56
  46. package/src/medical/models/demographics.ts +0 -63
  47. package/src/medical/models/document.ts +0 -49
  48. package/src/medical/models/facility.ts +0 -23
  49. package/src/medical/models/organization.ts +0 -24
  50. package/src/medical/models/patient.ts +0 -18
  51. package/src/shared.ts +0 -25
  52. package/tsconfig.json +0 -24
  53. package/tsconfig.ref.json +0 -7
@@ -1,7 +0,0 @@
1
- import { SourceInfo } from "./source-info";
2
-
3
- export interface Sample {
4
- time: string;
5
- value: number;
6
- data_source?: SourceInfo;
7
- }
@@ -1 +0,0 @@
1
- export type Sex = "male" | "female";
@@ -1,8 +0,0 @@
1
- import { SourceType } from "./source-type";
2
-
3
- export interface SourceInfo {
4
- source_type?: SourceType;
5
- id?: string;
6
- name?: string;
7
- type?: string;
8
- }
@@ -1,4 +0,0 @@
1
- export enum SourceType {
2
- manual = "MANUAL_ENTRY",
3
- device = "DEVICE",
4
- }
@@ -1,13 +0,0 @@
1
- import { Sample } from "./sample";
2
-
3
- export interface Temperature {
4
- core?: {
5
- avg_celcius?: number;
6
- samples_celcius?: Sample[];
7
- };
8
- delta_celcius?: number;
9
- skin?: {
10
- avg_celcius?: number;
11
- samples_celcius?: Sample[];
12
- };
13
- }
@@ -1,5 +0,0 @@
1
- import { Metadata } from "./common/metadata";
2
-
3
- export interface MetriportData {
4
- metadata: Metadata;
5
- }
@@ -1,10 +0,0 @@
1
- import { Aminos } from "./common/aminos";
2
- import { Macros } from "./common/macros";
3
- import { Micros } from "./common/micros";
4
- import { Food } from "./common/food";
5
- import { MetriportData } from "./metriport-data";
6
-
7
- export interface Nutrition extends MetriportData {
8
- summary?: { macros?: Macros; micros?: Micros; aminos?: Aminos };
9
- foods?: Food[];
10
- }
@@ -1,29 +0,0 @@
1
- import { HeartRate } from "./common/heart-rate";
2
- import { HeartRateVariability } from "./common/heart-rate-variability";
3
- import { Respiration } from "./common/respiration";
4
- import { Temperature } from "./common/temperature";
5
- import { MetriportData } from "./metriport-data";
6
-
7
- export interface Sleep extends MetriportData {
8
- start_time?: string;
9
- end_time?: string;
10
- durations?: SleepDurations;
11
- biometrics?: SleepBiometrics;
12
- // TODO: sleep events, ie times woken up?
13
- }
14
- export interface SleepDurations {
15
- total_seconds?: number;
16
- awake_seconds?: number;
17
- deep_seconds?: number;
18
- rem_seconds?: number;
19
- light_seconds?: number;
20
- in_bed_seconds?: number;
21
- time_to_fall_asleep_seconds?: number;
22
- no_data_seconds?: number;
23
- }
24
- export interface SleepBiometrics {
25
- heart_rate?: HeartRate;
26
- hrv?: HeartRateVariability;
27
- respiration?: Respiration;
28
- temperature?: Temperature;
29
- }
@@ -1,14 +0,0 @@
1
- import { Sex } from "./common/sex";
2
- import { MetriportData } from "./metriport-data";
3
-
4
- export interface User extends MetriportData {
5
- age?: number;
6
- first_name?: string;
7
- last_name?: string;
8
- city?: string;
9
- country?: string;
10
- date_of_birth?: string;
11
- email?: string;
12
- region?: string; // can be state, province, etc.
13
- sex?: Sex;
14
- }
package/src/index.ts DELETED
@@ -1,60 +0,0 @@
1
- // Devices API
2
- export { MetriportDevicesApi } from "./devices/client/metriport";
3
- export { Activity } from "./devices/models/activity";
4
- export { Biometrics } from "./devices/models/biometrics";
5
- export { Body } from "./devices/models/body";
6
- export { ProviderSource } from "./devices/models/common/provider-source";
7
- export { Food } from "./devices/models/common/food";
8
- export { Nutrition } from "./devices/models/nutrition";
9
- export { Sleep } from "./devices/models/sleep";
10
- export { User } from "./devices/models/user";
11
- export { ConnectedUserInfo } from "./devices/models/common/connected-user-info";
12
- export { SourceType } from "./devices/models/common/source-type";
13
- // Medical API
14
- export { MetriportMedicalApi } from "./medical/client/metriport";
15
- export { Address, addressSchema } from "./medical/models/common/address";
16
- export { BaseUpdate, baseUpdateSchema } from "./medical/models/common/base-update";
17
- export { USState, usStateSchema } from "./medical/models/common/us-data";
18
- export {
19
- contactSchema,
20
- Demographics,
21
- demographicsSchema,
22
- genderAtBirthSchema,
23
- PersonalIdentifier,
24
- personalIdentifierSchema,
25
- } from "./medical/models/demographics";
26
- export {
27
- DocumentList,
28
- documentListSchema,
29
- DocumentQuery,
30
- documentQuerySchema,
31
- DocumentQueryStatus,
32
- documentQueryStatusSchema,
33
- DocumentReference,
34
- documentReferenceSchema,
35
- } from "./medical/models/document";
36
- export {
37
- Facility,
38
- FacilityCreate,
39
- facilityCreateSchema,
40
- facilityListSchema,
41
- facilitySchema,
42
- } from "./medical/models/facility";
43
- export { MedicalDataSource } from "./medical/models/common/medical-data-source";
44
- export {
45
- Organization,
46
- OrganizationCreate,
47
- organizationCreateSchema,
48
- organizationSchema,
49
- OrgType,
50
- orgTypeSchema,
51
- } from "./medical/models/organization";
52
- export {
53
- Patient,
54
- PatientCreate,
55
- patientCreateSchema,
56
- patientListSchema,
57
- patientSchema,
58
- PatientUpdate,
59
- patientUpdateSchema,
60
- } from "./medical/models/patient";
@@ -1,328 +0,0 @@
1
- import axios, { AxiosInstance, AxiosStatic, CreateAxiosDefaults } from "axios";
2
- import {
3
- API_KEY_HEADER,
4
- BASE_ADDRESS,
5
- BASE_ADDRESS_SANDBOX,
6
- DEFAULT_AXIOS_TIMEOUT_MILLIS,
7
- } from "../../shared";
8
- import { getETagHeader } from "../models/common/base-update";
9
- import {
10
- documentListSchema,
11
- DocumentQuery,
12
- documentQuerySchema,
13
- DocumentReference,
14
- } from "../models/document";
15
- import { Facility, FacilityCreate, facilityListSchema, facilitySchema } from "../models/facility";
16
- import { Organization, OrganizationCreate, organizationSchema } from "../models/organization";
17
- import {
18
- Patient,
19
- PatientCreate,
20
- patientListSchema,
21
- patientSchema,
22
- PatientUpdate,
23
- } from "../models/patient";
24
-
25
- const NO_DATA_MESSAGE = "No data returned from API";
26
- const BASE_PATH = "/medical/v1";
27
- const ORGANIZATION_URL = `/organization`;
28
- const FACILITY_URL = `/facility`;
29
- const PATIENT_URL = `/patient`;
30
- const DOCUMENT_URL = `/document`;
31
-
32
- export type Options = {
33
- axios?: AxiosStatic; // Set axios if it fails to load
34
- timeout?: number;
35
- additionalHeaders?: Record<string, string>;
36
- } & (
37
- | {
38
- sandbox?: boolean;
39
- baseAddress?: never;
40
- }
41
- | {
42
- sandbox?: never;
43
- baseAddress?: string;
44
- }
45
- );
46
-
47
- export class MetriportMedicalApi {
48
- readonly api: AxiosInstance;
49
-
50
- static readonly headers = {
51
- clientApp: "x-metriport-client",
52
- };
53
-
54
- /**
55
- * Creates a new instance of the Metriport Medical API client.
56
- *
57
- * @param apiKey Your Metriport API key.
58
- * @param options - Optional parameters
59
- * @param options.additionalHeaders - HTTP headers to be used in all requests.
60
- * @param options.axios - Axios instance, default, useful when the dependency is not being imported
61
- * properly by NPM.
62
- * @param options.sandbox - Indicates whether to connect to the sandbox, default false.
63
- * @param options.timeout - Connection timeout in milliseconds, default 20 seconds.
64
- */
65
- constructor(apiKey: string, options: Options = {}) {
66
- const headers = { [API_KEY_HEADER]: apiKey, ...options.additionalHeaders };
67
- const { sandbox, timeout } = options;
68
-
69
- const baseURL =
70
- (options.baseAddress || (sandbox ? BASE_ADDRESS_SANDBOX : BASE_ADDRESS)) + BASE_PATH;
71
- const axiosConfig: CreateAxiosDefaults = {
72
- timeout: timeout ?? DEFAULT_AXIOS_TIMEOUT_MILLIS,
73
- baseURL,
74
- headers,
75
- };
76
-
77
- if (axios) {
78
- this.api = axios.create(axiosConfig);
79
- } else if (options.axios) {
80
- this.api = options.axios.create(axiosConfig);
81
- } else {
82
- throw new Error(`Failed to initialize Axios`);
83
- }
84
- }
85
-
86
- /**
87
- * Creates a new organization.
88
- *
89
- * @param data The data to be used to create a new organization.
90
- * @returns The created organization.
91
- */
92
- async createOrganization(data: OrganizationCreate): Promise<Organization> {
93
- const resp = await this.api.post(ORGANIZATION_URL, data);
94
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
95
- return organizationSchema.parse(resp.data);
96
- }
97
-
98
- /**
99
- * Updates an organization.
100
- *
101
- * @param organization The organization data to be updated.
102
- * @return The updated organization.
103
- */
104
- async updateOrganization(organization: Organization): Promise<Organization> {
105
- type FieldsToOmit = "id";
106
- const payload: Omit<Organization, FieldsToOmit> & Record<FieldsToOmit, undefined> = {
107
- ...organization,
108
- id: undefined,
109
- };
110
- const resp = await this.api.put(`${ORGANIZATION_URL}/${organization.id}`, payload, {
111
- headers: { ...getETagHeader(organization) },
112
- });
113
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
114
- return organizationSchema.parse(resp.data);
115
- }
116
-
117
- /**
118
- * Retrieve an organization representing this account.
119
- *
120
- * @returns The organization, or undefined if no organization has been created.
121
- */
122
- async getOrganization(): Promise<Organization | undefined> {
123
- const resp = await this.api.get(ORGANIZATION_URL);
124
- if (!resp.data) return undefined;
125
- return organizationSchema.parse(resp.data);
126
- }
127
-
128
- /**
129
- * Creates a new facility.
130
- *
131
- * @param data The data to be used to create a new facility.
132
- * @return The newly created facility.
133
- */
134
- async createFacility(data: FacilityCreate): Promise<Facility> {
135
- const resp = await this.api.post(`${FACILITY_URL}`, data);
136
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
137
- return facilitySchema.parse(resp.data);
138
- }
139
-
140
- /**
141
- * Returns a facility.
142
- *
143
- * @param id The ID of the facility to be returned.
144
- * @return The facilities.
145
- */
146
- async getFacility(id: string): Promise<Facility> {
147
- const resp = await this.api.get(`${FACILITY_URL}/${id}`);
148
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
149
- return facilitySchema.parse(resp.data);
150
- }
151
-
152
- /**
153
- * Updates a facility.
154
- *
155
- * @param facility The facility data to be updated.
156
- * @return The updated facility.
157
- */
158
- async updateFacility(facility: Facility): Promise<Facility> {
159
- type FieldsToOmit = "id";
160
- const payload: Omit<Facility, FieldsToOmit> & Record<FieldsToOmit, undefined> = {
161
- ...facility,
162
- id: undefined,
163
- };
164
- const resp = await this.api.put(`${FACILITY_URL}/${facility.id}`, payload, {
165
- headers: { ...getETagHeader(facility) },
166
- });
167
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
168
- return facilitySchema.parse(resp.data);
169
- }
170
-
171
- /**
172
- * Returns the facilities associated with this account.
173
- *
174
- * @return The list of facilities.
175
- */
176
- async listFacilities(): Promise<Facility[]> {
177
- const resp = await this.api.get(`${FACILITY_URL}`);
178
- if (!resp.data) [];
179
- return facilityListSchema.parse(resp.data).facilities;
180
- }
181
-
182
- /**
183
- * Creates a new patient at Metriport and HIEs.
184
- *
185
- * @param data The data to be used to create a new patient.
186
- * @param facilityId The facility providing the NPI to support this operation.
187
- * @return The newly created patient.
188
- */
189
- async createPatient(data: PatientCreate, facilityId: string): Promise<Patient> {
190
- const resp = await this.api.post(`${PATIENT_URL}`, data, {
191
- params: { facilityId },
192
- });
193
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
194
- return patientSchema.parse(resp.data);
195
- }
196
-
197
- /**
198
- * Returns a patient.
199
- *
200
- * @param id The ID of the patient to be returned.
201
- * @return The patients.
202
- */
203
- async getPatient(id: string): Promise<Patient> {
204
- const resp = await this.api.get(`${PATIENT_URL}/${id}`);
205
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
206
- return patientSchema.parse(resp.data);
207
- }
208
-
209
- /**
210
- * Updates a patient at Metriport and at HIEs the patient is linked to.
211
- *
212
- * @param patient The patient data to be updated.
213
- * @param facilityId The facility providing the NPI to support this operation.
214
- * @return The updated patient.
215
- */
216
- async updatePatient(patient: PatientUpdate, facilityId: string): Promise<Patient> {
217
- type FieldsToOmit = "id";
218
- const payload: Omit<PatientUpdate, FieldsToOmit> & Record<FieldsToOmit, undefined> = {
219
- ...patient,
220
- id: undefined,
221
- };
222
- const resp = await this.api.put(`${PATIENT_URL}/${patient.id}`, payload, {
223
- params: { facilityId },
224
- headers: { ...getETagHeader(patient) },
225
- });
226
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
227
- return patientSchema.parse(resp.data);
228
- }
229
-
230
- /**
231
- * Removes a patient at Metriport and at HIEs the patient is linked to.
232
- *
233
- * @param patientId The ID of the patient data to be deleted.
234
- * @param facilityId The facility providing the NPI to support this operation.
235
- */
236
- async deletePatient(patientId: string, facilityId: string, eTag?: string): Promise<void> {
237
- await this.api.delete(`${PATIENT_URL}/${patientId}`, {
238
- params: { facilityId },
239
- headers: { ...getETagHeader({ eTag }) },
240
- });
241
- }
242
-
243
- /**
244
- * Returns the patients associated with given facility.
245
- *
246
- * @param facilityId The ID of the facility.
247
- * @return The list of patients.
248
- */
249
- async listPatients(facilityId: string): Promise<Patient[]> {
250
- const resp = await this.api.get(`${PATIENT_URL}`, {
251
- params: { facilityId },
252
- });
253
- if (!resp.data) [];
254
- return patientListSchema.parse(resp.data).patients;
255
- }
256
-
257
- /**
258
- * Returns document references for the given patient across HIEs.
259
- *
260
- * @param patientId Patient ID for which to retrieve document metadata.
261
- * @param facilityId The facility providing the NPI to support this operation.
262
- * @return The list of available document references.
263
- */
264
- async listDocuments(patientId: string, facilityId: string): Promise<DocumentReference[]> {
265
- const resp = await this.api.get(`${DOCUMENT_URL}`, {
266
- params: {
267
- patientId,
268
- facilityId,
269
- },
270
- });
271
- if (!resp.data) return [];
272
- return documentListSchema.parse(resp.data).documents;
273
- }
274
-
275
- /**
276
- * Start a document query for the given patient across HIEs.
277
- *
278
- * @param patientId Patient ID for which to retrieve document metadata.
279
- * @param facilityId The facility providing the NPI to support this operation.
280
- * @return The document query progress & status indicating whether its being executed or not.
281
- */
282
- async startDocumentQuery(patientId: string, facilityId: string): Promise<DocumentQuery> {
283
- const resp = await this.api.post(`${DOCUMENT_URL}/query`, null, {
284
- params: {
285
- patientId,
286
- facilityId,
287
- },
288
- });
289
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
290
- return documentQuerySchema.parse(resp.data);
291
- }
292
-
293
- /**
294
- * Returns the document query status for the specified patient.
295
- *
296
- * @param patientId Patient ID for which to retrieve document query status.
297
- * @return The document query progress & status indicating whether its being executed or not.
298
- */
299
- async getDocumentQueryStatus(patientId: string): Promise<DocumentQuery> {
300
- const resp = await this.api.get(`${DOCUMENT_URL}/query`, {
301
- params: { patientId },
302
- });
303
- if (!resp.data) throw new Error(NO_DATA_MESSAGE);
304
- return documentQuerySchema.parse(resp.data);
305
- }
306
-
307
- /**
308
- * Returns a URL that can be used to download the document.
309
- *
310
- * @param req.query.fileName The file name of the document in s3.
311
- * @param req.query.conversionType The doc type to convert to. Valid values are "html" and "pdf".
312
- * @return presigned url
313
- */
314
- //eslint-disable-next-line @typescript-eslint/no-explicit-any
315
- async getDocumentUrl(
316
- fileName: string,
317
- conversionType?: "html" | "pdf"
318
- ): Promise<{ url: string }> {
319
- const resp = await this.api.get(`${DOCUMENT_URL}/downloadUrl`, {
320
- params: {
321
- fileName,
322
- conversionType,
323
- },
324
- });
325
-
326
- return resp.data;
327
- }
328
- }
@@ -1,20 +0,0 @@
1
- import { z } from "zod";
2
- import { usStateSchema } from "./us-data";
3
- import { defaultOptionalString, stripNonNumericChars } from "../../../shared";
4
-
5
- const zipLength = 5;
6
- export const addressSchema = z.object({
7
- addressLine1: defaultOptionalString,
8
- addressLine2: defaultOptionalString,
9
- city: defaultOptionalString,
10
- state: usStateSchema.or(defaultOptionalString),
11
- zip: z.coerce
12
- .string()
13
- .transform(zipStr => stripNonNumericChars(zipStr))
14
- .refine(zip => zip.length === zipLength, {
15
- message: `Zip must be a string consisting of ${zipLength} numbers`,
16
- }),
17
- country: defaultOptionalString.default("USA"), // here for backwards compatibility, we'll ignore this and always default to USA
18
- });
19
-
20
- export type Address = z.infer<typeof addressSchema>;
@@ -1,11 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export const baseUpdateSchema = z.object({
4
- id: z.string(),
5
- eTag: z.string().optional(),
6
- });
7
- export type BaseUpdate = z.infer<typeof baseUpdateSchema>;
8
-
9
- export function getETagHeader(entity: Pick<BaseUpdate, "eTag">) {
10
- return entity.eTag ? { "If-Match": entity.eTag } : undefined;
11
- }
@@ -1,3 +0,0 @@
1
- export enum MedicalDataSource {
2
- COMMONWELL = "COMMONWELL",
3
- }
@@ -1,56 +0,0 @@
1
- import { z } from "zod";
2
-
3
- export enum USState {
4
- AL = "AL",
5
- AK = "AK",
6
- AZ = "AZ",
7
- AR = "AR",
8
- CA = "CA",
9
- CO = "CO",
10
- CT = "CT",
11
- DE = "DE",
12
- DC = "DC",
13
- FL = "FL",
14
- GA = "GA",
15
- HI = "HI",
16
- ID = "ID",
17
- IL = "IL",
18
- IN = "IN",
19
- IA = "IA",
20
- KS = "KS",
21
- KY = "KY",
22
- LA = "LA",
23
- ME = "ME",
24
- MD = "MD",
25
- MA = "MA",
26
- MI = "MI",
27
- MN = "MN",
28
- MS = "MS",
29
- MO = "MO",
30
- MT = "MT",
31
- NE = "NE",
32
- NV = "NV",
33
- NH = "NH",
34
- NJ = "NJ",
35
- NM = "NM",
36
- NY = "NY",
37
- NC = "NC",
38
- ND = "ND",
39
- OH = "OH",
40
- OK = "OK",
41
- OR = "OR",
42
- PA = "PA",
43
- RI = "RI",
44
- SC = "SC",
45
- SD = "SD",
46
- TN = "TN",
47
- TX = "TX",
48
- UT = "UT",
49
- VT = "VT",
50
- VA = "VA",
51
- WA = "WA",
52
- WV = "WV",
53
- WI = "WI",
54
- WY = "WY",
55
- }
56
- export const usStateSchema = z.nativeEnum(USState);
@@ -1,63 +0,0 @@
1
- import { z } from "zod";
2
- import { addressSchema } from "./common/address";
3
- import { usStateSchema } from "./common/us-data";
4
- import {
5
- defaultDateString,
6
- defaultNameString,
7
- defaultOptionalString,
8
- stripNonNumericChars,
9
- } from "../../shared";
10
-
11
- const basePersonalIdentifierSchema = z.object({
12
- value: z.string(),
13
- period: z
14
- .object({
15
- start: z.string(),
16
- end: z.string().optional(),
17
- })
18
- .or(
19
- z.object({
20
- start: z.string().optional(),
21
- end: z.string(),
22
- })
23
- )
24
- .optional(),
25
- assigner: z.string().optional(),
26
- });
27
-
28
- export const driverLicenseIdentifierSchema = z.object({
29
- type: z.literal("driversLicense"),
30
- state: usStateSchema,
31
- });
32
-
33
- export const personalIdentifierSchema = basePersonalIdentifierSchema.merge(
34
- driverLicenseIdentifierSchema
35
- );
36
- export type PersonalIdentifier = z.infer<typeof personalIdentifierSchema>;
37
-
38
- export const genderAtBirthSchema = z.enum(["F", "M"]);
39
-
40
- const phoneLength = 10;
41
- export const contactSchema = z
42
- .object({
43
- phone: z.coerce
44
- .string()
45
- .transform(phone => stripNonNumericChars(phone))
46
- .refine(phone => phone.length === phoneLength, {
47
- message: `Phone must be a string consisting of ${phoneLength} numbers. For example: 4153245540`,
48
- })
49
- .or(defaultOptionalString),
50
- email: z.string().email().or(defaultOptionalString),
51
- })
52
- .refine(c => c.email || c.phone, { message: "Either email or phone must be present" });
53
-
54
- export const demographicsSchema = z.object({
55
- firstName: defaultNameString,
56
- lastName: defaultNameString,
57
- dob: defaultDateString,
58
- genderAtBirth: genderAtBirthSchema,
59
- personalIdentifiers: z.array(personalIdentifierSchema).optional(),
60
- address: z.array(addressSchema).or(addressSchema),
61
- contact: z.array(contactSchema).optional().or(contactSchema.optional()),
62
- });
63
- export type Demographics = z.infer<typeof demographicsSchema>;