in o3 forn calculateExpression does not seems capable of using other calculateExpression

Hi,

I want to chain calculates in the form but I fail to be able to retrieve the value for a calculate in an other calculate

here a form question test, first show true, second is empty

{
              "id": "triage_RED_Vv_1",
              "type": "control",
              "label": "triage RED vv 1",
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "true"
                }
              }
            },
            {
              "id": "triage_RED_Vv_2",
              "type": "control",
              "label": "triage RED  vv 2",
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "triage_RED_Vv_1"
                }
              }
            }

br

I had a bit fun with cline@grok-code- fast last night, this should cover the need but I was not able to load the engine-lib in the formbuilder local instance (I did yarn build/link) but I see no difference

br

poke @grace , even if that fix works, I am not sure O3 could support very complex form with a decent performance, TBC, the good part is the script to convert the drawio to O3 form seems to work (their is a limited supported functions but if the calc work I could extend them)

Hi @delcroip!

Thank you for reporting and taking a spike at the issue.

but I was not able to load the engine-lib in the formbuilder local instance (I did yarn build/link) but I see no difference

Steps for linking the FE in Form builder:

  1. Copy form engine path:
    • cd to form-engine root dir eg. /Users/samuel/Dev/openmrs-form-engine-lib
    • Copy path: pwd | pbcopy
  2. Navigate to the form-builder and link
    • cd to the form builder, eg. /Users/samuel/Dev/openmrs-esm-form-builder
    • run: yarn link path/form-engine Eg. yarn link /Users/samuel/Dev/openmrs-form-engine-lib
  3. Start form-builder

Let me know incase you run into any errors

Thank you,

I followed a similar approach and it worked (after some change), the PR is updated.

I sill have to check in details why the overall behaviour is not the one I expected from my test form but likely cause by an error on the form itself

I’ve provided a more detailed response on the PR, thank you!

I updated the PR and it works now

Here the payload (generated by TRICC)

{
  "$schema": "http://json.openmrs.org/form.schema.json",
  "name": "triage RED",
  "uuid": "df51d58e-d31d-56bb-99ec-121fc64707ba",
  "encounterType": "f18fa121-2b86-530f-aaf9-109ac6734265",
  "processor": "EncounterFormProcessor",
  "published": false,
  "retired": false,
  "version": "1.0",
  "availableIntents": [
    {
      "intent": "*",
      "display": "openmrs_form"
    }
  ],
  "referencedForms": [],
  "encounter": "openmrs_form",
  "pages": [
    {
      "label": "registration",
      "sections": [
        {
          "label": "A AND B",
          "questions": [
            {
              "label": "Is Airway compromised?",
              "type": "obs",
              "questionOptions": {
                "rendering": "select",
                "concept": "ce298c6e-2a7e-5939-8b4b-b95d69afa6d0",
                "answers": [
                  {
                    "label": "Yes",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  },
                  {
                    "label": "No",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "ask_WhmR5lBpts5AyKrwe5l7_1",
              "uuid": "ce298c6e-2a7e-5939-8b4b-b95d69afa6d0"
            },
            {
              "label": "Is breathing abnormal?",
              "type": "obs",
              "questionOptions": {
                "rendering": "select",
                "concept": "d7d808db-8e9b-531a-9eb0-8244f7cfe544",
                "answers": [
                  {
                    "label": "Yes",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  },
                  {
                    "label": "No",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "ask_WhmR5lBpts5AyKrwe5l7_4",
              "uuid": "d7d808db-8e9b-531a-9eb0-8244f7cfe544",
              "hide": {
                "hideWhenExpression": "!((ask_WhmR5lBpts5AyKrwe5l7_1 === false || ask_WhmR5lBpts5AyKrwe5l7_1 === '1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'))"
              }
            },
            {
              "label": "any of the following present?",
              "type": "obs",
              "questionOptions": {
                "rendering": "multiCheckbox",
                "concept": "35b89e96-82ef-50b8-8de9-b73747ef7a97",
                "answers": [
                  {
                    "label": "Oxygen sats 90-92%",
                    "concept": "5c2e7532-0175-5719-af96-51ff72fc0522"
                  },
                  {
                    "label": "Respiratory rate >9 or 21-30",
                    "concept": "3827ff62-9f74-5ba6-8343-e4d9cf3b0b27"
                  },
                  {
                    "label": "None of the above",
                    "concept": "7c980f3b-f786-547b-819c-ff54ea25d9a3"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "select_NBMiA9EtcCHO311uYoVd_2",
              "uuid": "35b89e96-82ef-50b8-8de9-b73747ef7a97",
              "hide": {
                "hideWhenExpression": "!((ask_WhmR5lBpts5AyKrwe5l7_4 === false || ask_WhmR5lBpts5AyKrwe5l7_4 === '1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'))"
              }
            },
            {
              "label": "any of the following present?",
              "type": "obs",
              "questionOptions": {
                "rendering": "multiCheckbox",
                "concept": "b44791ba-688a-53bf-8365-c51a60ce8db7",
                "answers": [
                  {
                    "label": "Oxygen Sats < 89%",
                    "concept": "5c2e7532-0175-5719-af96-51ff72fc0522"
                  },
                  {
                    "label": "Respiratory rate <8 or >31",
                    "concept": "3827ff62-9f74-5ba6-8343-e4d9cf3b0b27"
                  },
                  {
                    "label": "Severe respiratory dysfunction or exhaustion",
                    "concept": "db33a733-cfc2-5be4-8fcc-2b46edf2ad3d"
                  },
                  {
                    "label": "Inability to speak in complete sentences",
                    "concept": "4674ea43-9276-5c72-87a8-2d3797bfc8ab"
                  },
                  {
                    "label": "Stridor",
                    "concept": "a4bae45d-626b-51bd-8f97-3628b3560520"
                  },
                  {
                    "label": "Reduced level of consciousness due to low oxygen",
                    "concept": "c63cb4cf-f293-5ad2-a5a5-f574f100e191"
                  },
                  {
                    "label": "None of the above",
                    "concept": "7c980f3b-f786-547b-819c-ff54ea25d9a3"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "select_jmjsKcAgqat1JtKRkfiv_1",
              "uuid": "b44791ba-688a-53bf-8365-c51a60ce8db7",
              "hide": {
                "hideWhenExpression": "!((ask_WhmR5lBpts5AyKrwe5l7_4 === true || ask_WhmR5lBpts5AyKrwe5l7_4 === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'))"
              }
            }
          ]
        }
      ]
    },
    {
      "label": "determine-diagnosis",
      "sections": [
        {
          "label": "Classifications",
          "questions": [
            {
              "label": "TRIAGE YELLOW",
              "type": "obs",
              "questionOptions": {
                "rendering": "select",
                "concept": "2f25c0c1-5721-5c64-8105-2e646e558adb",
                "answers": [
                  {
                    "label": "Accept",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  },
                  {
                    "label": "Reject",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "pre_final_TRIAGE_YELLOW",
              "uuid": "2f25c0c1-5721-5c64-8105-2e646e558adb",
              "hide": {
                "hideWhenExpression": "!(TRIAGE_YELLOW === true || TRIAGE_YELLOW === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')"
              }
            },
            {
              "label": "triage RED",
              "type": "obs",
              "questionOptions": {
                "rendering": "select",
                "concept": "817420b6-c2da-5c59-9587-fc3c77f4924d",
                "answers": [
                  {
                    "label": "Accept",
                    "concept": "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  },
                  {
                    "label": "Reject",
                    "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "pre_final_triage_RED",
              "uuid": "817420b6-c2da-5c59-9587-fc3c77f4924d",
              "hide": {
                "hideWhenExpression": "!(triage_RED === true || triage_RED === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')"
              }
            },
            {
              "label": "Add classifications",
              "type": "obs",
              "questionOptions": {
                "rendering": "multiCheckbox",
                "concept": "587bee7e-356d-5600-83e6-d52b031faf54",
                "answers": [
                  {
                    "label": "TRIAGE YELLOW",
                    "concept": "4d940877-5d44-5ca3-a0c7-0f4f60479cfd"
                  },
                  {
                    "label": "triage RED",
                    "concept": "c02e5b75-adc4-50c4-b573-5adddf2da026"
                  }
                ]
              },
              "required": true,
              "unspecified": false,
              "id": "tricc_manual_diag",
              "uuid": "587bee7e-356d-5600-83e6-d52b031faf54"
            }
          ]
        }
      ]
    },
    {
      "label": "Calculations",
      "sections": [
        {
          "label": "Calculations",
          "questions": [
            {
              "id": "version",
              "type": "control",
              "label": "",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "version()"
                }
              }
            },
            {
              "id": "TRIAGE_YELLOW",
              "type": "control",
              "label": "TRIAGE YELLOW",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "((select_NBMiA9EtcCHO311uYoVd_2.includes('5c2e7532-0175-5719-af96-51ff72fc0522')) || (select_NBMiA9EtcCHO311uYoVd_2.includes('3827ff62-9f74-5ba6-8343-e4d9cf3b0b27')))"
                }
              }
            },
            {
              "id": "triage_RED_Vv_1",
              "type": "control",
              "label": "triage RED",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "(ask_WhmR5lBpts5AyKrwe5l7_4 === true || ask_WhmR5lBpts5AyKrwe5l7_4 === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') && select_jmjsKcAgqat1JtKRkfiv_1.length - Number((select_jmjsKcAgqat1JtKRkfiv_1.includes('7c980f3b-f786-547b-819c-ff54ea25d9a3'))) > 0"
                }
              }
            },
            {
              "id": "triage_RED",
              "type": "control",
              "label": "triage RED",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "((ask_WhmR5lBpts5AyKrwe5l7_1 === true || ask_WhmR5lBpts5AyKrwe5l7_1 === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') || (triage_RED_Vv_1 === true || triage_RED_Vv_1 === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'))"
                }
              }
            },
            {
              "id": "end_MocptzA2DGFnPYzxlNRT_1",
              "type": "control",
              "label": "end",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "true"
                }
              }
            },
            {
              "id": "final_TRIAGE_YELLOW",
              "type": "control",
              "label": "TRIAGE YELLOW",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "((pre_final_TRIAGE_YELLOW === true || pre_final_TRIAGE_YELLOW === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') || (tricc_manual_diag.includes('TRIAGE_YELLOW')))"
                }
              }
            },
            {
              "id": "final_triage_RED",
              "type": "control",
              "label": "triage RED",
              "hide": {
                "hideWhenExpression": "true"
              },
              "questionOptions": {
                "calculate": {
                  "calculateExpression": "((pre_final_triage_RED === true || pre_final_triage_RED === '1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') || (tricc_manual_diag.includes('triage_RED')))"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}