-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathform-processor.ts
More file actions
41 lines (34 loc) · 1.58 KB
/
form-processor.ts
File metadata and controls
41 lines (34 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { type OpenmrsResource } from '@openmrs/esm-framework';
import { type FormContextProps } from '../provider/form-provider';
import { type ValueAndDisplay, type FormField, type FormSchema, type Appointment } from '../types';
import { type FormProcessorContextProps } from '../types';
export type FormProcessorConstructor = new (...args: ConstructorParameters<typeof FormProcessor>) => FormProcessor;
export type GetCustomHooksResponse = {
useCustomHooks: (context: Partial<FormProcessorContextProps>) => {
data: any;
isLoading: boolean;
error: any;
updateContext: (setContext: React.Dispatch<React.SetStateAction<FormProcessorContextProps>>) => void;
};
};
export abstract class FormProcessor {
formJson: FormSchema;
domainObjectValue: OpenmrsResource;
constructor(formJson: FormSchema) {
this.formJson = formJson;
}
getDomainObject() {
return this.domainObjectValue;
}
async loadDependencies(
context: Partial<FormProcessorContextProps>,
setContext: React.Dispatch<React.SetStateAction<FormProcessorContextProps>>,
): Promise<Record<string, any>> {
return Promise.resolve({});
}
abstract getHistoricalValue(field: FormField, context: FormContextProps): Promise<ValueAndDisplay>;
abstract processSubmission(context: FormContextProps, appointments: Array<Appointment>, abortController: AbortController): Promise<OpenmrsResource>;
abstract getInitialValues(context: FormProcessorContextProps): Promise<Record<string, any>>;
abstract getCustomHooks(): GetCustomHooksResponse;
abstract prepareFormSchema(schema: FormSchema): FormSchema;
}