Skip to content

Commit

Permalink
improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho committed May 17, 2024
1 parent 8216aef commit 3e6ee36
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 76 deletions.
38 changes: 36 additions & 2 deletions packages/framework/esm-api/src/types/openmrs-resource.ts
Original file line number Diff line number Diff line change
@@ -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<Link>;
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;
}
36 changes: 22 additions & 14 deletions packages/framework/esm-api/src/types/patient-resource.ts
Original file line number Diff line number Diff line change
@@ -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;
}
120 changes: 60 additions & 60 deletions packages/framework/esm-api/src/types/person-resource.ts
Original file line number Diff line number Diff line change
@@ -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<PersonName>;
addresses: Array<PersonAddress>;
attributes: Array<PersonAttribute>;
birthtime: string;
deathdateEstimated: boolean;
causeOfDeathNonCoded: string;
links: Array<any>;
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<PersonName>;
addresses?: Array<PersonAddress>;
attributes?: Array<PersonAttribute>;
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;
}
5 changes: 5 additions & 0 deletions packages/framework/esm-api/src/types/user-resource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type OpenmrsResource } from './openmrs-resource';
import { type Person } from './person-resource';

export interface Session {
Expand Down Expand Up @@ -62,3 +63,7 @@ export interface Role {
display: string;
links: Array<any>;
}

export interface User extends OpenmrsResource {
// TODO: add more attributes
}

0 comments on commit 3e6ee36

Please sign in to comment.