Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add common typings for patient and person #1001

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/framework/esm-api/src/types/concept-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type OpenmrsResource } from './openmrs-resource';

export interface Concept extends OpenmrsResource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be OpenmrsResourceStrict too? Should it have more properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not every type needed by the Patient type (directly or transitively) is completely typed yet. Specifically this Concept type and the User type below are just using OpenmrsResource as a flexible placeholder for now, while still being more correct than any. A completely typed type should extend OpenmrsResourceStrict instead. This convention should allow us to add more typings piecemeal.

// TODO: add more fields
}
3 changes: 3 additions & 0 deletions packages/framework/esm-api/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export * from './attachments-types';
export * from './concept-resource';
export * from './fetch';
export * from './fhir-resource';
export * from './openmrs-resource';
export * from './user-resource';
export * from './patient-resource';
export * from './person-resource';
export * from './visit-resource';
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;
}
28 changes: 28 additions & 0 deletions packages/framework/esm-api/src/types/patient-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type OpenmrsResourceStrict } from './openmrs-resource';
import { type Person } from './person-resource';

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 extends OpenmrsResourceStrict {
identifiers?: PatientIdentifier[];
person?: Person;
voided?: boolean;
}

export interface PatientIdentifier extends OpenmrsResourceStrict {
identifier?: string;
identifierType?: PatientIdentifierType;
location?: Location;
preferred?: boolean;
voided?: boolean;
}
69 changes: 69 additions & 0 deletions packages/framework/esm-api/src/types/person-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { type Concept } from './concept-resource';
import { type OpenmrsResourceStrict, type OpenmrsResource } from './openmrs-resource';

export interface PersonAttribute extends OpenmrsResourceStrict {
attributeType?: OpenmrsResource;
value?: string;
voided?: boolean;
}

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 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 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;
}
13 changes: 7 additions & 6 deletions packages/framework/esm-api/src/types/user-resource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { type OpenmrsResource } from './openmrs-resource';
import { type Person } from './person-resource';

export interface Session {
allowedLocales?: Array<string>;
authenticated: boolean;
Expand Down Expand Up @@ -49,12 +52,6 @@ export interface SessionLocation {
links: Array<any>;
}

export interface Person {
uuid: string;
display: string;
links: Array<any>;
}

export interface Privilege {
uuid: string;
display: string;
Expand All @@ -66,3 +63,7 @@ export interface Role {
display: string;
links: Array<any>;
}

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