diff --git a/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx b/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx index 343610da63..f67d0c7206 100644 --- a/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx +++ b/packages/esm-patient-medications-app/src/add-drug-order/drug-order-form.component.tsx @@ -25,7 +25,15 @@ import { Add, ArrowLeft, Subtract } from '@carbon/react/icons'; import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { Controller, useController, useForm } from 'react-hook-form'; -import { age, formatDate, parseDate, useConfig, useLayoutType, usePatient } from '@openmrs/esm-framework'; +import { + age, + formatDate, + parseDate, + translateFrom, + useConfig, + useLayoutType, + usePatient, +} from '@openmrs/esm-framework'; import { useOrderConfig } from '../api/order-config'; import { type ConfigObject } from '../config-schema'; import type { @@ -37,6 +45,7 @@ import type { QuantityUnit, } from '../types'; import styles from './drug-order-form.scss'; +import { moduleName } from '../dashboard.meta'; export interface DrugOrderFormProps { initialOrderBasketItem: DrugOrderBasketItem; @@ -51,10 +60,32 @@ const comboSchema = { }; const schemaFields = { - freeTextDosage: z.string().refine((value) => value !== '', { message: 'Add free dosage note' }), - dosage: z.number({ invalid_type_error: 'A dosage is required' }), - unit: z.object({ ...comboSchema }, { invalid_type_error: 'Please select a unit' }), - route: z.object({ ...comboSchema }, { invalid_type_error: 'Please select a route' }), + // t( 'freeDosageErrorMessage', 'Add free dosage note') + freeTextDosage: z.string().refine((value) => value !== '', { + message: translateFrom(moduleName, 'freeDosageErrorMessage', 'Add free dosage note'), + }), + + // t( 'dosageRequiredErrorMessage', 'A dosage is required' ) + dosage: z.number({ + invalid_type_error: translateFrom(moduleName, 'dosageRequiredErrorMessage', 'A dosage is required'), + }), + + // t( 'selectUnitErrorMessage', 'Please select a unit' ) + unit: z.object( + { ...comboSchema }, + { + invalid_type_error: translateFrom(moduleName, 'selectUnitErrorMessage', 'Please select a unit'), + }, + ), + + // t( 'selectRouteErrorMessage', 'Please select a route' ) + route: z.object( + { ...comboSchema }, + { + invalid_type_error: translateFrom(moduleName, 'selectRouteErrorMessage', 'Please select a route'), + }, + ), + patientInstructions: z.string().nullable(), asNeeded: z.boolean(), asNeededCondition: z.string().nullable(), @@ -63,9 +94,17 @@ const schemaFields = { pillsDispensed: z.number().nullable(), quantityUnits: z.object({ ...comboSchema }).nullable(), numRefills: z.number().nullable(), - indication: z.string().refine((value) => value !== '', { message: 'Please add an indication' }), + indication: z.string().refine((value) => value !== '', { + message: translateFrom(moduleName, 'indicationErrorMessage', 'Please add an indication'), + }), startDate: z.date(), - frequency: z.object({ ...comboSchema }, { invalid_type_error: 'Please select a frequency' }), + // t( 'selectFrequencyErrorMessage', 'Please select a frequency' ) + frequency: z.object( + { ...comboSchema }, + { + invalid_type_error: translateFrom(moduleName, 'selectFrequencyErrorMessage', 'Please select a frequency'), + }, + ), }; const medicationOrderFormSchema = z.discriminatedUnion('isFreeTextDosage', [ diff --git a/packages/esm-patient-medications-app/src/dashboard.meta.ts b/packages/esm-patient-medications-app/src/dashboard.meta.ts index d33df8fb7b..9f92279fe5 100644 --- a/packages/esm-patient-medications-app/src/dashboard.meta.ts +++ b/packages/esm-patient-medications-app/src/dashboard.meta.ts @@ -1,3 +1,4 @@ +export const moduleName = '@openmrs/esm-patient-medications-app'; export const dashboardMeta = { slot: 'patient-chart-medications-dashboard-slot', columns: 1, diff --git a/packages/esm-patient-medications-app/src/index.ts b/packages/esm-patient-medications-app/src/index.ts index ce579a3bf7..409e67d091 100644 --- a/packages/esm-patient-medications-app/src/index.ts +++ b/packages/esm-patient-medications-app/src/index.ts @@ -1,14 +1,12 @@ import { defineConfigSchema, getAsyncLifecycle, getSyncLifecycle } from '@openmrs/esm-framework'; import { createDashboardLink, registerWorkspace } from '@openmrs/esm-patient-common-lib'; import { configSchema } from './config-schema'; -import { dashboardMeta } from './dashboard.meta'; +import { dashboardMeta, moduleName } from './dashboard.meta'; import medicationsSummaryComponent from './medications-summary/medications-summary.component'; import activeMedicationsComponent from './active-medications/active-medications.component'; export const importTranslation = require.context('../translations', false, /.json$/, 'lazy'); -const moduleName = '@openmrs/esm-patient-medications-app'; - const options = { featureName: 'patient-medications', moduleName, diff --git a/packages/esm-patient-medications-app/translations/en.json b/packages/esm-patient-medications-app/translations/en.json index 0317265b52..3d614d294e 100644 --- a/packages/esm-patient-medications-app/translations/en.json +++ b/packages/esm-patient-medications-app/translations/en.json @@ -12,6 +12,7 @@ "discontinue": "Discontinue", "dispensingInformation": "3. Dispensing instructions", "dosageInstructions": "1. Dosage instructions", + "dosageRequiredErrorMessage": "A dosage is required", "dose": "Dose", "drugAlreadyPrescribed": "Already prescribed", "drugOrders": "Drug orders", @@ -31,6 +32,7 @@ "errorFetchingDrugResults": "Error fetching results for \"{{searchTerm}}\"", "errorFetchingOrderConfig": "Error occured when fetching Order config", "female": "Female", + "freeDosageErrorMessage": "Add free dosage note", "freeTextDosage": "Free text dosage", "goToDrugOrderForm": "Order form", "increment": "Increment", @@ -73,6 +75,9 @@ "searchFieldPlaceholder": "Search for a drug or orderset (e.g. \"Aspirin\")", "searchResultsMatchesForTerm_one": "{{count}} result for \"{{searchTerm}}\"", "searchResultsMatchesForTerm_other": "{{count}} results for \"{{searchTerm}}\"", + "selectFrequencyErrorMessage": "Please select a frequency", + "selectRouteErrorMessage": "Please select a route", + "selectUnitErrorMessage": "Please select a unit", "startDate": "Start date", "takeAsNeeded": "Take as needed", "tryReopeningTheForm": "Please try launching the form again",