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 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 @@ -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,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 @@ -153,59 +230,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 @@ -90,6 +90,12 @@ export const configSchema = {
_default: false,
_description: 'Whether to enable form validation',
},
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 @@ -99,4 +105,5 @@ export interface ConfigObject {
dataTypeToRenderingMap: Record<string, Array<string>>;
enableFormValidation: boolean;
blockRenderingWithErrors: boolean;
enableRDESection: boolean;
}