From 3e6ee362c3feebe4462d0f20efead9069a69f493 Mon Sep 17 00:00:00 2001 From: Chi Bong Ho Date: Fri, 17 May 2024 17:03:47 -0400 Subject: [PATCH] improve typings --- .../esm-api/src/types/openmrs-resource.ts | 38 +++++- .../esm-api/src/types/patient-resource.ts | 36 ++++-- .../esm-api/src/types/person-resource.ts | 120 +++++++++--------- .../esm-api/src/types/user-resource.ts | 5 + 4 files changed, 123 insertions(+), 76 deletions(-) diff --git a/packages/framework/esm-api/src/types/openmrs-resource.ts b/packages/framework/esm-api/src/types/openmrs-resource.ts index 5a568b5eb..5a4a2b7df 100644 --- a/packages/framework/esm-api/src/types/openmrs-resource.ts +++ b/packages/framework/esm-api/src/types/openmrs-resource.ts @@ -1,5 +1,39 @@ -export interface OpenmrsResource { +import { type User } from './user-resource'; + +export interface OpenmrsResource extends OpenmrsResourceStrict { + [anythingElse: string]: any; +} + +/** + * Superclass for all Openmrs Resources, with strict typings. + * If the subclass does not have all attributes (including optional ones) + * accounted for, use OpenmrsResource instead. + */ +export interface OpenmrsResourceStrict { uuid: string; display?: string; - [anythingElse: string]: any; + links?: Array; + auditInfo?: AuditInfo; + resourceVersion?: string; +} + +export interface Link { + rel: string; + uri: string; + resourceAlias?: string; +} + +export interface AuditInfo { + dateCreated?: string; + creator?: User; + dateChanged?: string; + changedBy?: User; + voided?: boolean; + dateVoided?: string; + voidedBy?: User; + voidReason?: string; + retired?: boolean; + datedRetired?: string; + retiredBy?: User; + retireReason?: string; } diff --git a/packages/framework/esm-api/src/types/patient-resource.ts b/packages/framework/esm-api/src/types/patient-resource.ts index 440ec6b46..e6c5ad91f 100644 --- a/packages/framework/esm-api/src/types/patient-resource.ts +++ b/packages/framework/esm-api/src/types/patient-resource.ts @@ -1,20 +1,28 @@ -import { type OpenmrsResource } from './openmrs-resource'; +import { type OpenmrsResourceStrict } from './openmrs-resource'; import { type Person } from './person-resource'; -export interface PatientIdentifierType extends OpenmrsResource {} +export interface PatientIdentifierType extends OpenmrsResourceStrict { + name?: string; + description?: string; + format?: string; + formatDescription?: string; + required?: boolean; + validator?: string; + locationBehavior?: string; + uniquenessBehavior?: string; + retired?: boolean; +} -export interface Patient { - uuid: string; - display: string; - identifiers: PatientIdentifier[]; - person: Person; +export interface Patient extends OpenmrsResourceStrict { + identifiers?: PatientIdentifier[]; + person?: Person; + voided?: boolean; } -export interface PatientIdentifier { - uuid: string; - display: string; - identifier: string; - identifierType: PatientIdentifierType; - location: Location; - preferred: boolean; +export interface PatientIdentifier extends OpenmrsResourceStrict { + identifier?: string; + identifierType?: PatientIdentifierType; + location?: Location; + preferred?: boolean; + voided?: boolean; } diff --git a/packages/framework/esm-api/src/types/person-resource.ts b/packages/framework/esm-api/src/types/person-resource.ts index c857fe923..74dd1b285 100644 --- a/packages/framework/esm-api/src/types/person-resource.ts +++ b/packages/framework/esm-api/src/types/person-resource.ts @@ -1,69 +1,69 @@ import { type Concept } from './concept-resource'; -import { type OpenmrsResource } from './openmrs-resource'; +import { type OpenmrsResourceStrict, type OpenmrsResource } from './openmrs-resource'; -export interface PersonAttribute { - attributeType: OpenmrsResource; - display: string; - uuid: string; - value: string | number; +export interface PersonAttribute extends OpenmrsResourceStrict { + attributeType?: OpenmrsResource; + value?: string; + voided?: boolean; } -export interface Person { - uuid: string; - display: string; - gender: string; - age: number; - birthdate: string; - birthdateEstimated: boolean; - dead: boolean; - deathDate: string; - causeOfDeath: Concept; - preferredName: PersonName; - preferredAddress: PersonAddress; - names: Array; - addresses: Array; - attributes: Array; - birthtime: string; - deathdateEstimated: boolean; - causeOfDeathNonCoded: string; - links: Array; +export interface Person extends OpenmrsResourceStrict { + gender?: string; + age?: number; + birthdate?: string; + birthdateEstimated?: boolean; + dead?: boolean; + deathDate?: string | null; + causeOfDeath?: Concept | null; + preferredName?: PersonName; + preferredAddress?: PersonAddress; + names?: Array; + addresses?: Array; + attributes?: Array; + voided?: boolean; + birthtime?: string | null; + deathdateEstimated?: boolean; + causeOfDeathNonCoded?: string | null; } -export interface PersonName { - uuid: string; - display: string; - givenName: string; - middleName: string; - familyName: string; - familyName2: string; +export interface PersonName extends OpenmrsResourceStrict { + givenName?: string; + middleName?: string; + familyName?: string; + familyName2?: string; + preferred?: boolean; + prefix?: string; + familyNamePrefix?: string; + familyNameSuffix?: string; + degree?: string; + voided?: boolean; } -export interface PersonAddress { - uuid: string; - display: string; - preferred: true; - cityVillage: string; - stateProvince: string; - country: string; - postalCode: string; - countyDistrict: string; - startDate: string; - endDate: string; - latitude: string; - longitude: string; - address1: string; - address2: string; - address3: string; - address4: string; - address5: string; - address6: string; - address7: string; - address8: string; - address9: string; - address10: string; - address11: string; - address12: string; - address13: string; - address14: string; - address15: string; +export interface PersonAddress extends OpenmrsResourceStrict { + preferred?: boolean; + cityVillage?: string; + stateProvince?: string; + country?: string; + postalCode?: string; + countyDistrict?: string; + startDate?: string; + endDate?: string; + latitude?: string; + longitude?: string; + address1?: string; + address2?: string; + address3?: string; + address4?: string; + address5?: string; + address6?: string; + address7?: string; + address8?: string; + address9?: string; + address10?: string; + address11?: string; + address12?: string; + address13?: string; + address14?: string; + address15?: string; + voided?: boolean; } diff --git a/packages/framework/esm-api/src/types/user-resource.ts b/packages/framework/esm-api/src/types/user-resource.ts index 72f87f24d..310ccbc24 100644 --- a/packages/framework/esm-api/src/types/user-resource.ts +++ b/packages/framework/esm-api/src/types/user-resource.ts @@ -1,3 +1,4 @@ +import { type OpenmrsResource } from './openmrs-resource'; import { type Person } from './person-resource'; export interface Session { @@ -62,3 +63,7 @@ export interface Role { display: string; links: Array; } + +export interface User extends OpenmrsResource { + // TODO: add more attributes +}