Skip to content

Commit

Permalink
refractor: move object type to types dir
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Mar 25, 2024
1 parent 2aab89e commit f5dca54
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
20 changes: 3 additions & 17 deletions packages/esm-patient-common-lib/src/orders/postOrders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { openmrsFetch } from '@openmrs/esm-framework';
import { getPatientUuidFromUrl } from '../get-patient-uuid-from-url';
import { type OrderBasketStore, orderBasketStore } from './store';
import { type OrderBasketItem, type OrderPost } from './types';
import { type ExtractedOrderErrorObject, type OrderBasketItem, type OrderPost } from './types';
import { type OderErrorObject } from './types';

export async function postOrders(encounterUuid: string, abortController: AbortController) {
const patientUuid = getPatientUuidFromUrl();
Expand Down Expand Up @@ -35,22 +36,7 @@ function postOrder(body: OrderPost, abortController?: AbortController) {
});
}

interface IErrorObject {
responseBody?: {
error?: {
message?: string;
fieldErrors?: {
[fieldName: string]: {
message: string;
[key: string]: string;
}[];
};
globalErrors?: string[];
};
};
}

function extractErrorDetails(errorObject: IErrorObject) {
function extractErrorDetails(errorObject: OderErrorObject): ExtractedOrderErrorObject {
const errorDetails = {
message: errorObject.responseBody?.error?.message,
fieldErrors: [],
Expand Down
22 changes: 21 additions & 1 deletion packages/esm-patient-common-lib/src/orders/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { type OpenmrsResource } from '@openmrs/esm-framework';

export interface ExtractedOrderErrorObject {
message: string;
fieldErrors: string[];
globalErrors: string[];
}
export interface OderErrorObject {
responseBody?: {
error?: {
message?: string;
fieldErrors?: {
[fieldName: string]: {
message: string;
[key: string]: string;
}[];
};
globalErrors?: string[];
};
};
}

export interface OrderBasketItem {
action: 'NEW' | 'REVISE' | 'DISCONTINUE' | 'RENEW' | undefined;
display: string;
Expand All @@ -15,7 +35,7 @@ export interface OrderBasketItem {
};
};
};
extractedOrderError?: { message: string; fieldErrors: string[]; globalErrors: string[] };
extractedOrderError?: ExtractedOrderErrorObject;
isOrderIncomplete?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ const schemaFields = {
asNeededCondition: z.string().nullable(),
duration: z.number().nullable(),
durationUnit: z.object({ ...comboSchema }).nullable(),
// t( 'pillDispensedErrorMessage', 'The quantity to dispense is required' )
pillsDispensed: z.number({
invalid_type_error: translateFrom(moduleName, 'pillDispensedErrorMessage', 'The quantity to dispense is required'),
}),
// t( 'selectQuantityUnitsErrorMessage', 'Dispensing requires a quantity unit' )
quantityUnits: z.object(
{ ...comboSchema },
{
Expand All @@ -105,6 +107,7 @@ const schemaFields = {
},
),
numRefills: z.number().nullable(),
// t( 'indicationErrorMessage', 'Please add an indication' )
indication: z.string().refine((value) => value !== '', {
message: translateFrom(moduleName, 'indicationErrorMessage', 'Please add an indication'),
}),
Expand Down
4 changes: 3 additions & 1 deletion packages/esm-patient-medications-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"goToDrugOrderForm": "Order form",
"increment": "Increment",
"indication": "Indication",
"indicationErrorMessage": "Please add an indication",
"indicationPlaceholder": "e.g. \"Hypertension\"",
"male": "Male",
"medicationDurationAndUnit": "for {{duration}} {{durationUnit}}",
Expand All @@ -58,6 +59,7 @@
"pastMedicationsTableTitle": "Past Medications",
"patientInstructions": "Patient instructions",
"patientInstructionsPlaceholder": "Additional dosing instructions (e.g. \"Take after eating\")",
"pillDispensedErrorMessage": "The quantity to dispense is required",
"prescriptionDuration": "2. Prescription duration",
"prescriptionRefills": "Prescription refills",
"print": "Print",
Expand All @@ -76,9 +78,9 @@
"searchResultsMatchesForTerm_one": "{{count}} result for \"{{searchTerm}}\"",
"searchResultsMatchesForTerm_other": "{{count}} results for \"{{searchTerm}}\"",
"selectFrequencyErrorMessage": "Please select a frequency",
"selectQuantityUnitsErrorMessage": "Dispensing requires a quantity unit",
"selectRouteErrorMessage": "Please select a route",
"selectUnitErrorMessage": "Please select a unit",
"selectQuantityUnitsErrorMessage": "Dispensing requires a quantity unit",
"startDate": "Start date",
"takeAsNeeded": "Take as needed",
"tryReopeningTheForm": "Please try launching the form again",
Expand Down

0 comments on commit f5dca54

Please sign in to comment.