Skip to content

Commit 1ed6588

Browse files
committed
O3-1144: Remove redundant type definitions, use types from form-engine-lib
- Import and re-export types (FormField, FormPage, FormSection, FormQuestionOptions, etc.) from @openmrs/esm-form-engine-lib instead of defining them locally - Create type aliases (Page, Section, Question, QuestionOptions) pointing to form-engine types for backward compatibility - Export additional useful types (QuestionAnswerOption, HideProps, DisableProps, RepeatOptions, etc.) from form-engine-lib - Update add-form-reference.modal.tsx to use FormPage, FormSection, FormField instead of local Page, Section, Question types - All tests passing, no breaking changes
1 parent 0b0aca3 commit 1ed6588

File tree

2 files changed

+61
-156
lines changed

2 files changed

+61
-156
lines changed

src/components/interactive-builder/modals/add-form-reference/add-form-reference.modal.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { showSnackbar } from '@openmrs/esm-framework';
2020
import { useForms } from '@hooks/useForms';
2121
import { useClobdata } from '@hooks/useClobdata';
22-
import { type Form as FormType, type Schema, type Page, type Section, type Question } from '@types';
22+
import { type Form as FormType, type Schema, type FormPage, type FormSection, type FormField } from '@types';
2323
import styles from './add-form-reference.scss';
2424

2525
interface AddFormReferenceModalProps {
@@ -41,9 +41,9 @@ const AddFormReferenceModal: React.FC<AddFormReferenceModalProps> = ({
4141
}) => {
4242
const { t } = useTranslation();
4343
const [selectedForm, setSelectedForm] = useState<FormType>(null);
44-
const [pages, setPages] = useState<Page[]>([]);
45-
const [selectedPage, setSelectedPage] = useState<Page>(null);
46-
const [selectedSection, setSelectedSection] = useState<Section>(null);
44+
const [pages, setPages] = useState<FormPage[]>([]);
45+
const [selectedPage, setSelectedPage] = useState<FormPage>(null);
46+
const [selectedSection, setSelectedSection] = useState<FormSection>(null);
4747
const [excludedQuestions, setExcludedQuestions] = useState<string[]>([]);
4848
const { forms, error, isLoading } = useForms();
4949
const { clobdata, isLoadingClobdata, clobdataError } = useClobdata(selectedForm);
@@ -61,18 +61,18 @@ const AddFormReferenceModal: React.FC<AddFormReferenceModalProps> = ({
6161
}
6262
}, [clobdata]);
6363

64-
const handleSelectedPage = useCallback(({ selectedItem }: { selectedItem: Page }) => {
64+
const handleSelectedPage = useCallback(({ selectedItem }: { selectedItem: FormPage }) => {
6565
setSelectedPage(selectedItem);
6666
setSelectedSection(null);
6767
setExcludedQuestions([]);
6868
}, []);
6969

70-
const handleSelectedSections = useCallback((section: Section) => {
70+
const handleSelectedSections = useCallback((section: FormSection) => {
7171
setSelectedSection(section);
7272
setExcludedQuestions([]);
7373
}, []);
7474

75-
const handleExcludedQuestions = useCallback((question: Question, checked: Boolean) => {
75+
const handleExcludedQuestions = useCallback((question: FormField, checked: Boolean) => {
7676
setExcludedQuestions((prev) => {
7777
if (!checked) {
7878
return prev.some((q) => q === question.id) ? prev : [...prev, question.id];
@@ -211,7 +211,7 @@ const AddFormReferenceModal: React.FC<AddFormReferenceModalProps> = ({
211211
label: page.label,
212212
sections: page.sections,
213213
}))}
214-
itemToString={(item: Page) => (item ? item.label : '')}
214+
itemToString={(item: FormPage) => (item ? item.label : '')}
215215
onChange={handleSelectedPage}
216216
selectedItem={selectedPage}
217217
/>

src/types.ts

Lines changed: 53 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ import type {
77
RenderType,
88
RequiredFieldProps,
99
FormReference,
10+
OpenmrsEncounter,
11+
OpenmrsObs,
12+
SessionMode,
13+
PostSubmissionAction,
14+
FormSchema,
15+
FormPage,
16+
FormSection,
17+
FormQuestionOptions,
18+
QuestionAnswerOption,
19+
HideProps,
20+
DisableProps,
21+
RepeatOptions,
1022
} from '@openmrs/esm-form-engine-lib';
1123
import type { AuditInfo } from './components/audit-details/audit-details.component';
1224
import type { questionTypes } from '@constants';
1325

26+
// Extend FormSchema to include description property
27+
export interface FormBuilderSchema extends FormSchema {
28+
description?: string;
29+
}
30+
1431
export interface Form {
1532
uuid: string;
1633
name: string;
@@ -50,116 +67,33 @@ export type QuestionType = (typeof questionTypes)[number];
5067

5168
export type DatePickerType = 'both' | 'calendar' | 'timer';
5269

53-
export interface Schema {
54-
name: string;
55-
pages: Array<{
56-
label: string;
57-
sections: Array<{
58-
label: string;
59-
isExpanded: string;
60-
reference?: FormReference;
61-
questions: Array<{
62-
id: string;
63-
label?: string;
64-
value?: string;
65-
type: string;
66-
required?: string | boolean | RequiredFieldProps;
67-
questionInfo?: string;
68-
questionOptions: {
69-
type?: string;
70-
concept?: string;
71-
answers?: Array<Record<string, string>>;
72-
rendering: RenderType;
73-
max?: string;
74-
min?: string;
75-
conceptMappings?: Array<Record<string, string>>;
76-
};
77-
questions?: Array<Question>;
78-
validators?: Array<Record<string, string>>;
79-
}>;
80-
}>;
81-
}>;
82-
processor: string;
83-
uuid: string;
84-
encounterType: string;
85-
referencedForms: Array<ReferencedForm>;
86-
version?: string;
87-
description?: string;
88-
encounter?: string | OpenmrsEncounter;
89-
allowUnspecifiedAll?: boolean;
90-
defaultPage?: string;
91-
readonly?: string | boolean;
92-
inlineRendering?: 'single-line' | 'multiline' | 'automatic';
93-
markdown?: unknown;
94-
postSubmissionActions?: Array<{ actionId: string; config?: Record<string, unknown> }>;
95-
formOptions?: {
96-
usePreviousValueDisabled: boolean;
97-
};
98-
translations?: Record<string, string>;
99-
}
70+
// Using extended FormBuilderSchema instead of FormSchema
71+
export type Schema = FormBuilderSchema;
10072

10173
export interface SchemaContextType {
10274
schema: Schema;
10375
setSchema: (schema: Schema) => void;
10476
}
10577

106-
export interface Page {
107-
label: string;
108-
sections: Array<Section>;
109-
}
78+
// Using FormPage from form-engine-lib instead of local Page
79+
export type Page = FormPage;
80+
// Export FormPage as well for direct imports
81+
export { FormPage };
11082

111-
export interface Section {
112-
label: string;
113-
questions: Array<Question>;
114-
isExpanded: string | boolean;
115-
}
83+
// Using FormSection from form-engine-lib instead of local Section
84+
export type Section = FormSection;
85+
// Export FormSection as well for direct imports
86+
export { FormSection };
11687

117-
export interface Question {
118-
id: string;
119-
label?: string;
120-
value?: any;
121-
type: string;
122-
questionOptions: QuestionOptions;
123-
datePickerFormat?: DatePickerType;
124-
questions?: Array<Question>;
125-
required?: string | boolean | RequiredFieldProps;
126-
validators?: Array<Record<string, string>>;
127-
questionInfo?: string;
128-
}
88+
// Using FormField from form-engine-lib instead of local Question
89+
export type Question = FormField;
90+
// Export FormField as well for direct imports
91+
export { FormField };
12992

130-
export interface QuestionOptions {
131-
rendering: RenderType;
132-
answers?: Array<Record<string, string>>;
133-
concept?: string;
134-
conceptMappings?: Array<ConceptMapping>;
135-
max?: string;
136-
min?: string;
137-
isSearchable?: boolean;
138-
attributeType?: string;
139-
calculate?: {
140-
calculateExpression: string;
141-
};
142-
rows?: number;
143-
orderSettingUuid?: string;
144-
orderType?: string;
145-
identifierType?: string;
146-
selectableOrders?: Array<
147-
| {
148-
concept: string;
149-
label: string;
150-
}
151-
| Record<string, any>
152-
>;
153-
weekList?: [];
154-
showComment?: boolean;
155-
showDate?: string;
156-
programUuid?: string;
157-
workflowUuid?: string;
158-
toggleOptions?: {
159-
labelTrue: string;
160-
labelFalse: string;
161-
};
162-
}
93+
// Using FormQuestionOptions from form-engine-lib instead of local QuestionOptions
94+
export type QuestionOptions = FormQuestionOptions;
95+
// Export FormQuestionOptions as well for direct imports
96+
export { FormQuestionOptions };
16397

16498
export interface Answer {
16599
concept: string;
@@ -208,53 +142,24 @@ export interface PersonAttributeType {
208142
};
209143
}
210144

211-
export interface OpenmrsEncounter {
212-
uuid?: string;
213-
encounterDatetime?: string | Date;
214-
patient?: OpenmrsResource | string;
215-
location?: OpenmrsResource | string;
216-
encounterType?: OpenmrsResource | string;
217-
obs?: Array<OpenmrsObs>;
218-
orders?: Array<OpenmrsResource>;
219-
voided?: boolean;
220-
visit?: OpenmrsResource | string;
221-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
222-
encounterProviders?: Array<Record<string, any>>;
223-
form?: OpenmrsFormResource;
224-
}
225-
226-
export type SessionMode = 'edit' | 'enter' | 'view' | 'embedded-view';
227-
228-
export interface PostSubmissionAction {
229-
applyAction(
230-
formSession: {
231-
patient: fhir.Patient;
232-
encounters: Array<OpenmrsEncounter>;
233-
sessionMode: SessionMode;
234-
},
235-
config?: Record<string, unknown>,
236-
enabled?: string,
237-
): void;
238-
}
239-
240-
export interface OpenmrsObs extends OpenmrsResource {
241-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
242-
concept?: any;
243-
obsDatetime?: string | Date;
244-
obsGroup?: OpenmrsObs;
245-
groupMembers?: Array<OpenmrsObs>;
246-
comment?: string;
247-
location?: OpenmrsResource;
248-
order?: OpenmrsResource;
249-
encounter?: OpenmrsResource;
250-
voided?: boolean;
251-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
252-
value?: any;
253-
formFieldPath?: string;
254-
formFieldNamespace?: string;
255-
status?: string;
256-
interpretation?: string;
257-
}
145+
// Export the imported types directly
146+
export type {
147+
OpenmrsEncounter,
148+
OpenmrsObs,
149+
SessionMode,
150+
PostSubmissionAction,
151+
FormSchema,
152+
QuestionAnswerOption,
153+
HideProps,
154+
DisableProps,
155+
RepeatOptions,
156+
OpenmrsFormResource,
157+
RenderType,
158+
RequiredFieldProps,
159+
FormReference,
160+
ReferencedForm,
161+
ProgramState,
162+
};
258163

259164
export interface Program {
260165
uuid: string;

0 commit comments

Comments
 (0)