@openmrs/esm-emr-api 6.3.1-pre.2986

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 (61) hide show
  1. package/.swcrc +16 -0
  2. package/.turbo/turbo-build.log +3 -0
  3. package/README.md +7 -0
  4. package/dist/attachments.d.ts +6 -0
  5. package/dist/attachments.js +35 -0
  6. package/dist/current-patient.d.ts +15 -0
  7. package/dist/current-patient.js +26 -0
  8. package/dist/index.d.ts +6 -0
  9. package/dist/index.js +6 -0
  10. package/dist/location.d.ts +4 -0
  11. package/dist/location.js +23 -0
  12. package/dist/public.d.ts +6 -0
  13. package/dist/public.js +6 -0
  14. package/dist/types/attachments-types.d.ts +26 -0
  15. package/dist/types/attachments-types.js +1 -0
  16. package/dist/types/diagnosis-resource.d.ts +22 -0
  17. package/dist/types/diagnosis-resource.js +2 -0
  18. package/dist/types/encounter-resource.d.ts +31 -0
  19. package/dist/types/encounter-resource.js +1 -0
  20. package/dist/types/fhir-resource.d.ts +40 -0
  21. package/dist/types/fhir-resource.js +1 -0
  22. package/dist/types/fhir.d.ts +1 -0
  23. package/dist/types/fhir.js +5 -0
  24. package/dist/types/index.d.ts +9 -0
  25. package/dist/types/index.js +9 -0
  26. package/dist/types/location-resource.d.ts +47 -0
  27. package/dist/types/location-resource.js +1 -0
  28. package/dist/types/obs-resource.d.ts +22 -0
  29. package/dist/types/obs-resource.js +1 -0
  30. package/dist/types/patient-resource.d.ts +24 -0
  31. package/dist/types/patient-resource.js +1 -0
  32. package/dist/types/visit-resource.d.ts +39 -0
  33. package/dist/types/visit-resource.js +1 -0
  34. package/dist/visit-type.d.ts +4 -0
  35. package/dist/visit-type.js +15 -0
  36. package/dist/visit-utils.d.ts +44 -0
  37. package/dist/visit-utils.js +75 -0
  38. package/mock-jest.ts +10 -0
  39. package/mock.ts +12 -0
  40. package/package.json +77 -0
  41. package/src/attachments.ts +43 -0
  42. package/src/current-patient.test.ts +53 -0
  43. package/src/current-patient.ts +58 -0
  44. package/src/index.ts +6 -0
  45. package/src/location.ts +36 -0
  46. package/src/public.ts +6 -0
  47. package/src/types/attachments-types.ts +28 -0
  48. package/src/types/diagnosis-resource.ts +24 -0
  49. package/src/types/encounter-resource.ts +36 -0
  50. package/src/types/fhir-resource.ts +32 -0
  51. package/src/types/fhir.ts +102 -0
  52. package/src/types/index.ts +9 -0
  53. package/src/types/location-resource.ts +49 -0
  54. package/src/types/obs-resource.ts +23 -0
  55. package/src/types/patient-resource.ts +27 -0
  56. package/src/types/visit-resource.ts +43 -0
  57. package/src/visit-type.ts +24 -0
  58. package/src/visit-utils.ts +127 -0
  59. package/tsconfig.build.json +9 -0
  60. package/tsconfig.json +5 -0
  61. package/vitest.config.ts +8 -0
package/.swcrc ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://swc.rs/schema.json",
3
+ "exclude": [".*\\.test\\..*", "setup-tests\\..*"],
4
+ "module": {
5
+ "type": "es6",
6
+ "resolveFully": true
7
+ },
8
+ "jsc": {
9
+ "parser": {
10
+ "syntax": "typescript",
11
+ "tsx": false
12
+ },
13
+ "target": "es2020",
14
+ "baseUrl": "src"
15
+ }
16
+ }
@@ -0,0 +1,3 @@
1
+ [0] Successfully compiled: 17 files with swc (139.26ms)
2
+ [0] swc --strip-leading-paths src -d dist exited with code 0
3
+ [1] tsc --project tsconfig.build.json exited with code 0
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # openmrs-esm-emr-api
2
+
3
+ openmrs-esm-emr-api exports functions that reflect shared EMR concerns. Things here are separated out from emr-api
4
+ to remove circular dependencies within the framewok.
5
+
6
+ See the [Retrieving and posting data](https://o3-docs.openmrs.org/docs/recipes/retrieve-and-post-data)
7
+ page of the Developer Documentation.
@@ -0,0 +1,6 @@
1
+ import type { UploadedFile } from './types';
2
+ export declare const attachmentUrl: string;
3
+ export declare function getAttachmentByUuid(attachmentUuid: string, abortController: AbortController): Promise<import("@openmrs/esm-api").FetchResponse<any>>;
4
+ export declare function getAttachments(patientUuid: string, includeEncounterless: boolean, abortController: AbortController): Promise<import("@openmrs/esm-api").FetchResponse<any>>;
5
+ export declare function createAttachment(patientUuid: string, fileToUpload: UploadedFile): Promise<import("@openmrs/esm-api").FetchResponse<any>>;
6
+ export declare function deleteAttachmentPermanently(attachmentUuid: string, abortController: AbortController): Promise<import("@openmrs/esm-api").FetchResponse<any>>;
@@ -0,0 +1,35 @@
1
+ /** @module @category API */ import { openmrsFetch, restBaseUrl } from "@openmrs/esm-api";
2
+ export const attachmentUrl = `${restBaseUrl}/attachment`;
3
+ export function getAttachmentByUuid(attachmentUuid, abortController) {
4
+ return openmrsFetch(`${attachmentUrl}/${attachmentUuid}`, {
5
+ signal: abortController.signal
6
+ });
7
+ }
8
+ export function getAttachments(patientUuid, includeEncounterless, abortController) {
9
+ return openmrsFetch(`${attachmentUrl}?patient=${patientUuid}&includeEncounterless=${includeEncounterless}`, {
10
+ signal: abortController.signal
11
+ });
12
+ }
13
+ export async function createAttachment(patientUuid, fileToUpload) {
14
+ const formData = new FormData();
15
+ formData.append('fileCaption', fileToUpload.fileDescription);
16
+ formData.append('patient', patientUuid);
17
+ if (fileToUpload.file) {
18
+ formData.append('file', fileToUpload.file, fileToUpload.fileName);
19
+ } else {
20
+ formData.append('file', new File([
21
+ ''
22
+ ], fileToUpload.fileName), fileToUpload.fileName);
23
+ formData.append('base64Content', fileToUpload.base64Content);
24
+ }
25
+ return openmrsFetch(`${attachmentUrl}`, {
26
+ method: 'POST',
27
+ body: formData
28
+ });
29
+ }
30
+ export function deleteAttachmentPermanently(attachmentUuid, abortController) {
31
+ return openmrsFetch(`${attachmentUrl}/${attachmentUuid}`, {
32
+ method: 'DELETE',
33
+ signal: abortController.signal
34
+ });
35
+ }
@@ -0,0 +1,15 @@
1
+ /// <reference types="fhir" />
2
+ /** @module @category API */
3
+ import { type FetchConfig, type FetchResponse } from '@openmrs/esm-api';
4
+ export type CurrentPatient = fhir.Patient | FetchResponse<fhir.Patient>;
5
+ export interface CurrentPatientOptions {
6
+ includeConfig?: boolean;
7
+ }
8
+ export interface PatientWithFullResponse extends CurrentPatientOptions {
9
+ includeConfig: true;
10
+ }
11
+ export interface OnlyThePatient extends CurrentPatientOptions {
12
+ includeConfig: false;
13
+ }
14
+ export type PatientUuid = string | null;
15
+ export declare function fetchCurrentPatient(patientUuid: PatientUuid, fetchInit?: FetchConfig, includeOfflinePatients?: boolean): Promise<fhir.Patient | null>;
@@ -0,0 +1,26 @@
1
+ /** @module @category API */ import { fhirBaseUrl, openmrsFetch } from "@openmrs/esm-api";
2
+ import { getSynchronizationItems } from "@openmrs/esm-offline";
3
+ export async function fetchCurrentPatient(patientUuid, fetchInit, includeOfflinePatients = true) {
4
+ if (patientUuid) {
5
+ let err = null;
6
+ const [onlinePatient, offlinePatient] = await Promise.all([
7
+ openmrsFetch(`${fhirBaseUrl}/Patient/${patientUuid}`, fetchInit).catch((e)=>err = e),
8
+ includeOfflinePatients ? getOfflineRegisteredPatientAsFhirPatient(patientUuid) : Promise.resolve(null)
9
+ ]);
10
+ if (onlinePatient.ok) {
11
+ return onlinePatient.data;
12
+ }
13
+ if (offlinePatient) {
14
+ return offlinePatient;
15
+ }
16
+ if (err) {
17
+ throw err;
18
+ }
19
+ }
20
+ return null;
21
+ }
22
+ async function getOfflineRegisteredPatientAsFhirPatient(patientUuid) {
23
+ const patientRegistrationSyncItems = await getSynchronizationItems('patient-registration');
24
+ const patientSyncItem = patientRegistrationSyncItems.find((item)=>item.fhirPatient.id === patientUuid);
25
+ return patientSyncItem?.fhirPatient ?? null;
26
+ }
@@ -0,0 +1,6 @@
1
+ export * from './attachments';
2
+ export * from './current-patient';
3
+ export * from './location';
4
+ export * from './types';
5
+ export * from './visit-type';
6
+ export * from './visit-utils';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./attachments.js";
2
+ export * from "./current-patient.js";
3
+ export * from "./location.js";
4
+ export * from "./types/index.js";
5
+ export * from "./visit-type.js";
6
+ export * from "./visit-utils.js";
@@ -0,0 +1,4 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { Location } from './types';
3
+ export declare function toLocationObject(openmrsRestForm: any): Location;
4
+ export declare function getLocations(tagUuidOrName?: string | null, query?: string | null): Observable<Array<Location>>;
@@ -0,0 +1,23 @@
1
+ /** @module @category API */ import { openmrsObservableFetch, restBaseUrl } from "@openmrs/esm-api";
2
+ import { map, take } from "rxjs/operators/index.js";
3
+ export function toLocationObject(openmrsRestForm) {
4
+ return {
5
+ uuid: openmrsRestForm.uuid,
6
+ display: openmrsRestForm.display
7
+ };
8
+ }
9
+ export function getLocations(tagUuidOrName = null, query = null) {
10
+ const params = new URLSearchParams();
11
+ if (tagUuidOrName) {
12
+ params.set('tag', tagUuidOrName);
13
+ }
14
+ if (query) {
15
+ params.set('q', query);
16
+ }
17
+ const queryString = params.toString();
18
+ const url = `${restBaseUrl}/location${queryString ? '?' + queryString : ''}`;
19
+ return openmrsObservableFetch(url).pipe(map((results)=>{
20
+ const locations = results.data.results.map(toLocationObject);
21
+ return locations;
22
+ })).pipe(take(1));
23
+ }
@@ -0,0 +1,6 @@
1
+ export * from './attachments';
2
+ export * from './current-patient';
3
+ export * from './types';
4
+ export * from './visit-utils';
5
+ export * from './visit-type';
6
+ export * from './location';
package/dist/public.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./attachments.js";
2
+ export * from "./current-patient.js";
3
+ export * from "./types/index.js";
4
+ export * from "./visit-utils.js";
5
+ export * from "./visit-type.js";
6
+ export * from "./location.js";
@@ -0,0 +1,26 @@
1
+ export interface UploadedFile {
2
+ file?: File;
3
+ base64Content: string;
4
+ fileName: string;
5
+ fileType: string;
6
+ fileDescription: string;
7
+ status?: 'uploading' | 'complete';
8
+ capturedFromWebcam?: boolean;
9
+ }
10
+ export interface Attachment {
11
+ id: string;
12
+ src: string;
13
+ filename: string;
14
+ dateTime: string;
15
+ bytesMimeType: string;
16
+ bytesContentFamily: string;
17
+ description?: string;
18
+ }
19
+ export interface AttachmentResponse {
20
+ bytesContentFamily: string;
21
+ bytesMimeType: string;
22
+ comment: string;
23
+ dateTime: string;
24
+ uuid: string;
25
+ filename?: string;
26
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,22 @@
1
+ import { type Concept, type ConceptClass, type OpenmrsResource } from '@openmrs/esm-api';
2
+ import { type Encounter } from './encounter-resource';
3
+ import { type Patient } from './patient-resource';
4
+ export interface Diagnosis extends OpenmrsResource {
5
+ diagnosis?: {
6
+ coded?: {
7
+ uuid: string;
8
+ display?: string;
9
+ name?: Concept;
10
+ datatype?: OpenmrsResource;
11
+ conceptClass?: ConceptClass;
12
+ };
13
+ nonCoded?: string;
14
+ };
15
+ patient?: Patient;
16
+ encounter?: Encounter;
17
+ certainty?: string;
18
+ rank?: number;
19
+ formFieldNamespace?: string;
20
+ formFieldPath?: string;
21
+ voided?: boolean;
22
+ }
@@ -0,0 +1,2 @@
1
+ // TODO: make this extends OpenmrsResourceStrict
2
+ export { };
@@ -0,0 +1,31 @@
1
+ import { type OpenmrsResource } from '@openmrs/esm-api';
2
+ import { type Diagnosis } from './diagnosis-resource';
3
+ import { type Location } from './location-resource';
4
+ import { type Obs } from './obs-resource';
5
+ import { type Patient } from './patient-resource';
6
+ import { type Visit } from './visit-resource';
7
+ export interface Encounter extends OpenmrsResource {
8
+ encounterDatetime?: string;
9
+ patient?: Patient;
10
+ location?: Location;
11
+ encounterType?: EncounterType;
12
+ obs?: Array<Obs>;
13
+ visit?: Visit;
14
+ encounterProviders?: Array<EncounterProvider>;
15
+ diagnoses?: Array<Diagnosis>;
16
+ form?: OpenmrsResource;
17
+ }
18
+ export interface EncounterType extends OpenmrsResource {
19
+ name?: string;
20
+ description?: string;
21
+ retired?: boolean;
22
+ }
23
+ export interface EncounterProvider extends OpenmrsResource {
24
+ provider?: OpenmrsResource;
25
+ encounterRole?: EncounterRole;
26
+ }
27
+ export interface EncounterRole extends OpenmrsResource {
28
+ name?: string;
29
+ description?: string;
30
+ retired?: boolean;
31
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,40 @@
1
+ export interface FHIRResource {
2
+ resource: {
3
+ code: {
4
+ coding: Array<FHIRCode>;
5
+ };
6
+ effectiveDateTime: Date;
7
+ encounter: {
8
+ reference: string;
9
+ type: string;
10
+ };
11
+ id: string;
12
+ issued: Date;
13
+ referenceRange: any;
14
+ resourceType: string;
15
+ status: string;
16
+ subject: {
17
+ display: string;
18
+ identifier: {
19
+ id: string;
20
+ system: string;
21
+ use: string;
22
+ value: string;
23
+ };
24
+ reference: string;
25
+ type: string;
26
+ };
27
+ valueQuantity: {
28
+ value: number;
29
+ };
30
+ valueString: string;
31
+ valueCodeableConcept: {
32
+ coding: Array<FHIRCode>;
33
+ };
34
+ };
35
+ }
36
+ export interface FHIRCode {
37
+ code: string;
38
+ system: string;
39
+ display?: string;
40
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export type ResourceName = 'DomainResource' | 'Organization' | 'Location' | 'HealthcareService' | 'Practitioner' | 'Patient' | 'RelatedPerson' | 'Device' | 'Account' | 'AllergyIntolerance' | 'Schedule' | 'Slot' | 'Appointment' | 'AppointmentResponse' | 'AuditEvent' | 'Basic' | 'BodySite' | 'Substance' | 'Medication' | 'Group' | 'Specimen' | 'DeviceComponent' | 'DeviceMetric' | 'ValueSet' | 'Questionnaire' | 'QuestionnaireResponse' | 'Observation' | 'FamilyMemberHistory' | 'DocumentReference' | 'DiagnosticOrder' | 'ProcedureRequest' | 'ReferralRequest' | 'Procedure' | 'ImagingStudy' | 'ImagingObjectSelection' | 'Media' | 'DiagnosticReport' | 'CommunicationRequest' | 'DeviceUseRequest' | 'MedicationOrder' | 'NutritionOrder' | 'Order' | 'ProcessRequest' | 'SupplyRequest' | 'VisionPrescription' | 'ClinicalImpression' | 'Condition' | 'EpisodeOfCare' | 'Encounter' | 'MedicationStatement' | 'RiskAssessment' | 'Goal' | 'CarePlan' | 'Composition' | 'Contract' | 'Coverage' | 'ClaimResponse' | 'Claim' | 'Communication' | 'StructureDefinition' | 'ConceptMap' | 'OperationDefinition' | 'Conformance' | 'DataElement' | 'DetectedIssue' | 'DeviceUseStatement' | 'DocumentManifest' | 'EligibilityRequest' | 'EligibilityResponse' | 'EnrollmentRequest' | 'EnrollmentResponse' | 'ExplanationOfBenefit' | 'Flag' | 'Immunization' | 'ImmunizationRecommendation' | 'ImplementationGuide' | 'List' | 'MedicationAdministration' | 'MedicationDispense' | 'OperationOutcome' | 'MessageHeader' | 'NamingSystem' | 'OrderResponse' | 'PaymentNotice' | 'PaymentReconciliation' | 'Person' | 'ProcessResponse' | 'Provenance' | 'SearchParameter' | 'Subscription' | 'SupplyDelivery' | 'TestScript' | 'Binary' | 'Bundle' | 'Parameters';
@@ -0,0 +1,5 @@
1
+ /*
2
+ Originally taken from https://github.com/FHIR/fhir.js/blob/ec82ccfc125e05dbb645f47c100fe60f2c34bb73/src/fhir.d.ts
3
+ Has been adapted to be even better - if we can get fhir.js to publish a good version to npm with better typedefs,
4
+ we can remove this file in favor of the one they maintain
5
+ */ export { };
@@ -0,0 +1,9 @@
1
+ export * from './attachments-types';
2
+ export * from './diagnosis-resource';
3
+ export * from './encounter-resource';
4
+ export * from './fhir';
5
+ export * from './fhir-resource';
6
+ export * from './location-resource';
7
+ export * from './obs-resource';
8
+ export * from './patient-resource';
9
+ export * from './visit-resource';
@@ -0,0 +1,9 @@
1
+ export * from "./attachments-types.js";
2
+ export * from "./diagnosis-resource.js";
3
+ export * from "./encounter-resource.js";
4
+ export * from "./fhir.js";
5
+ export * from "./fhir-resource.js";
6
+ export * from "./location-resource.js";
7
+ export * from "./obs-resource.js";
8
+ export * from "./patient-resource.js";
9
+ export * from "./visit-resource.js";
@@ -0,0 +1,47 @@
1
+ import { type OpenmrsResource } from '@openmrs/esm-api';
2
+ export interface Location extends OpenmrsResource {
3
+ name?: string;
4
+ description?: string;
5
+ cityVillage?: string;
6
+ stateProvince?: string;
7
+ country?: string;
8
+ postalCode?: string;
9
+ countyDistrict?: string;
10
+ latitude?: string;
11
+ longitude?: string;
12
+ address1?: string;
13
+ address2?: string;
14
+ address3?: string;
15
+ address4?: string;
16
+ address5?: string;
17
+ address6?: string;
18
+ address7?: string;
19
+ address8?: string;
20
+ address9?: string;
21
+ address10?: string;
22
+ address11?: string;
23
+ address12?: string;
24
+ address13?: string;
25
+ address14?: string;
26
+ address15?: string;
27
+ tags?: Array<OpenmrsResource>;
28
+ attributes?: Array<OpenmrsResource>;
29
+ parentLocation?: Location;
30
+ childLocation?: Location;
31
+ retired?: boolean;
32
+ }
33
+ export interface FHIRLocationResource {
34
+ resource: {
35
+ id: string;
36
+ name: string;
37
+ resourceType: string;
38
+ status: 'active' | 'inactive';
39
+ meta?: {
40
+ tag?: Array<{
41
+ code: string;
42
+ display: string;
43
+ system: string;
44
+ }>;
45
+ };
46
+ };
47
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,22 @@
1
+ import { type Concept, type OpenmrsResource, type Person } from '@openmrs/esm-api';
2
+ import { type Encounter } from './encounter-resource';
3
+ import { type Location } from './location-resource';
4
+ export interface Obs extends OpenmrsResource {
5
+ concept?: Concept;
6
+ person?: Person;
7
+ obsDatetime?: string;
8
+ accessionNumber?: string;
9
+ obsGroup?: Obs;
10
+ valueCodedName?: OpenmrsResource;
11
+ groupMembers?: Array<Obs>;
12
+ comment?: string;
13
+ location?: Location;
14
+ order?: OpenmrsResource;
15
+ encounter?: Encounter;
16
+ value?: number | string | boolean | OpenmrsResource;
17
+ valueModifier?: string;
18
+ formFilePath?: string;
19
+ formFiledNamespace?: string;
20
+ status?: 'PRELIMINARY' | 'FINAL' | 'AMENDED';
21
+ interpretation?: string;
22
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,24 @@
1
+ import { type OpenmrsResourceStrict, type Person } from '@openmrs/esm-api';
2
+ export interface PatientIdentifierType extends OpenmrsResourceStrict {
3
+ name?: string;
4
+ description?: string;
5
+ format?: string;
6
+ formatDescription?: string;
7
+ required?: boolean;
8
+ validator?: string;
9
+ locationBehavior?: string;
10
+ uniquenessBehavior?: string;
11
+ retired?: boolean;
12
+ }
13
+ export interface Patient extends OpenmrsResourceStrict {
14
+ identifiers?: PatientIdentifier[];
15
+ person?: Person;
16
+ voided?: boolean;
17
+ }
18
+ export interface PatientIdentifier extends OpenmrsResourceStrict {
19
+ identifier?: string;
20
+ identifierType?: PatientIdentifierType;
21
+ location?: Location;
22
+ preferred?: boolean;
23
+ voided?: boolean;
24
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,39 @@
1
+ import { type OpenmrsResource } from '@openmrs/esm-api';
2
+ import { type Encounter } from './encounter-resource';
3
+ import { type Patient } from './patient-resource';
4
+ export interface NewVisitPayload {
5
+ uuid?: string;
6
+ location: string;
7
+ patient?: string;
8
+ startDatetime: Date;
9
+ visitType: string;
10
+ stopDatetime?: Date;
11
+ attributes?: Array<{
12
+ attributeType: string;
13
+ value: string;
14
+ }>;
15
+ }
16
+ export type UpdateVisitPayload = Partial<NewVisitPayload> & {};
17
+ export interface Visit {
18
+ uuid: string;
19
+ display?: string;
20
+ encounters?: Array<Encounter>;
21
+ patient?: Patient;
22
+ visitType: VisitType;
23
+ location?: Location;
24
+ startDatetime: string;
25
+ stopDatetime?: string;
26
+ attributes?: Array<OpenmrsResource>;
27
+ [anythingElse: string]: any;
28
+ }
29
+ interface Location {
30
+ uuid: string;
31
+ display?: string;
32
+ name?: string;
33
+ }
34
+ export interface VisitType {
35
+ uuid: string;
36
+ display: string;
37
+ name?: string;
38
+ }
39
+ export {};
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,4 @@
1
+ import type { Observable } from 'rxjs';
2
+ import { type VisitType } from './types';
3
+ export declare function toVisitTypeObject(openmrsRestForm: any): VisitType;
4
+ export declare function getVisitTypes(): Observable<Array<VisitType>>;
@@ -0,0 +1,15 @@
1
+ /** @module @category API */ import { openmrsObservableFetch, restBaseUrl } from "@openmrs/esm-api";
2
+ import { map, take } from "rxjs/operators/index.js";
3
+ export function toVisitTypeObject(openmrsRestForm) {
4
+ return {
5
+ uuid: openmrsRestForm.uuid,
6
+ display: openmrsRestForm.display,
7
+ name: openmrsRestForm.name
8
+ };
9
+ }
10
+ export function getVisitTypes() {
11
+ return openmrsObservableFetch(`${restBaseUrl}/visittype`).pipe(map((results)=>{
12
+ const visitTypes = results.data.results.map(toVisitTypeObject);
13
+ return visitTypes;
14
+ })).pipe(take(1));
15
+ }
@@ -0,0 +1,44 @@
1
+ /** @module @category API */
2
+ import { type FetchResponse } from '@openmrs/esm-api';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ import { type NewVisitPayload, type UpdateVisitPayload, type Visit } from './types';
5
+ export interface VisitItem {
6
+ mode: VisitMode;
7
+ visitData?: Visit;
8
+ status: VisitStatus;
9
+ anythingElse?: any;
10
+ }
11
+ export declare enum VisitMode {
12
+ NEWVISIT = "startVisit",
13
+ EDITVISIT = "editVisit",
14
+ LOADING = "loadingVisit"
15
+ }
16
+ export declare enum VisitStatus {
17
+ NOTSTARTED = "notStarted",
18
+ ONGOING = "ongoing"
19
+ }
20
+ export interface VisitStoreState {
21
+ patientUuid: string | null;
22
+ manuallySetVisitUuid: string | null;
23
+ /**
24
+ * Stores a record of SWR mutate callbacks that should be called when
25
+ * the Visit with the specified uuid is modified. The callbacks are keyed
26
+ * by unique component IDs.
27
+ */
28
+ mutateVisitCallbacks: {
29
+ [componentId: string]: () => void;
30
+ };
31
+ }
32
+ export declare const defaultVisitCustomRepresentation: string;
33
+ export declare function getVisitStore(): import("zustand").StoreApi<VisitStoreState>;
34
+ export declare function setCurrentVisit(patientUuid: string, visitUuid: string): void;
35
+ export declare function saveVisit(payload: NewVisitPayload, abortController: AbortController): Promise<FetchResponse<Visit>>;
36
+ export declare function updateVisit(uuid: string, payload: UpdateVisitPayload, abortController: AbortController): Promise<FetchResponse<Visit>>;
37
+ /**
38
+ * @deprecated Use the `useVisit` hook instead.
39
+ */
40
+ export declare function getVisitsForPatient(patientUuid: string, abortController: AbortController, v?: string): Promise<FetchResponse<{
41
+ results: Array<Visit>;
42
+ }>>;
43
+ /** @deprecated */
44
+ export declare const getStartedVisit: BehaviorSubject<VisitItem | null>;
@@ -0,0 +1,75 @@
1
+ /** @module @category API */ import { openmrsFetch, restBaseUrl } from "@openmrs/esm-api";
2
+ import { getGlobalStore } from "@openmrs/esm-state";
3
+ import { BehaviorSubject } from "rxjs";
4
+ export var VisitMode = /*#__PURE__*/ function(VisitMode) {
5
+ VisitMode["NEWVISIT"] = "startVisit";
6
+ VisitMode["EDITVISIT"] = "editVisit";
7
+ VisitMode["LOADING"] = "loadingVisit";
8
+ return VisitMode;
9
+ }({});
10
+ export var VisitStatus = /*#__PURE__*/ function(VisitStatus) {
11
+ VisitStatus["NOTSTARTED"] = "notStarted";
12
+ VisitStatus["ONGOING"] = "ongoing";
13
+ return VisitStatus;
14
+ }({});
15
+ export const defaultVisitCustomRepresentation = 'custom:(uuid,display,voided,indication,startDatetime,stopDatetime,' + 'encounters:(uuid,display,encounterDatetime,' + 'form:(uuid,name),location:ref,' + 'encounterType:ref,' + 'encounterProviders:(uuid,display,' + 'provider:(uuid,display))),' + 'patient:(uuid,display),' + 'visitType:(uuid,name,display),' + 'attributes:(uuid,display,attributeType:(name,datatypeClassname,uuid),value),' + 'location:(uuid,name,display))';
16
+ const initialState = getVisitSessionStorage() || {
17
+ patientUuid: null,
18
+ manuallySetVisitUuid: null,
19
+ mutateVisitCallbacks: {}
20
+ };
21
+ export function getVisitStore() {
22
+ return getGlobalStore('visit', initialState);
23
+ }
24
+ export function setCurrentVisit(patientUuid, visitUuid) {
25
+ getVisitStore().setState({
26
+ patientUuid,
27
+ manuallySetVisitUuid: visitUuid
28
+ });
29
+ }
30
+ getVisitStore().subscribe((state)=>{
31
+ setVisitSessionStorage(state);
32
+ });
33
+ function setVisitSessionStorage(value) {
34
+ sessionStorage.setItem('openmrs:visitStoreState', JSON.stringify(value));
35
+ }
36
+ function getVisitSessionStorage() {
37
+ try {
38
+ return JSON.parse(sessionStorage.getItem('openmrs:visitStoreState') || 'null');
39
+ } catch (e) {
40
+ return null;
41
+ }
42
+ }
43
+ export function saveVisit(payload, abortController) {
44
+ return openmrsFetch(`${restBaseUrl}/visit`, {
45
+ signal: abortController.signal,
46
+ method: 'POST',
47
+ headers: {
48
+ 'Content-type': 'application/json'
49
+ },
50
+ body: payload
51
+ });
52
+ }
53
+ export function updateVisit(uuid, payload, abortController) {
54
+ return openmrsFetch(`${restBaseUrl}/visit/${uuid}`, {
55
+ signal: abortController.signal,
56
+ method: 'POST',
57
+ headers: {
58
+ 'Content-type': 'application/json'
59
+ },
60
+ body: payload
61
+ });
62
+ }
63
+ /**
64
+ * @deprecated Use the `useVisit` hook instead.
65
+ */ export function getVisitsForPatient(patientUuid, abortController, v) {
66
+ const custom = v ?? defaultVisitCustomRepresentation;
67
+ return openmrsFetch(`${restBaseUrl}/visit?patient=${patientUuid}&v=${custom}`, {
68
+ signal: abortController.signal,
69
+ method: 'GET',
70
+ headers: {
71
+ 'Content-type': 'application/json'
72
+ }
73
+ });
74
+ }
75
+ /** @deprecated */ export const getStartedVisit = new BehaviorSubject(null);
package/mock-jest.ts ADDED
@@ -0,0 +1,10 @@
1
+ export const setCurrentVisit = jest.fn();
2
+ export const attachmentUrl = '/ws/rest/v1/attachment';
3
+ export const getAttachmentByUuid = jest.fn();
4
+ export const getAttachments = jest.fn();
5
+ export const createAttachment = jest.fn();
6
+ export const deleteAttachmentPermanently = jest.fn();
7
+ export const updateVisit = jest.fn();
8
+ export const saveVisit = jest.fn();
9
+ export const getVisitsForPatient = jest.fn();
10
+ export const getStartedVisit = jest.fn();