Skip to content

(feat) O3-4750 : Provide support on the form builder to be able to auto create a standard section containing encounterDateTime and encounterProvider to support RDE. #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
130 changes: 82 additions & 48 deletions src/components/form-editor/form-editor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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 @@ -142,7 +142,86 @@ 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',
concept: 'a-system-defined-concept-uuid',
},
},
{
id: 'encounterProvider',
label: 'Encounter Provider',
type: 'encounterProvider',
questionOptions: {
rendering: 'ui-select-extended',
concept: 'a-system-defined-concept-uuid',
},
},
],
});

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 @@ -153,59 +232,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
6 changes: 6 additions & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const configSchema = {
_default: false,
_description: 'Whether to enable form validation',
},
enableRDESection: {
_type: Type.Boolean,
_default: false,
_description: 'Whether to enable the RDE section in the form builder',
Copy link
Member

@denniskigen denniskigen May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_description: 'Whether to enable the RDE section in the form builder',
_description: 'Whether to add an Encounter Details section for retrospective data entry, which includes encounter date/time and provider fields',

I think there's room for improving this config property description.

Copy link
Collaborator

@NethmiRodrigo NethmiRodrigo May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a config for this? Since its just a section to be added into the form, and that too, as it is, gets added to the dummy form which is only if you press the Input dummy schema button. It doesn't seem like something that a user should need to "configure" to have in a form.
Can't we instead have a checkbox somewhere here that would add the section to the form?
Screenshot 2025-05-29 at 7 37 00 PM
Plus, this way, users could have it anytime and not accessible only under the input dummy schema button.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NethmiRodrigo i could explore this approach.

},
};

export interface ConfigObject {
Expand All @@ -99,4 +104,5 @@ export interface ConfigObject {
dataTypeToRenderingMap: Record<string, Array<string>>;
enableFormValidation: boolean;
blockRenderingWithErrors: boolean;
enableRDESection: boolean;
}