diff --git a/src/components/form-editor/form-editor.component.tsx b/src/components/form-editor/form-editor.component.tsx index ce592892..31024b92 100644 --- a/src/components/form-editor/form-editor.component.tsx +++ b/src/components/form-editor/form-editor.component.tsx @@ -70,7 +70,7 @@ const ErrorNotification = ({ error, title }: ErrorProps) => { const FormEditorContent: React.FC = ({ t }) => { const defaultEnterDelayInMs = 300; const { formUuid } = useParams<{ formUuid: string }>(); - const { blockRenderingWithErrors, dataTypeToRenderingMap } = useConfig(); + const { blockRenderingWithErrors, dataTypeToRenderingMap, enableRDESection } = useConfig(); const isNewSchema = !formUuid; const [schema, setSchema] = useState(); const { form, formError, isLoadingForm } = useForm(formUuid); @@ -156,7 +156,84 @@ const FormEditorContent: React.FC = ({ t }) => { } }; + const buildRdeSection = () => ({ + label: 'Encounter Details', + isExpanded: 'false', + questions: [ + { + id: 'encounterDateTime', + label: 'Encounter Date & Time', + type: 'encounterDateTime', + questionOptions: { + rendering: 'date', + }, + }, + { + id: 'encounterProvider', + label: 'Encounter Provider', + type: 'encounterProvider', + questionOptions: { + rendering: 'ui-select-extended', + }, + }, + ], + }); + const inputDummySchema = useCallback(() => { + const sections = []; + + // Conditionally insert RDE section + if (enableRDESection) { + sections.push(buildRdeSection()); + } + + sections.push( + { + label: 'A Section', + isExpanded: 'true', + questions: [ + { + id: 'sampleQuestion', + label: 'A Question of type obs that renders a text input', + type: 'obs', + questionOptions: { + rendering: 'text', + concept: 'a-system-defined-concept-uuid', + }, + }, + ], + }, + { + label: 'Another Section', + isExpanded: 'true', + questions: [ + { + id: 'anotherSampleQuestion', + label: 'Another Question of type obs whose answers get rendered as radio inputs', + type: 'obs', + questionOptions: { + rendering: 'radio', + concept: 'system-defined-concept-uuid', + answers: [ + { + concept: 'another-system-defined-concept-uuid', + label: 'Choice 1', + }, + { + concept: 'yet-another-system-defined-concept-uuid', + label: 'Choice 2', + }, + { + concept: 'yet-one-more-system-defined-concept-uuid', + label: 'Choice 3', + }, + ], + }, + }, + ], + }, + ); + const dummySchema: FormSchema = { encounterType: '', name: 'Sample Form', @@ -167,59 +244,14 @@ const FormEditorContent: React.FC = ({ t }) => { pages: [ { label: 'First Page', - sections: [ - { - label: 'A Section', - isExpanded: 'true', - questions: [ - { - id: 'sampleQuestion', - label: 'A Question of type obs that renders a text input', - type: 'obs', - questionOptions: { - rendering: 'text', - concept: 'a-system-defined-concept-uuid', - }, - }, - ], - }, - { - label: 'Another Section', - isExpanded: 'true', - questions: [ - { - id: 'anotherSampleQuestion', - label: 'Another Question of type obs whose answers get rendered as radio inputs', - type: 'obs', - questionOptions: { - rendering: 'radio', - concept: 'system-defined-concept-uuid', - answers: [ - { - concept: 'another-system-defined-concept-uuid', - label: 'Choice 1', - }, - { - concept: 'yet-another-system-defined-concept-uuid', - label: 'Choice 2', - }, - { - concept: 'yet-one-more-system-defined-concept-uuid', - label: 'Choice 3', - }, - ], - }, - }, - ], - }, - ], + sections: sections, }, ], }; setStringifiedSchema(JSON.stringify(dummySchema, null, 2)); updateSchema({ ...dummySchema }); - }, [updateSchema]); + }, [updateSchema, enableRDESection]); const renderSchemaChanges = useCallback(() => { resetErrorMessage(); diff --git a/src/config-schema.ts b/src/config-schema.ts index c0f64e55..5b81b8f1 100644 --- a/src/config-schema.ts +++ b/src/config-schema.ts @@ -160,6 +160,12 @@ export const configSchema = { _description: 'Whether to block form rendering when there are validation errors', _default: false, }, + enableRDESection: { + _type: Type.Boolean, + _default: false, + _description: + 'Whether to add an Encounter Details section for retrospective data entry, which includes encounter date/time and provider fields', + }, }; export interface ConfigObject { @@ -169,4 +175,5 @@ export interface ConfigObject { dataTypeToRenderingMap: Record>; enableFormValidation: boolean; blockRenderingWithErrors: boolean; + enableRDESection: boolean; }