Skip to content

Commit

Permalink
(feat) O3-2779: Error messages in drug order form should be translated (
Browse files Browse the repository at this point in the history
#1652)

* O3-2779: Error messages in drug order form should be translated

* Updated translation

Co-authored-by: Dennis Kigen <[email protected]>

* Revert "Updated translation"

This reverts commit d11523e.

---------

Co-authored-by: Dennis Kigen <[email protected]>
  • Loading branch information
vasharma05 and denniskigen authored Feb 13, 2024
1 parent 9cfea2f commit 4563c5f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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(),
Expand All @@ -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', [
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-medications-app/src/dashboard.meta.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const moduleName = '@openmrs/esm-patient-medications-app';
export const dashboardMeta = {
slot: 'patient-chart-medications-dashboard-slot',
columns: 1,
Expand Down
4 changes: 1 addition & 3 deletions packages/esm-patient-medications-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 5 additions & 0 deletions packages/esm-patient-medications-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 4563c5f

Please sign in to comment.