From c7ea88ac814288892666e963e36de9a04048be8a Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 26 Jul 2023 14:21:54 -0400 Subject: [PATCH] Stricter types --- .../src/offline.resources.ts | 8 +-- .../src/offline.ts | 2 +- .../field/__mocks__/field.resource.ts | 2 +- .../address/address-hierarchy.resource.tsx | 31 +++------- .../field/address/tests/mocks.ts | 2 +- .../field/field.resource.ts | 2 +- .../field/id/id-field.component.tsx | 2 +- .../field/id/identifier-selection-overlay.tsx | 2 +- .../field/obs/obs-field.component.tsx | 2 +- .../coded-attributes.component.tsx | 2 +- ...coded-person-attribute-field.component.tsx | 2 +- .../person-attributes.resource.tsx | 2 +- .../text-person-attribute-field.component.tsx | 2 +- .../patient-registration/form-manager.test.ts | 2 +- .../src/patient-registration/form-manager.ts | 2 +- .../identifier/identifier-input.component.tsx | 2 +- .../input/custom-input/identifier/utils.ts | 2 +- .../dummy-data/dummy-data-input.component.tsx | 2 +- .../patient-registration-context.ts | 2 +- .../patient-registration-hooks.ts | 2 +- .../patient-registration-utils.ts | 2 +- .../patient-registration.component.tsx | 2 +- .../patient-registration.resource.tsx | 2 +- ...pes.tsx => patient-registration.types.tsx} | 60 +++++++++++-------- .../relationships-section.component.tsx | 2 +- .../relationships.resource.tsx | 2 +- .../patient-registration-validation.tsx | 2 +- .../src/root.component.tsx | 8 +-- 28 files changed, 73 insertions(+), 82 deletions(-) rename packages/esm-patient-registration-app/src/patient-registration/{patient-registration-types.tsx => patient-registration.types.tsx} (87%) diff --git a/packages/esm-patient-registration-app/src/offline.resources.ts b/packages/esm-patient-registration-app/src/offline.resources.ts index b8797bcef..c3d20844c 100644 --- a/packages/esm-patient-registration-app/src/offline.resources.ts +++ b/packages/esm-patient-registration-app/src/offline.resources.ts @@ -2,12 +2,12 @@ import React from 'react'; import find from 'lodash-es/find'; import camelCase from 'lodash-es/camelCase'; import escapeRegExp from 'lodash-es/escapeRegExp'; -import { FetchResponse, messageOmrsServiceWorker, openmrsFetch, Session } from '@openmrs/esm-framework'; -import { +import { messageOmrsServiceWorker, openmrsFetch, Session } from '@openmrs/esm-framework'; +import type { PatientIdentifierType, FetchedPatientIdentifierType, AddressTemplate, -} from './patient-registration/patient-registration-types'; +} from './patient-registration/patient-registration.types'; import { cacheForOfflineHeaders } from './constants'; export interface Resources { @@ -25,7 +25,7 @@ export async function fetchCurrentSession(): Promise { } export async function fetchAddressTemplate() { - const { data } = await cacheAndFetch('/ws/rest/v1/addresstemplate'); + const { data } = await cacheAndFetch('/ws/rest/v1/addresstemplate'); return data; } diff --git a/packages/esm-patient-registration-app/src/offline.ts b/packages/esm-patient-registration-app/src/offline.ts index 5cc38a81d..1c2ee15de 100644 --- a/packages/esm-patient-registration-app/src/offline.ts +++ b/packages/esm-patient-registration-app/src/offline.ts @@ -15,7 +15,7 @@ import { fetchPatientIdentifierTypesWithSources, } from './offline.resources'; import { FormManager } from './patient-registration/form-manager'; -import { PatientRegistration } from './patient-registration/patient-registration-types'; +import { PatientRegistration } from './patient-registration/patient-registration.types'; export function setupOffline() { setupOfflineSync(patientRegistration, [], syncPatientRegistration, { diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/__mocks__/field.resource.ts b/packages/esm-patient-registration-app/src/patient-registration/field/__mocks__/field.resource.ts index c4f12827f..7db7f105d 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/__mocks__/field.resource.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/field/__mocks__/field.resource.ts @@ -1,4 +1,4 @@ -import { ConceptResponse } from '../../patient-registration-types'; +import { ConceptResponse } from '../../patient-registration.types'; export const useConcept = jest.fn(function mockUseConceptImplementation(uuid: string): { data: ConceptResponse; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy.resource.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy.resource.tsx index 0f8b28617..aae3c3486 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy.resource.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy.resource.tsx @@ -1,4 +1,4 @@ -import { FetchResponse, openmrsFetch } from '@openmrs/esm-framework'; +import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework'; import { useField } from 'formik'; import { useCallback, useContext, useEffect, useMemo } from 'react'; import useSWRImmutable from 'swr/immutable'; @@ -10,7 +10,7 @@ interface AddressFields { export function useOrderedAddressHierarchyLevels() { const url = '/module/addresshierarchy/ajax/getOrderedAddressHierarchyLevels.form'; - const { data, isLoading, error } = useSWRImmutable>>(url, openmrsFetch); + const { data, isLoading, error } = useSWRImmutable>, Error>(url, openmrsFetch); const results = useMemo( () => ({ @@ -56,7 +56,7 @@ export function useAddressEntries(fetchResults, searchString) { * This also returns the function to reset the lower ordered fields if the value of a field is changed. */ export function useAddressEntryFetchConfig(addressField: string) { - const { orderedFields, isLoadingFieldOrder, errorFetchingFieldOrder } = useOrderedAddressHierarchyLevels(); + const { orderedFields, isLoadingFieldOrder } = useOrderedAddressHierarchyLevels(); const { setFieldValue } = useContext(PatientRegistrationContext); const [, { value: addressValues }] = useField('address'); @@ -102,14 +102,7 @@ export function useAddressEntryFetchConfig(addressField: string) { return results; } -export function useAddressHierarchy( - searchString, - separator, -): { - addresses: Array; - isLoading: boolean; - error: Error; -} { +export function useAddressHierarchy(searchString: string, separator: string) { const { data, error, isLoading } = useSWRImmutable< FetchResponse< Array<{ @@ -135,25 +128,15 @@ export function useAddressHierarchy( return results; } -export function useAdressHierarchyWithParentSearch( - addressField, - parentid, - query, -): { - error: Error; - isLoading: boolean; - addresses: Array<{ - uuid: string; - name: string; - }>; -} { +export function useAddressHierarchyWithParentSearch(addressField: string, parentid: string, query: string) { const { data, error, isLoading } = useSWRImmutable< FetchResponse< Array<{ uuid: string; name: string; }> - > + >, + Error >( query ? `/module/addresshierarchy/ajax/getPossibleAddressHierarchyEntriesWithParents.form?addressField=${addressField}&limit=20&searchString=${query}&parentUuid=${parentid}` diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts index d554f96b6..da9611698 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts @@ -1,4 +1,4 @@ -import { AddressTemplate } from '../../../patient-registration-types'; +import { AddressTemplate } from '../../../patient-registration.types'; export const mockedAddressTemplate: AddressTemplate = { displayName: null, diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/field.resource.ts b/packages/esm-patient-registration-app/src/patient-registration/field/field.resource.ts index 3dcbb8410..c2bf6c691 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/field.resource.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/field/field.resource.ts @@ -1,6 +1,6 @@ import { FetchResponse, openmrsFetch, showToast } from '@openmrs/esm-framework'; import useSWRImmutable from 'swr/immutable'; -import { ConceptAnswers, ConceptResponse } from '../patient-registration-types'; +import { ConceptAnswers, ConceptResponse } from '../patient-registration.types'; export function useConcept(conceptUuid: string): { data: ConceptResponse; isLoading: boolean } { const shouldFetch = typeof conceptUuid === 'string' && conceptUuid !== ''; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/id/id-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/id/id-field.component.tsx index 3c78118e3..46d396172 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/id/id-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/id/id-field.component.tsx @@ -11,7 +11,7 @@ import { IdentifierSource, PatientIdentifierType, PatientIdentifierValue, -} from '../../patient-registration-types'; +} from '../../patient-registration.types'; import { ResourcesContext } from '../../../offline.resources'; import styles from '../field.scss'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/id/identifier-selection-overlay.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/id/identifier-selection-overlay.tsx index 059375554..cd7772b53 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/id/identifier-selection-overlay.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/id/identifier-selection-overlay.tsx @@ -2,7 +2,7 @@ import React, { useMemo, useCallback, useEffect, useState, useContext } from 're import { useTranslation } from 'react-i18next'; import { Button, ButtonSet, Checkbox, Search, RadioButtonGroup, RadioButton } from '@carbon/react'; import { isDesktop, useConfig, useLayoutType } from '@openmrs/esm-framework'; -import { FormValues, PatientIdentifierType, PatientIdentifierValue } from '../../patient-registration-types'; +import { FormValues, PatientIdentifierType, PatientIdentifierValue } from '../../patient-registration.types'; import Overlay from '../../ui-components/overlay'; import { ResourcesContext } from '../../../offline.resources'; import { PatientRegistrationContext } from '../../patient-registration-context'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/obs/obs-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/obs/obs-field.component.tsx index 0e49e6245..652ccc94e 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/obs/obs-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/obs/obs-field.component.tsx @@ -3,7 +3,7 @@ import { Field } from 'formik'; import { useTranslation } from 'react-i18next'; import { InlineNotification, Layer, Select, SelectItem } from '@carbon/react'; import { useConfig } from '@openmrs/esm-framework'; -import { ConceptResponse } from '../../patient-registration-types'; +import { ConceptResponse } from '../../patient-registration.types'; import { FieldDefinition, RegistrationConfig } from '../../../config-schema'; import { Input } from '../../input/basic-input/input/input.component'; import { useConcept, useConceptAnswers } from '../field.resource'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-attributes.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-attributes.component.tsx index ec2ae22c1..41ae2c425 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-attributes.component.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Layer, Select, SelectItem } from '@carbon/react'; import { useConfig } from '@openmrs/esm-framework'; import { Input } from '../../input/basic-input/input/input.component'; -import { CodedPersonAttributeConfig } from '../../patient-registration-types'; +import { CodedPersonAttributeConfig } from '../../patient-registration.types'; import { useConceptAnswers } from '../field.resource'; import { usePersonAttributeType } from './person-attributes.resource'; import styles from './../field.scss'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx index 7380782a2..a1e1b26fe 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Layer, Select, SelectItem } from '@carbon/react'; import { Input } from '../../input/basic-input/input/input.component'; -import { PersonAttributeTypeResponse } from '../../patient-registration-types'; +import { PersonAttributeTypeResponse } from '../../patient-registration.types'; import { useConceptAnswers } from '../field.resource'; import styles from './../field.scss'; import { useTranslation } from 'react-i18next'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/person-attributes.resource.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/person-attributes.resource.tsx index fa38e283c..6f5136512 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/person-attributes.resource.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/person-attributes.resource.tsx @@ -1,6 +1,6 @@ import { FetchResponse, openmrsFetch, showToast } from '@openmrs/esm-framework'; import useSWRImmutable from 'swr/immutable'; -import { PersonAttributeTypeResponse } from '../../patient-registration-types'; +import { PersonAttributeTypeResponse } from '../../patient-registration.types'; export function usePersonAttributeType(personAttributeTypeUuid: string): { data: PersonAttributeTypeResponse; diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx index a7780e8e2..0d1e1569f 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/person-attributes/text-person-attribute-field.component.tsx @@ -3,7 +3,7 @@ import styles from './../field.scss'; import { Input } from '../../input/basic-input/input/input.component'; import { Field } from 'formik'; import { useTranslation } from 'react-i18next'; -import { PersonAttributeTypeResponse } from '../../patient-registration-types'; +import { PersonAttributeTypeResponse } from '../../patient-registration.types'; export interface TextPersonAttributeFieldProps { id: string; diff --git a/packages/esm-patient-registration-app/src/patient-registration/form-manager.test.ts b/packages/esm-patient-registration-app/src/patient-registration/form-manager.test.ts index 51957e7f2..ffedd3ce1 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/form-manager.test.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/form-manager.test.ts @@ -1,5 +1,5 @@ import { FormManager } from './form-manager'; -import { FormValues } from './patient-registration-types'; +import { FormValues } from './patient-registration.types'; jest.mock('./patient-registration.resource'); diff --git a/packages/esm-patient-registration-app/src/patient-registration/form-manager.ts b/packages/esm-patient-registration-app/src/patient-registration/form-manager.ts index e094d1bba..82b6f258f 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/form-manager.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/form-manager.ts @@ -10,7 +10,7 @@ import { PatientRegistration, RelationshipValue, Encounter, -} from './patient-registration-types'; +} from './patient-registration.types'; import { addPatientIdentifier, deletePatientIdentifier, diff --git a/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx index 8e91e9192..28a8c585b 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx @@ -7,7 +7,7 @@ import { ResourcesContext } from '../../../../offline.resources'; import { showModal, useConfig, UserHasAccess } from '@openmrs/esm-framework'; import { shouldBlockPatientIdentifierInOfflineMode } from './utils'; import { deleteIdentifierType, setIdentifierSource } from '../../../field/id/id-field.component'; -import { PatientIdentifierValue } from '../../../patient-registration-types'; +import { PatientIdentifierValue } from '../../../patient-registration.types'; import { PatientRegistrationContext } from '../../../patient-registration-context'; import { Input } from '../../basic-input/input/input.component'; import styles from '../../input.scss'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.ts b/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.ts index 1a52ac504..0cb736841 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/input/custom-input/identifier/utils.ts @@ -1,4 +1,4 @@ -import { FetchedPatientIdentifierType, PatientIdentifierType } from '../../../patient-registration-types'; +import { FetchedPatientIdentifierType, PatientIdentifierType } from '../../../patient-registration.types'; export function shouldBlockPatientIdentifierInOfflineMode(identifierType: PatientIdentifierType) { // Patient Identifiers which are unique and can be manually entered are prohibited while offline because diff --git a/packages/esm-patient-registration-app/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx index a0bccefe8..b232ebfb5 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/input/dummy-data/dummy-data-input.component.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { v4 } from 'uuid'; -import { FormValues } from '../../patient-registration-types'; +import { FormValues } from '../../patient-registration.types'; import styles from './../input.scss'; interface DummyDataInputProps { diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-context.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-context.ts index 53b13656c..eb259af3c 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-context.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-context.ts @@ -1,7 +1,7 @@ import { useConfig } from '@openmrs/esm-framework'; import { createContext, SetStateAction } from 'react'; import { RegistrationConfig } from '../config-schema'; -import { FormValues, CapturePhotoProps } from './patient-registration-types'; +import { FormValues, CapturePhotoProps } from './patient-registration.types'; export interface PatientRegistrationContextProps { identifierTypes: Array; diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts index db7ab45fc..90cd720f3 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-hooks.ts @@ -12,7 +12,7 @@ import { PersonAttributeResponse, PatientIdentifierResponse, Encounter, -} from './patient-registration-types'; +} from './patient-registration.types'; import { getAddressFieldValuesFromFhirPatient, getFormValuesFromFhirPatient, diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts index 4624bc91b..bed641732 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration-utils.ts @@ -6,7 +6,7 @@ import { PatientUuidMapType, PatientIdentifierValue, Encounter, -} from './patient-registration-types'; +} from './patient-registration.types'; import { parseDate } from '@openmrs/esm-framework'; import camelCase from 'lodash-es/camelCase'; import capitalize from 'lodash-es/capitalize'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx index 1c9f760e7..ee5ba9938 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.component.tsx @@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next'; import { Formik, Form, FormikHelpers } from 'formik'; import { createErrorHandler, showToast, useConfig, interpolateUrl, usePatient } from '@openmrs/esm-framework'; import { validationSchema as initialSchema } from './validation/patient-registration-validation'; -import { FormValues, CapturePhotoProps, PatientIdentifierValue } from './patient-registration-types'; +import { FormValues, CapturePhotoProps, PatientIdentifierValue } from './patient-registration.types'; import { PatientRegistrationContext } from './patient-registration-context'; import { SavePatientForm, SavePatientTransactionManager } from './form-manager'; import { usePatientPhoto } from './patient-registration.resource'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.resource.tsx b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.resource.tsx index 324acc384..83959b532 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.resource.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.resource.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import useSWR from 'swr'; import useSWRImmutable from 'swr/immutable'; import { FetchResponse, openmrsFetch, useConfig } from '@openmrs/esm-framework'; -import { Patient, Relationship, PatientIdentifier, Encounter } from './patient-registration-types'; +import { Patient, Relationship, PatientIdentifier, Encounter } from './patient-registration.types'; export const uuidIdentifier = '05a29f94-c0ed-11e2-94be-8c13b969e334'; export const uuidTelephoneNumber = '14d4f066-15f5-102d-96e4-000c29c2a5d7'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-types.tsx b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.types.tsx similarity index 87% rename from packages/esm-patient-registration-app/src/patient-registration/patient-registration-types.tsx rename to packages/esm-patient-registration-app/src/patient-registration/patient-registration.types.tsx index 1ccf24c79..4028a7480 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration-types.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.types.tsx @@ -263,35 +263,47 @@ export interface ConceptAnswers { uuid: string; } +export type AddressProperties = + | 'cityVillage' + | 'stateProvince' + | 'countyDistrict' + | 'postalCode' + | 'country' + | 'address1' + | 'address2' + | 'address3' + | 'address4' + | 'address5' + | 'address6' + | 'address7' + | 'address8' + | 'address9' + | 'address10' + | 'address11' + | 'address12' + | 'address13' + | 'address14' + | 'address15'; + +export type ExtensibleAddressProperties = { [p in AddressProperties]?: string } | null; + export interface AddressTemplate { - displayName: null; - codeName: string; - country: string; + displayName: string | null; + codeName: string | null; + country: string | null; lines: Array< Array<{ isToken: 'IS_NOT_ADDR_TOKEN' | 'IS_ADDR_TOKEN'; displayText: string; - codeName?: string; + codeName?: AddressProperties; displaySize?: string; }> - >; - lineByLineFormat: Array; - nameMappings: { - [x: string]: string; - }; - sizeMappings: { - [x: string]: string; - }; - elementDefaults: { - [x: string]: string; - }; - elementRegex: { - [x: string]: string; - }; - elementRegexFormats: { - [x: string]: string; - }; - requiredElements: { - [x: string]: string; - }; + > | null; + lineByLineFormat: Array | null; + nameMappings: ExtensibleAddressProperties; + sizeMappings: ExtensibleAddressProperties; + elementDefaults: ExtensibleAddressProperties; + elementRegex: ExtensibleAddressProperties; + elementRegexFormats: ExtensibleAddressProperties; + requiredElements: Array | null; } diff --git a/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships-section.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships-section.component.tsx index 3634218a1..080d76a3a 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships-section.component.tsx @@ -15,7 +15,7 @@ import { Autosuggest } from '../../input/custom-input/autosuggest/autosuggest.co import { PatientRegistrationContext } from '../../patient-registration-context'; import { ResourcesContext } from '../../../offline.resources'; import { fetchPerson } from '../../patient-registration.resource'; -import { RelationshipValue } from '../../patient-registration-types'; +import { RelationshipValue } from '../../patient-registration.types'; import sectionStyles from '../section.scss'; import styles from './relationships.scss'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx b/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx index a3730cb9a..9a8912493 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/section/patient-relationships/relationships.resource.tsx @@ -1,5 +1,5 @@ import { FetchResponse, openmrsFetch, showToast } from '@openmrs/esm-framework'; -import { RelationshipValue } from '../../patient-registration-types'; +import { RelationshipValue } from '../../patient-registration.types'; import useSWR from 'swr'; import { useMemo } from 'react'; import { personRelationshipRepresentation } from '../../../constants'; diff --git a/packages/esm-patient-registration-app/src/patient-registration/validation/patient-registration-validation.tsx b/packages/esm-patient-registration-app/src/patient-registration/validation/patient-registration-validation.tsx index d340e043f..c942bc8f9 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/validation/patient-registration-validation.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/validation/patient-registration-validation.tsx @@ -1,6 +1,6 @@ import * as Yup from 'yup'; import mapValues from 'lodash/mapValues'; -import { FormValues } from '../patient-registration-types'; +import { FormValues } from '../patient-registration.types'; export const validationSchema = Yup.object({ givenName: Yup.string().required('givenNameRequired'), diff --git a/packages/esm-patient-registration-app/src/root.component.tsx b/packages/esm-patient-registration-app/src/root.component.tsx index 4c7db0aa9..4e6c620fc 100644 --- a/packages/esm-patient-registration-app/src/root.component.tsx +++ b/packages/esm-patient-registration-app/src/root.component.tsx @@ -1,7 +1,7 @@ import React, { useMemo } from 'react'; import { BrowserRouter, Route, Routes } from 'react-router-dom'; import { Grid, Row } from '@carbon/react'; -import { ExtensionSlot, FetchResponse, useConnectivity, useSession } from '@openmrs/esm-framework'; +import { ExtensionSlot, useConnectivity, useSession } from '@openmrs/esm-framework'; import { ResourcesContext, fetchAddressTemplate, @@ -12,15 +12,11 @@ import { FormManager } from './patient-registration/form-manager'; import { PatientRegistration } from './patient-registration/patient-registration.component'; import useSWRImmutable from 'swr/immutable'; import styles from './root.scss'; -import { AddressTemplate } from './patient-registration/patient-registration-types'; export default function Root() { const isOnline = useConnectivity(); const currentSession = useSession(); - const { data: addressTemplate } = useSWRImmutable( - 'patientRegistrationAddressTemplate', - fetchAddressTemplate, - ); + const { data: addressTemplate } = useSWRImmutable('patientRegistrationAddressTemplate', fetchAddressTemplate); const { data: relationshipTypes } = useSWRImmutable( 'patientRegistrationRelationshipTypes', fetchAllRelationshipTypes,