Skip to content

Commit

Permalink
O3-2253: Ability to mark a form field as transient (#127)
Browse files Browse the repository at this point in the history
* Initial commit with rough tests

* Updated test suites

* Update ohri-encounter-form.component.tsx

* Update ohri-encounter-form.component.tsx

* clean up

* Update src/api/types.ts

Co-authored-by: Jovan Ssebaggala <[email protected]>

* Update src/components/encounter/ohri-encounter-form.component.tsx

Co-authored-by: Jovan Ssebaggala <[email protected]>

* Update src/ohri-form.component.test.tsx

Co-authored-by: Jovan Ssebaggala <[email protected]>

* Update ohri-encounter-form.component.tsx

* Clean up

* Resolved comments

* Ability to mark a form field as transient and form submission tests

* Update ohri-form.component.test.tsx

---------

Co-authored-by: arodidev <[email protected]>
Co-authored-by: Jamie Arodi <[email protected]>
Co-authored-by: Jovan Ssebaggala <[email protected]>
  • Loading branch information
4 people authored Oct 6, 2023
1 parent 9b46355 commit a71f2bb
Show file tree
Hide file tree
Showing 4 changed files with 571 additions and 156 deletions.
241 changes: 241 additions & 0 deletions __mocks__/forms/ohri-forms/test-enrolment-form.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
{
"name": "Service Enrolment 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:** Enrolment/Re-enrol a client for HIV Care"
]
}
]
}
]
},
{
"label": "Client Profile",
"sections": [
{
"label": "Client Details",
"isExpanded": "true",
"questions": [
{
"label": "Enrolment Date",
"type": "obs",
"questionOptions": {
"isTransient": "true",
"rendering": "date",
"concept": "160555AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "date",
"allowFutureDates": "false"
},
{
"type": "js_expression",
"failsWhenExpression": "isDateBefore(myValue, '1980-01-01')"
}
]
}
],
"id": "hivEnrolmentDate"
},
{
"label": "Unique ID",
"type": "obs",
"questionOptions": {
"rendering": "text",
"concept": "162576AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
},
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
},
"validators": [
{
"type": "js_expression",
"failsWhenExpression": "isEmpty(patientIdentifier)"
}
]
}
],
"id": "patientIdentifier"
},
{
"label": "Patient Type at Enrolment",
"type": "obs",
"questionOptions": {
"rendering": "radio",
"concept": "83e40f2c-c316-43e6-a12e-20a338100281",
"answers": [
{
"concept": "163532AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Mother enrolled in PMTCT program",
"conceptMappings": []
},
{
"concept": "159833AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Re-enrol",
"conceptMappings": []
},
{
"concept": "160563AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Transfer in",
"conceptMappings": []
},
{
"concept": "164144AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "New client",
"conceptMappings": []
}
]
},
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "false",
"hide": {
"hideWhenExpression": "false"
}
}
],
"id": "clientDescription"
},
{
"label": "Population Category",
"type": "obs",
"questionOptions": {
"rendering": "radio",
"concept": "166432AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"answers": [
{
"concept": "166431AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "Key population",
"conceptMappings": [
{
"type": "SNOMED-CT",
"value": "385436007"
}
]
},
{
"concept": "166430AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"label": "General population",
"conceptMappings": [
{
"type": "SNOMED-CT",
"value": "385436007"
}
]
}
]
},
"behaviours": [
{
"intent": "*",
"required": "true",
"unspecified": "true",
"hide": {
"hideWhenExpression": "false"
}
}
],
"id": "clientPopulationCategory"
}
]
}
]
},

{
"label": "Notes",
"sections": [
{
"label": "Enrollment notes",
"isExpanded": "true",
"questions": [
{
"label": "General notes",
"type": "obs",
"questionOptions": {
"rendering": "textarea",
"concept": "165095AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"rows": "",
"conceptMappings": [
{
"type": "AMPATH",
"value": "1915"
},
{
"type": "AMPATH",
"value": "1915"
},
{
"type": "LOINC",
"value": "48767-8"
},
{
"type": "CIEL",
"value": "160632"
}
]
},
"id": "generalNotes",
"behaviours": [
{
"intent": "*",
"required": "false",
"unspecified": "false",
"hide": {
"hideWhenExpression": "false"
},
"validators": []
}
]
}
]
}
]
}
],
"availableIntents": [
{
"intent": "*",
"display": "Service Enrolment Form"
}
],
"processor": "EncounterFormProcessor",
"uuid": "8f713e0e-94a0-3c57-9024-69520933802a",
"referencedForms": [],
"encounterType": "7e54cd64-f9c3-11eb-8e6a-57478ce139b0",
"encounter": "Care and Treatment Service Enrolment",
"allowUnspecifiedAll": true
}

1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export interface OHRIFormQuestionOptions {
/**
* maxLength and maxLength are used to validate text field length
*/
isTransient?: boolean;
maxLength?: string;
minLength?: string;
showDate?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/components/encounter/ohri-encounter-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,10 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
const handleFormSubmit = (values: Record<string, any>) => {
const obsForSubmission = [];
fields
.filter(field => field.value || field.type == 'obsGroup') // filter out fields with empty values except groups
.filter(field => field.value || field.type == 'obsGroup' ) // filter out fields with empty values except groups
.filter(field => !field.isParentHidden && !field.isHidden && (field.type == 'obs' || field.type == 'obsGroup'))
.filter(field => !field['groupId']) // filter out grouped obs
.filter(field => !field.questionOptions.isTransient) //filter out fields marked as transient
.forEach(field => {
if (field.type == 'obsGroup') {
const obsGroup = {
Expand Down
Loading

0 comments on commit a71f2bb

Please sign in to comment.