openmrs / openmrs-esm-form-engine-lib

React Form Engine library for O3
Other
10 stars 59 forks source link

(feat) O3-3699 Add support to hide answers based on expression condition #374

Closed pirupius closed 3 weeks ago

pirupius commented 1 month ago

Requirements

Summary

This is a utility helper to filter and hide answers based on predefined question conditions.

Dummy JSON Question

{
  "label": "Hide Expression Answers",
  "isExpanded": "true",
  "questions": [
    {
      "id": "testQuestionExpression",
      "label": "Show only answers that match criteria",
      "type": "obs",
      "questionOptions": {
        "rendering": "radio",
        "concept": "my-defined-concept-uuid",
        "hideAnswers": {
          "hideWhenExpression": "['concept-uuid-2', 'concept-uuid-3']"
        },
        "answers": [
          {
            "concept": "concept-uuid-1",
            "label": "Choice 1",
            "conceptMappings": []
          },
          {
            "concept": "concept-uuid-2",
            "label": "Choice 2",
            "conceptMappings": []
          },
          {
            "concept": "concept-uuid-3",
            "label": "Choice 3",
            "conceptMappings": []
          },
          {
            "concept": "concept-uuid-4",
            "label": "Choice 4",
            "conceptMappings": []
          },
          {
            "concept": "concept-uuid-5",
            "label": "Choice 5",
            "conceptMappings": []
          }
        ]
      }
    }
  ]
}

Based on the all the answers being rendered as options to chose from, an optional hideAnswers can be passed to filter and display only answers that match a criteria (The json above just passes valid answers). Out of the 5 or more only 2 pass the condition so those will be the only options displayed

Screenshot 2024-09-05 at 14 29 48

Screenshots

https://github.com/user-attachments/assets/072b7ee5-572f-4494-a627-c9ae508fbf1d

Related Issue

https://openmrs.atlassian.net/browse/O3-3699

Other

github-actions[bot] commented 1 month ago

Size Change: -205 kB (-15.23%) πŸ‘

Total Size: 1.14 MB

Filename Size Change
dist/617.js 0 B -86.9 kB (removed) πŸ†
dist/733.js 0 B -107 kB (removed) πŸ†
dist/901.js 0 B -11.8 kB (removed) πŸ†
ℹ️ View Unchanged | Filename | Size | Change | | :--- | :---: | :---: | | `dist/116.js` | 110 kB | 0 B | | `dist/118.js` | 7.84 kB | 0 B | | `dist/151.js` | 300 kB | 0 B | | `dist/225.js` | 2.57 kB | 0 B | | `dist/277.js` | 1.84 kB | 0 B | | `dist/3.js` | 481 B | 0 B | | `dist/300.js` | 642 B | 0 B | | `dist/335.js` | 968 B | 0 B | | `dist/353.js` | 3.02 kB | 0 B | | `dist/41.js` | 3.37 kB | 0 B | | `dist/422.js` | 6.8 kB | 0 B | | `dist/540.js` | 2.63 kB | 0 B | | `dist/55.js` | 758 B | 0 B | | `dist/572.js` | 252 kB | +119 B (+0.05%) | | `dist/635.js` | 14.3 kB | 0 B | | `dist/96.js` | 89.8 kB | 0 B | | `dist/99.js` | 691 B | 0 B | | `dist/993.js` | 3.09 kB | 0 B | | `dist/main.js` | 340 kB | -288 B (-0.08%) | | `dist/openmrs-esm-form-engine-lib.js` | 3.66 kB | -4 B (-0.11%) |

compressed-size-action

samuelmale commented 1 month ago

@pirupius I'm not sure I understand the issue you are solving here. From the sample JSON:

"hideAnswers": {
     "hideWhenExpression": "['concept-uuid-2', 'concept-uuid-3']"
 },

Is the above meant to be some kind of a conditional statement?

pirupius commented 1 month ago

@samuelmale this was a bad example, was trying to show something more direct. Let me update with a real world scenario.

pirupius commented 3 weeks ago

After a another thought at this, i've decided to close this PR in favor of reusing some of the already available features. This eliminate the need to maintain more code and avoid duplication.