Skip to content

Commit

Permalink
(feat) O3-4043: Dispensing: Allow back dating dispense events for ret… (
Browse files Browse the repository at this point in the history
#122)

(update to latest Core libraries and fix usage of OpenMRS datepicker accordingly)
  • Loading branch information
mogoodrich authored Oct 8, 2024
1 parent a84de4c commit ca3c9ef
Show file tree
Hide file tree
Showing 8 changed files with 1,637 additions and 1,359 deletions.
16 changes: 6 additions & 10 deletions src/forms/medication-dispense-review.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ComboBox, Dropdown, NumberInput, Stack, TextArea } from '@carbon/react';
import { OpenmrsDatePicker, useLayoutType, useConfig, useSession, userHasAccess } from '@openmrs/esm-framework';
import {
getConceptCodingUuid,
getMedicationReferenceOrCodeableConcept,
getOpenMRSMedicineDrugName,
isSameDay,
} from '../utils';
import { getConceptCodingUuid, getMedicationReferenceOrCodeableConcept, getOpenMRSMedicineDrugName } from '../utils';
import MedicationCard from '../components/medication-card.component';
import { useMedicationCodeableConcept, useMedicationFormulations } from '../medication/medication.resource';
import { useMedicationRequest, usePrescriptionDetails } from '../medication-request/medication-request.resource';
Expand Down Expand Up @@ -506,13 +501,14 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
labelText={t('dispenseDate', 'Date of Dispense')}
minDate={prescriptionDate ? dayjs(prescriptionDate).startOf('day').toDate() : null}
maxDate={dayjs().toDate()}
onChange={(selectedDate) => {
const currentDate = dayjs(medicationDispense.whenHandedOver);
onChange={(input) => {
const currentDate = medicationDispense.whenHandedOver ? dayjs(medicationDispense.whenHandedOver) : null;
const selectedDate = dayjs(input);
updateMedicationDispense({
...medicationDispense,
whenHandedOver: isSameDay(currentDate, selectedDate)
whenHandedOver: currentDate?.isSame(selectedDate, 'day')
? currentDate.toISOString()
: selectedDate.toString(), // to preserve any time component, only update if the day actually changes
: selectedDate.toISOString(), // to preserve any time component, only update if the day actually changes
});
}}
value={dayjs(medicationDispense.whenHandedOver).toDate()}></OpenmrsDatePicker>
Expand Down
10 changes: 1 addition & 9 deletions src/location/location.resource.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import { openmrsFetch } from '@openmrs/esm-framework';
import { useLocationForFiltering } from './location.resource';
import { type PharmacyConfig } from '../config-schema';

jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
__esModule: true,
...originalModule,
openmrsFetch: jest.fn(() => 'mocked fetch'),
};
});

jest.mocked(openmrsFetch);
jest.mock('swr');

const pharmacyConfig: PharmacyConfig = {
Expand Down
10 changes: 1 addition & 9 deletions src/medication-dispense/medication-dispense.resource.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ import {
} from '../types';
import dayjs from 'dayjs';

jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
__esModule: true,
...originalModule,
openmrsFetch: jest.fn(() => 'mocked fetch'),
};
});

jest.mocked(openmrsFetch);
jest.mock('swr');

describe('Medication Dispense Resource tests', () => {
Expand Down
12 changes: 2 additions & 10 deletions src/medication-request/medication-request.resource.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import { openmrsFetch, parseDate } from '@openmrs/esm-framework';
import { MedicationRequestFulfillerStatus } from '../types';
import { JSON_MERGE_PATH_MIME_TYPE, OPENMRS_FHIR_EXT_REQUEST_FULFILLER_STATUS } from '../constants';

jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
__esModule: true,
...originalModule,
openmrsFetch: jest.fn(() => 'mocked fetch'),
};
});

jest.mocked(openmrsFetch);
jest.mock('swr');

describe('Medication Request Resource Test', () => {
Expand Down Expand Up @@ -1248,7 +1240,7 @@ describe('Medication Request Resource Test', () => {

// @ts-ignore
useSWR.mockImplementation(() => ({ data: { data: queryRequestBundle } }));
const { allergies, totalAllergies } = usePatientAllergies('558494fe-5850-4b34-a3bf-06550334ba4a', 10000);
const { totalAllergies } = usePatientAllergies('558494fe-5850-4b34-a3bf-06550334ba4a', 10000);
expect(totalAllergies).toBe(2);
// TODO allergy parsing doesn't seem to be working?
});
Expand Down
10 changes: 1 addition & 9 deletions src/medication/medication.resource.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { useMedicationCodeableConcept, useMedicationFormulations } from './medic
import useSWR from 'swr';
import { openmrsFetch } from '@openmrs/esm-framework';

jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
__esModule: true,
...originalModule,
openmrsFetch: jest.fn(() => 'mocked fetch'),
};
});

jest.mocked(openmrsFetch);
jest.mock('swr');

describe('Medication Resource Tests', () => {
Expand Down
17 changes: 1 addition & 16 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mutate } from 'swr';
import { type CalendarDate } from '@internationalized/date';
import {
type Coding,
type DosageInstruction,
Expand All @@ -22,7 +21,7 @@ import {
PRESCRIPTION_DETAILS_ENDPOINT,
PRESCRIPTIONS_TABLE_ENDPOINT,
} from './constants';
import dayjs, { type Dayjs } from 'dayjs';
import dayjs from 'dayjs';

const unitsDontMatchErrorMessage =
"Misconfiguration, please contact your System Administrator: Can't calculate quantity dispensed if units don't match. Likely issue: allowModifyingPrescription and restrictTotalQuantityDispensed configuration parameters both set to true. " +
Expand Down Expand Up @@ -591,17 +590,3 @@ export function sortMedicationDispensesByWhenHandedOver(a: MedicationDispense, b
return a.id.localeCompare(b.id); // just to enforce a standard order if two dates are equals
}
}

/**
* Given a dayJs date object and a CalendarDate date object, returns true if they represent the same day
*
* @param dayJsDate
* @param calendarDate
*/
export function isSameDay(dayJsDate: Dayjs, calendarDate: CalendarDate): boolean {
return (
dayJsDate.date() === calendarDate.day &&
dayJsDate.month() + 1 === calendarDate.month &&
dayJsDate.year() === calendarDate.year
);
}
26 changes: 11 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "esnext",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"skipLibCheck": true,
"moduleResolution": "node",
"lib": [
"dom",
"es2022",
"es5",
"scripthost",
"es2015",
"es2015.promise",
"es2016.array.include",
"es2018",
"es2020"
],
"resolveJsonModule": true,
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"target": "esnext",
"paths": {
"@openmrs/*": ["./node_modules/@openmrs/*"]
}
"@openmrs/*": ["./node_modules/@openmrs/*"],
"__mocks__": ["./__mocks__"],
"tools": ["./tools"],
},
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "esnext",
}
}
Loading

0 comments on commit ca3c9ef

Please sign in to comment.