O3 form boolean cannot be null

Dear all,

I am quite new in openMRS even if I am in the digital health fields for years.

I am trying to have question that could take boolean value, I found “toggle” input [https://openmrs.atlassian.net/wiki/spaces/docs/pages/68681754/Field+Types+Reference#toggle\\] fast but I have a huge issue: they cannot be null … this is a problem because an observation not done is not equal to no found (see FHIR management of bool).

in my case it is particularly problematic because I build the form from a drawio file that is also use to create form in CHT and ODK, therefore I would like to keep the skip logic clean and not use concept when the data is from the form and bool if from history

Please advise

note: the answers list seem not mandatory for toggle

So far the only approach that I can find is to extend the helper with isTrue and isFalse along with select using the CIEL UUID for yes/no 1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

// LMM generated
// Import the Form Engine’s expression helper registration function
import { registerExpressionHelper } from '@openmrs/esm-form-engine-lib';

// Constants for CIEL Yes/No UUIDs
const CIEL_YES_UUID = '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; //'3cd6f600-26fe-102b-80cb-0017a47871b2'; CIEL:1065 (Yes)
const CIEL_NO_UUID = '1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; //'3cd6f86c-26fe-102b-80cb-0017a47871b2';  CIEL:1066 (No)

// Custom function: isTrue
// Returns true if value is not undefined, not null, and either true (boolean) or CIEL Yes UUID
registerExpressionHelper('isTrue', (value) => {
  if (value === undefined || value === null) {
    return false;
  }
  return value === true || value === CIEL_YES_UUID;
});

// Custom function: isFalse
// Returns true if value is not undefined, not null, and either false (boolean) or CIEL No UUID
registerExpressionHelper('isFalse', (value) => {
  if (value === undefined || value === null) {
    return false;
  }
  return value === false || value === CIEL_NO_UUID;
});

Does that approach makes sense ?

br

You could just use a two-valued radio control too (with "orientation": "horizontal" to make it more compact).

Thank you

it does not work, the question with "hideWhenExpression": "!((ask_cVjjgBlzz0tecl0hnNG0_56 === false ))" is not showing up, Did I missed something ?

          {
              "label": "Is Airway compromised?",
              "type": "obs",
              "questionOptions": {
                "rendering": "content-switcher",
                "concept": "4073958a-ff61-5209-8a20-839488ec19fd",
                "answers": [
                  {
                    "label": "Yes",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
                    "value": true
                  },
                  {
                    "label": "No",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
                    "value": false
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "ask_cVjjgBlzz0tecl0hnNG0_56",
              "uuid": "4073958a-ff61-5209-8a20-839488ec19fd"
            },

@delcroip you need to compare with the concept UUID of false in the hideWhenExpression. Here’s an example:

{
  "id": "sampleQuestion",
  "label": "Hidden if the answer to is airway compromised is true or not given",
  "type": "obs",
  "questionOptions": {
    "rendering": "text",
    "concept": "a-system-defined-concept-uuid"
  },
  "hide": {
    "hideWhenExpression": "isEmpty(ask_cVjjgBlzz0tecl0hnNG0_56) || ask_cVjjgBlzz0tecl0hnNG0_56 !== '1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'"
  }
}
1 Like

thank you but I know that I can do that but it is still problematic because I also want to be able to have a streamlined approach when I test data entry and calculate output (the later does not work either ).

my current workarround is the generate more complex checks but it will harm performance, here a simple example (all operation are generated from either a decision tree or CQL like code):

            {
              "label": "Is Airway compromised?",
              "type": "obs",
              "questionOptions": {
                "rendering": "select",
                "concept": "4073958a-ff61-5209-8a20-839488ec19fd",
                "answers": [
                  {
                    "label": "Yes",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  },
                  {
                    "label": "No",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "ask_cVjjgBlzz0tecl0hnNG0_56",
              "uuid": "4073958a-ff61-5209-8a20-839488ec19fd"
            },
            {
              "label": "Is breathing abnormal?",
              "type": "obs",
              "questionOptions": {
                "rendering": "select",
                "concept": "91cd9058-0087-5a61-8de4-a57b3c548cb7",
                "answers": [
                  {
                    "label": "Yes",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  },
                  {
                    "label": "No",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "ask_cVjjgBlzz0tecl0hnNG0_61",
              "uuid": "91cd9058-0087-5a61-8de4-a57b3c548cb7",
              "hide": {
                "hideWhenExpression": "!((ask_cVjjgBlzz0tecl0hnNG0_56 === false || ask_cVjjgBlzz0tecl0hnNG0_56 === '1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'))"
              }
            },