Skip to content

Commit

Permalink
(feat) O3-3416 make useVisit() take in optional custom representation (
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho authored Jun 14, 2024
1 parent 6c25a8d commit e39ca12
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 44 deletions.
1 change: 0 additions & 1 deletion packages/apps/esm-login-app/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"back": "Back",
"backToUserNameIconLabel": "Back to username",
"cancel": "Cancel",
"change": "Change",
"continue": "Continue",
"errorLoadingLoginLocations": "Error loading login locations",
Expand Down
11 changes: 7 additions & 4 deletions packages/framework/esm-api/src/shared-api-objects/visit-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import type { FetchResponse, NewVisitPayload, UpdateVisitPayload, Visit } from '
import { getGlobalStore } from '@openmrs/esm-state';

export const defaultVisitCustomRepresentation =
'custom:(uuid,encounters:(uuid,encounterDatetime,' +
'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,uuid),' +
'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),startDatetime,stopDatetime)';
'location:(uuid,name,display))';

export interface VisitStoreState {
patientUuid: string | null;
Expand Down
97 changes: 72 additions & 25 deletions packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@
- [canAccessStorage](API.md#canaccessstorage)
- [daysIntoYear](API.md#daysintoyear)
- [displayName](API.md#displayname)
- [formatPatientName](API.md#formatpatientname)
- [formattedName](API.md#formattedname)
- [getDefaultsFromConfigSchema](API.md#getdefaultsfromconfigschema)
- [getPatientName](API.md#getpatientname)
- [isSameDay](API.md#issameday)
- [isVersionSatisfied](API.md#isversionsatisfied)
- [retry](API.md#retry)
Expand Down Expand Up @@ -981,7 +983,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:100](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L100)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:103](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L103)

___

Expand Down Expand Up @@ -1959,7 +1961,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:27](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L27)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:30](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L30)

___

Expand Down Expand Up @@ -1995,7 +1997,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:51](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L51)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:54](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L54)

___

Expand Down Expand Up @@ -2196,7 +2198,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:73](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L73)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:76](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L76)

___

Expand All @@ -2217,7 +2219,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:31](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L31)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:34](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L34)

___

Expand Down Expand Up @@ -2342,7 +2344,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:84](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L84)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:87](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L87)

___

Expand Down Expand Up @@ -2471,7 +2473,7 @@ ___

### useVisit

**useVisit**(`patientUuid`): [`VisitReturnType`](interfaces/VisitReturnType.md)
**useVisit**(`patientUuid`, `representation?`): [`VisitReturnType`](interfaces/VisitReturnType.md)

This React hook returns visit information if the patient UUID is not null. There are
potentially two relevant visits at a time: "active" and "current".
Expand All @@ -2491,17 +2493,18 @@ API call is in progress. `mutate` refreshes the data from both API calls.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `patientUuid` | `string` | Unique patient identifier `string` |
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `patientUuid` | `string` | `undefined` | Unique patient identifier `string` |
| `representation` | `string` | `defaultVisitCustomRepresentation` | The custom representation of the visit |

#### Returns

[`VisitReturnType`](interfaces/VisitReturnType.md)

#### Defined in

[packages/framework/esm-react-utils/src/useVisit.ts:41](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useVisit.ts#L41)
[packages/framework/esm-react-utils/src/useVisit.ts:42](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-react-utils/src/useVisit.ts#L42)

___

Expand Down Expand Up @@ -6266,32 +6269,27 @@ ___

**displayName**(`patient`): `string`

Gets the formatted display name for a patient.

The display name will be taken from the patient's 'usual' name,
or may fall back to the patient's 'official' name.
**`deprecated`** Use `getPatientName`

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `patient` | `Patient` | The patient details in FHIR format. |
| Name | Type |
| :------ | :------ |
| `patient` | `Patient` |

#### Returns

`string`

The patient's display name or an empty string if name is not present.

#### Defined in

[packages/framework/esm-utils/src/patient-helpers.ts:14](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L14)
[packages/framework/esm-utils/src/patient-helpers.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L20)

___

### formattedName
### formatPatientName

**formattedName**(`name`): `string`
**formatPatientName**(`name`): `string`

Get a formatted display string for an FHIR name.

Expand All @@ -6309,7 +6307,29 @@ The formatted display name or an empty string if name is undefined.

#### Defined in

[packages/framework/esm-utils/src/patient-helpers.ts:24](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L24)
[packages/framework/esm-utils/src/patient-helpers.ts:29](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L29)

___

### formattedName

**formattedName**(`name`): `string`

**`deprecated`** Use `formatPatientName`

#### Parameters

| Name | Type |
| :------ | :------ |
| `name` | `undefined` \| `HumanName` |

#### Returns

`string`

#### Defined in

[packages/framework/esm-utils/src/patient-helpers.ts:35](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L35)

___

Expand Down Expand Up @@ -6348,6 +6368,33 @@ need to override some of the default values.

___

### getPatientName

**getPatientName**(`patient`): `string`

Gets the formatted display name for a patient.

The display name will be taken from the patient's 'usual' name,
or may fall back to the patient's 'official' name.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `patient` | `Patient` | The patient details in FHIR format. |

#### Returns

`string`

The patient's display name or an empty string if name is not present.

#### Defined in

[packages/framework/esm-utils/src/patient-helpers.ts:14](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L14)

___

### isSameDay

**isSameDay**(`firstDate`, `secondDate`): `boolean`
Expand Down Expand Up @@ -6466,7 +6513,7 @@ the preferred name for the patient, or undefined if no acceptable name could be

#### Defined in

[packages/framework/esm-utils/src/patient-helpers.ts:47](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L47)
[packages/framework/esm-utils/src/patient-helpers.ts:57](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/patient-helpers.ts#L57)

___

Expand Down
6 changes: 3 additions & 3 deletions packages/framework/esm-framework/docs/enums/VisitMode.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:111](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L111)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:114](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L114)

___

Expand All @@ -28,7 +28,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:112](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L112)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:115](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L115)

___

Expand All @@ -38,4 +38,4 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:110](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L110)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:113](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L113)
4 changes: 2 additions & 2 deletions packages/framework/esm-framework/docs/enums/VisitStatus.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:116](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L116)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:119](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L119)

___

Expand All @@ -27,4 +27,4 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:117](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L117)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:120](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L120)
8 changes: 4 additions & 4 deletions packages/framework/esm-framework/docs/interfaces/VisitItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:106](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L106)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:109](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L109)

___

Expand All @@ -29,7 +29,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:103](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L103)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:106](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L106)

___

Expand All @@ -39,7 +39,7 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:105](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L105)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:108](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L108)

___

Expand All @@ -49,4 +49,4 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:104](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L104)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:107](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L107)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L20)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L23)

___

Expand All @@ -27,4 +27,4 @@ ___

#### Defined in

[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:19](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L19)
[packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L22)
7 changes: 4 additions & 3 deletions packages/framework/esm-react-utils/src/useVisit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ export interface VisitReturnType {
* API call is in progress. `mutate` refreshes the data from both API calls.
*
* @param patientUuid Unique patient identifier `string`
* @param representation The custom representation of the visit
*/
export function useVisit(patientUuid: string): VisitReturnType {
export function useVisit(patientUuid: string, representation = defaultVisitCustomRepresentation): VisitReturnType {
const { patientUuid: visitStorePatientUuid, manuallySetVisitUuid } = useStore(getVisitStore());
// Ignore the visit store data if it is not for this patient
const retrospectiveVisitUuid = patientUuid && visitStorePatientUuid == patientUuid ? manuallySetVisitUuid : null;
const activeVisitUrlSuffix = `?patient=${patientUuid}&v=${defaultVisitCustomRepresentation}&includeInactive=false`;
const retrospectiveVisitUrlSuffix = `/${retrospectiveVisitUuid}`;
const activeVisitUrlSuffix = `?patient=${patientUuid}&v=${representation}&includeInactive=false`;
const retrospectiveVisitUrlSuffix = `/${retrospectiveVisitUuid}?v=${representation}`;

const {
data: activeData,
Expand Down

0 comments on commit e39ca12

Please # to comment.