Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 80 additions & 48 deletions src/components/form-editor/form-editor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const ErrorNotification = ({ error, title }: ErrorProps) => {
const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
const defaultEnterDelayInMs = 300;
const { formUuid } = useParams<{ formUuid: string }>();
const { blockRenderingWithErrors, dataTypeToRenderingMap } = useConfig<ConfigObject>();
const { blockRenderingWithErrors, dataTypeToRenderingMap, enableRDESection } = useConfig<ConfigObject>();
const isNewSchema = !formUuid;
const [schema, setSchema] = useState<Schema>();
const { form, formError, isLoadingForm } = useForm(formUuid);
Expand Down Expand Up @@ -156,7 +156,84 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ 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',
Expand All @@ -167,59 +244,14 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ 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();
Expand Down
7 changes: 7 additions & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -169,4 +175,5 @@ export interface ConfigObject {
dataTypeToRenderingMap: Record<string, Array<string>>;
enableFormValidation: boolean;
blockRenderingWithErrors: boolean;
enableRDESection: boolean;
}