Skip to content

Commit

Permalink
(fix) Should not render empty obs-groups (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmale authored Dec 11, 2024
1 parent fac66fd commit 4e34674
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 129 deletions.
312 changes: 188 additions & 124 deletions __mocks__/forms/rfe-forms/obs-group-test_form.json
Original file line number Diff line number Diff line change
@@ -1,137 +1,201 @@
{
"name": "ObsGroup Test Form",
"version": "1",
"published": true,
"retired": false,
"pages": [
{
"label": "Introduction",
"sections": [
{
"label": "",
"isExpanded": "true",
"questions": [
{
"type": "markdown",
"questionOptions": {
"rendering": "markdown"
},
"id": "fooMarkdown",
"value": [
"**Use this form to:** Test Obs Group behaviour"
]
}
]
}
]
},
{
"label": "Obs Group Page",
"sections": [
{
"label": "Group Section",
"isExpanded": "true",
"questions": [
{
"id": "myGroup",
"label": "My Group",
"type": "obsGroup",
"questionOptions": {
"rendering": "repeating",
"concept": "1c70c490-cafa-4c95-9fdd-a30b62bb78b8"
"name": "ObsGroup Test Form",
"version": "1",
"published": true,
"retired": false,
"pages": [
{
"label": "Obs Group Page",
"sections": [
{
"label": "Group Section",
"isExpanded": "true",
"questions": [
{
"id": "myGroup",
"label": "My Group",
"type": "obsGroup",
"questionOptions": {
"rendering": "repeating",
"concept": "1c70c490-cafa-4c95-9fdd-a30b62bb78b8"
},
"behaviours": [
{
"intent": "*",
"required": "false",
"unspecified": "false",
"hide": {
"hideWhenExpression": ""
},
"validators": []
}
],
"questions": [
{
"label": "Sex",
"type": "obs",
"required": "true",
"questionOptions": {
"rendering": "radio",
"concept": "1587AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"answers": [
{
"concept": "1535AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Female"
},
{
"concept": "1534AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Male"
}
]
},
"id": "childSex",
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": []
}
]
},
"behaviours":[
{
"intent":"*",
"required":"false",
"unspecified":"false",
"hide":{
"hideWhenExpression":""
},
"validators":[]
}
],
"questions": [
{
"label": "Sex",
"type":"obs",
"required":"true",
"questionOptions":{
"rendering":"radio",
"concept":"1587AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"answers":[
{
"label": "Date of Birth",
"type": "obs",
"questionOptions": {
"rendering": "date",
"concept": "164802AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"weeksList": ""
},
"id": "birthDate",
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"concept":"1535AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label":"Female"
"type": "date",
"allowFutureDates": "false"
},
{
"concept":"1534AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label":"Male"
"type": "js_expression",
"failsWhenExpression": "!isDateEqualTo(myValue, useFieldValue('visit_date'))",
"message": "Child birth date should be the same as the visit date!"
}
]
},
"id":"childSex",
"behaviours":[
{
"intent":"*",
"required":"true",
"unspecified":"true",
"hide":{
"hideWhenExpression":"false"
},
"validators":[]
}
]
}
]
}
]
}
]
},
{
"label": "Screening Section",
"questions": [
{
"label": "Do you have dependents?",
"id": "hasDependents",
"type": "obs",
"questionOptions": {
"rendering": "radio",
"concept": "a89e3f94-1350-11df-a1f1-0026b9348837",
"answers": [
{
"concept": "a89ce50e-1350-11df-a1f1-0026b9348839",
"label": "Yes"
},
{
"label": "Date of Birth",
"type": "obs",
"questionOptions": {
"rendering": "date",
"concept": "164802AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"weeksList": ""
},
"id": "birthDate",
"behaviours": [
"concept": "a89ce50e-1350-11df-a1f1-0026b9348838",
"label": "No"
}
]
}
}
]
},
{
"label": "Groups with Hide logic",
"questions": [
{
"type": "obsGroup",
"label": "Dependents Group",
"id": "dependentGroup",
"questionOptions": {
"concept": "3665d0ef-3718-47b2-9091-8b685bda412d",
"rendering": "group"
},
"questions": [
{
"label": "Dependent Type",
"id": "dependentType",
"type": "obs",
"questionOptions": {
"rendering": "radio",
"concept": "a89e3f94-1350-11df-a1f1-0026b9348838",
"answers": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "!isDateEqualTo(myValue, useFieldValue('visit_date'))",
"message": "Child birth date should be the same as the visit date!"
}
]
"concept": "6daff4ce-bce7-41f5-9141-17e694155180",
"label": "Child"
},
{
"concept": "a89ce50e-1350-11df-a1f1-0026b9348838",
"label": "Spouse"
}
]
},
"hide": {
"hideWhenExpression": "hasDependents !== 'a89ce50e-1350-11df-a1f1-0026b9348839'"
}
]
}
]
}
]
}
],
"availableIntents": [
{
"intent": "*",
"display": "ObsGroup Test Form"
}
],
"processor": "EncounterFormProcessor",
"uuid": "8f713e0e-94a0-3c57-9024-69520933802a",
"referencedForms": [],
"encounterType": "7e54cd64-f9c3-11eb-8e6a-57478ce139b0",
"encounter": "Obs Group Test",
"allowUnspecifiedAll": true
}

},
{
"label": "Dependent Name",
"id": "dependentName",
"type": "obs",
"questionOptions": {
"rendering": "text",
"concept": "a8a06fc6-1350-11df-a1f1-0026b9348838"
},
"hide": {
"hideWhenExpression": "isEmpty(dependentType)"
}
},
{
"label": "Dependent Age",
"id": "dependentAge",
"type": "obs",
"questionOptions": {
"rendering": "number",
"concept": "a8a06fc6-1350-11df-a1f1-0026b9348839"
},
"hide": {
"hideWhenExpression": "dependentType !== '6daff4ce-bce7-41f5-9141-17e694155180'"
}
}
]
}
]
}
]
}
],
"availableIntents": [
{
"intent": "*",
"display": "ObsGroup Test Form"
}
],
"processor": "EncounterFormProcessor",
"uuid": "8f713e0e-94a0-3c57-9024-69520933802a",
"referencedForms": [],
"encounterType": "7e54cd64-f9c3-11eb-8e6a-57478ce139b0",
"encounter": "Obs Group Test",
"allowUnspecifiedAll": true
}
10 changes: 5 additions & 5 deletions src/components/group/obs-group.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { useTranslation } from 'react-i18next';

export const ObsGroup: React.FC<FormFieldInputProps> = ({ field, ...restProps }) => {
const { t } = useTranslation();
const { formFieldAdapters } = useFormProviderContext();
const showLabel = useMemo(() => field.questions?.length > 1, [field]);
const { formFieldAdapters, formFields } = useFormProviderContext();

const content = useMemo(
() =>
field.questions
?.filter((child) => !child.isHidden)
.map((child) => formFields.find((field) => field.id === child.id))
.filter((child) => !child.isHidden)
.map((child, index) => {
const key = `${child.id}_${index}`;

Expand All @@ -35,12 +35,12 @@ export const ObsGroup: React.FC<FormFieldInputProps> = ({ field, ...restProps })
);
}
}),
[field],
[field, formFields],
);

return (
<div className={styles.groupContainer}>
{showLabel ? (
{content.length > 1 ? (
<FormGroup legendText={t(field.label)} className={styles.boldLegend}>
{content}
</FormGroup>
Expand Down
Loading

0 comments on commit 4e34674

Please sign in to comment.