{"action":"created","issue":{"url":"https://api.github.com/repos/medic/medic-webapp/issues/4457","repository_url":"https://api.github.com/repos/medic/medic-webapp","labels_url":"https://api.github.com/repos/medic/medic-webapp/issues/4457/labels{/name}","comments_url":"https://api.github.com/repos/medic/medic-webapp/issues/4457/comments","events_url":"https://api.github.com/repos/medic/medic-webapp/issues/4457/events","html_url":"https://github.com/medic/medic-webapp/issues/4457","id":316382184,"number":4457,"title":"The z-score enketo widget is not usable","user":{"login":"abbyad","id":789512,"avatar_url":"https://avatars3.githubusercontent.com/u/789512?v=4","gravatar_id":"","url":"https://api.github.com/users/abbyad","html_url":"https://github.com/abbyad","followers_url":"https://api.github.com/users/abbyad/followers","following_url":"https://api.github.com/users/abbyad/following{/other_user}","gists_url":"https://api.github.com/users/abbyad/gists{/gist_id}","starred_url":"https://api.github.com/users/abbyad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abbyad/subscriptions","organizations_url":"https://api.github.com/users/abbyad/orgs","repos_url":"https://api.github.com/users/abbyad/repos","events_url":"https://api.github.com/users/abbyad/events{/privacy}","received_events_url":"https://api.github.com/users/abbyad/received_events","type":"User","site_admin":false},"labels":[{"id":679686115,"url":"https://api.github.com/repos/medic/medic-webapp/labels/Priority:%202%20-%20Medium","name":"Priority: 2 - Medium","color":"880000","default":false},{"id":55021840,"url":"https://api.github.com/repos/medic/medic-webapp/labels/Status:%204%20-%20Acceptance%20testing","name":"Status: 4 - Acceptance testing","color":"669966","default":false},{"id":4577664,"url":"https://api.github.com/repos/medic/medic-webapp/labels/Type:%20Bug","name":"Type: Bug","color":"c10c02","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-20T19:18:21Z","updated_at":"2018-05-03T23:44:15Z","closed_at":null,"author_association":"OWNER","body":"As first reported by @binokaryg in https://github.com/medic/medic-projects/issues/3828 the calculation of Z-Score does not work as expected in `2.14`. \r\n\r\nFrom further testing it appears that z-score calculations work _in isolation_ in `2.14`, but not when getting the sex and age from the patient context. From what I can tell this is because:\r\n- the z-score calculation finds fields using `appearance` (eg `zscore-sex`, `zscore-age`) so they must be UI elements\r\n- we avoid manually re-entering the age and sex by passing them from the patient's profile (via context or `db-object`) and then have it assigned to a UI field using calculations\r\n- and as of 2.14 we should no longer use `calculation` on fields with UI input fields because of [unexpected results](https://github.com/medic/medic-webapp/issues/4134).\r\n\r\nWe previously used calculations like this, but it was an undocumented and unsupported feature, which we have since lost (_as is expected by undocumented features not in the spec_). \r\n\r\nHere are some possible alternatives, each requiring development and having their own pros and cons:\r\n1) Trigger the value change with Actions and Events, as per https://github.com/medic/medic-webapp/issues/4131. _Setting the values as static currently defaults works._\r\n1) Allow the z-score calculation to find the fields without UI elements, perhaps with specific field names. _May be quickest to implement, but requires some custom and inflexible naming convention, which is not ideal._\r\n1) Modify the z-score calculation to be an XPath calculation. _This would be ideal since it brings the configuration of this function in line with all other XForm functions we use. I seem to recall the reason we didn't do this in the first place was because of the async call to the z-score table._\r\n\r\n----\r\nHere is a test form: [issue_3828_4.zip](https://github.com/medic/medic-webapp/files/1933337/issue_3828_4.zip)\r\n\r\n```xml\r\n<?xml version=\"1.0\"?>\r\n<h:html xmlns=\"http://www.w3.org/2002/xforms\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:h=\"http://www.w3.org/1999/xhtml\" xmlns:jr=\"http://openrosa.org/javarosa\" xmlns:orx=\"http://openrosa.org/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <h:head>\r\n    <h:title>Growth Monitoring</h:title>\r\n    <model>\r\n      <instance>\r\n        <issue_3828_4 delimiter=\"#\" id=\"issue_3828_4\" prefix=\"J1!issue_3828_4!\" version=\"2017-05-16 00:00:00\">\r\n          <measurement>\r\n            <zscore>\r\n              <sex/>\r\n              <age_in_days/>\r\n              <zscore_sex/>\r\n              <zscore_age/>\r\n              <note_zscore_inputs/>\r\n              <zscore_weight/>\r\n              <zscore_height/>\r\n              <zscore_wfa/>\r\n              <zscore_hfa/>\r\n              <zscore_wfh/>\r\n              <wfa_message/>\r\n              <hfa_message/>\r\n              <wfh_message/>\r\n              <zscore_wfa_note/>\r\n              <zscore_hfa_note/>\r\n              <zscore_wfh_note/>\r\n            </zscore>\r\n          </measurement>\r\n          <meta tag=\"hidden\">\r\n            <instanceID/>\r\n          </meta>\r\n        </issue_3828_4>\r\n      </instance>\r\n      <instance id=\"contact-summary\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/sex\" type=\"select1\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/age_in_days\" type=\"int\"/>\r\n      <bind calculate=\" /issue_3828_4/measurement/zscore/sex \" nodeset=\"/issue_3828_4/measurement/zscore/zscore_sex\" required=\"true()\" type=\"select1\"/>\r\n      <bind calculate=\" /issue_3828_4/measurement/zscore/age_in_days \" nodeset=\"/issue_3828_4/measurement/zscore/zscore_age\" required=\"true()\" type=\"int\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/note_zscore_inputs\" readonly=\"true()\" type=\"string\"/>\r\n      <bind constraint=\". &gt;= 0.8 and . &lt;= 68.5\" jr:constraintMsg=\"Body weight must be between 0.8 and 68.5 kgs.\" nodeset=\"/issue_3828_4/measurement/zscore/zscore_weight\" required=\"true()\" type=\"decimal\"/>\r\n      <bind constraint=\". &gt;= 45 and . &lt;= 120\" jr:constraintMsg=\"Body height must be between 45 and 120 cms.\" nodeset=\"/issue_3828_4/measurement/zscore/zscore_height\" type=\"decimal\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/zscore_wfa\" type=\"decimal\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/zscore_hfa\" type=\"decimal\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/zscore_wfh\" type=\"decimal\"/>\r\n      <bind calculate=\"if( /issue_3828_4/measurement/zscore/zscore_wfa  = &quot;&quot;, &quot;&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfa  &lt; -3), &quot;&lt; -3SD [Severely Malnourished]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfa  &lt; -2 and  /issue_3828_4/measurement/zscore/zscore_wfa  &gt;= -3), &quot;-3SD to &lt; -2SD [Moderately Malnourished]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfa  &lt;= 2 and  /issue_3828_4/measurement/zscore/zscore_wfa  &gt;= -2), &quot;-2SD to 2SD [Normal]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfa  &gt; 2 and  /issue_3828_4/measurement/zscore/zscore_wfa  &lt;= 3), &quot;&gt;2SD [Overweight]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfa  &gt; 3 ), &quot;&gt;3SD [Obese]&quot;, &quot;&quot; ) ) ) ) ) )\" nodeset=\"/issue_3828_4/measurement/zscore/wfa_message\" type=\"string\"/>\r\n      <bind calculate=\"if( /issue_3828_4/measurement/zscore/zscore_hfa  = &quot;&quot;, &quot;&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_hfa  &lt; -3), &quot;&lt; -3SD [Severely Stunted]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_hfa  &lt; -2 and  /issue_3828_4/measurement/zscore/zscore_hfa  &gt;= -3), &quot;-3SD to &lt;-2SD [Moderately Stunted]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_hfa  &lt;= 2 and  /issue_3828_4/measurement/zscore/zscore_hfa  &gt;= -2), &quot;-2SD to 2SD [Normal]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_hfa  &gt; 2), &quot;&gt;2SD [High]&quot;, &quot;&quot; ) ) ) ) )\" nodeset=\"/issue_3828_4/measurement/zscore/hfa_message\" type=\"string\"/>\r\n      <bind calculate=\"if( /issue_3828_4/measurement/zscore/zscore_wfh  = &quot;&quot;, &quot;&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfh  &lt; -3), &quot;&lt; -3SD [Severely Wasted]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfh  &lt; -2 and  /issue_3828_4/measurement/zscore/zscore_wfh  &gt;= -3), &quot;-3SD to &lt;-2SD [Moderately Wasted]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfh  &lt;= 2 and  /issue_3828_4/measurement/zscore/zscore_wfh  &gt;= -2), &quot;-2SD to 2SD [Normal]&quot;, if( ( /issue_3828_4/measurement/zscore/zscore_wfh  &gt; 2), &quot;&gt;2SD [Overweight]&quot;, &quot;&quot; ) ) ) ))\" nodeset=\"/issue_3828_4/measurement/zscore/wfh_message\" type=\"string\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/zscore_wfa_note\" readonly=\"true()\" type=\"string\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/zscore_hfa_note\" readonly=\"true()\" relevant=\" /issue_3828_4/measurement/zscore/zscore_hfa  != ''\" type=\"string\"/>\r\n      <bind nodeset=\"/issue_3828_4/measurement/zscore/zscore_wfh_note\" readonly=\"true()\" relevant=\" /issue_3828_4/measurement/zscore/zscore_wfh  != ''\" type=\"string\"/>\r\n      <bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/issue_3828_4/meta/instanceID\" readonly=\"true()\" type=\"string\"/>\r\n    </model>\r\n  </h:head>\r\n  <h:body class=\"pages\">\r\n    <group appearance=\"field-list\" ref=\"/issue_3828_4/measurement\">\r\n      <label>Measurements</label>\r\n      <group appearance=\"zscore\" ref=\"/issue_3828_4/measurement/zscore\">\r\n        <label></label>\r\n        <select1 ref=\"/issue_3828_4/measurement/zscore/sex\">\r\n          <label>Sex [typically populated from patient's doc]</label>\r\n          <item>\r\n            <label>Male</label>\r\n            <value>male</value>\r\n          </item>\r\n          <item>\r\n            <label>Female</label>\r\n            <value>female</value>\r\n          </item>\r\n        </select1>\r\n        <input ref=\"/issue_3828_4/measurement/zscore/age_in_days\">\r\n          <label>Age in days (days) [typically populated from patient's doc]</label>\r\n        </input>\r\n        <select1 appearance=\"zscore-sex hidden\" ref=\"/issue_3828_4/measurement/zscore/zscore_sex\">\r\n          <label>Sex [HIDDEN]</label>\r\n          <item>\r\n            <label>Male</label>\r\n            <value>male</value>\r\n          </item>\r\n          <item>\r\n            <label>Female</label>\r\n            <value>female</value>\r\n          </item>\r\n        </select1>\r\n        <input appearance=\"zscore-age hidden\" ref=\"/issue_3828_4/measurement/zscore/zscore_age\">\r\n          <label>Age in days (days) [HIDDEN]</label>\r\n        </input>\r\n        <input ref=\"/issue_3828_4/measurement/zscore/note_zscore_inputs\">\r\n          <label>**Values from calculated hidden fields:**\r\n - **Sex** <output value=\" /issue_3828_4/measurement/zscore/zscore_sex \"/>\r\n - **Age (days)** <output value=\" /issue_3828_4/measurement/zscore/zscore_age \"/></label></input>\r\n        <input appearance=\"zscore-weight\" ref=\"/issue_3828_4/measurement/zscore/zscore_weight\">\r\n          <label>Body Weight (kg)</label>\r\n        </input>\r\n        <input appearance=\"zscore-height\" ref=\"/issue_3828_4/measurement/zscore/zscore_height\">\r\n          <label>Body Height (cm)</label>\r\n        </input>\r\n        <input appearance=\"zscore-weight-for-age hidden\" ref=\"/issue_3828_4/measurement/zscore/zscore_wfa\">\r\n          <label>WFA</label>\r\n        </input>\r\n        <input appearance=\"zscore-height-for-age hidden\" ref=\"/issue_3828_4/measurement/zscore/zscore_hfa\">\r\n          <label>HFA</label>\r\n        </input>\r\n        <input appearance=\"zscore-weight-for-height hidden\" ref=\"/issue_3828_4/measurement/zscore/zscore_wfh\">\r\n          <label>WFH</label>\r\n        </input>\r\n        <input ref=\"/issue_3828_4/measurement/zscore/zscore_wfa_note\">\r\n          <label>Weight for Age: <output value=\" /issue_3828_4/measurement/zscore/wfa_message \"/></label>\r\n        </input>\r\n        <input ref=\"/issue_3828_4/measurement/zscore/zscore_hfa_note\">\r\n          <label>Height for Age: <output value=\" /issue_3828_4/measurement/zscore/hfa_message \"/></label>\r\n        </input>\r\n        <input ref=\"/issue_3828_4/measurement/zscore/zscore_wfh_note\">\r\n          <label>Weight for Height: <output value=\" /issue_3828_4/measurement/zscore/wfh_message \"/></label>\r\n        </input>\r\n      </group>\r\n    </group>\r\n  </h:body>\r\n</h:html>\r\n```"},"comment":{"url":"https://api.github.com/repos/medic/medic-webapp/issues/comments/386469226","html_url":"https://github.com/medic/medic-webapp/issues/4457#issuecomment-386469226","issue_url":"https://api.github.com/repos/medic/medic-webapp/issues/4457","id":386469226,"user":{"login":"garethbowen","id":2064938,"avatar_url":"https://avatars2.githubusercontent.com/u/2064938?v=4","gravatar_id":"","url":"https://api.github.com/users/garethbowen","html_url":"https://github.com/garethbowen","followers_url":"https://api.github.com/users/garethbowen/followers","following_url":"https://api.github.com/users/garethbowen/following{/other_user}","gists_url":"https://api.github.com/users/garethbowen/gists{/gist_id}","starred_url":"https://api.github.com/users/garethbowen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethbowen/subscriptions","organizations_url":"https://api.github.com/users/garethbowen/orgs","repos_url":"https://api.github.com/users/garethbowen/repos","events_url":"https://api.github.com/users/garethbowen/events{/privacy}","received_events_url":"https://api.github.com/users/garethbowen/received_events","type":"User","site_admin":false},"created_at":"2018-05-03T23:44:15Z","updated_at":"2018-05-03T23:44:15Z","author_association":"OWNER","body":"For AT, ensure that the zscore widget and xpath calculation both work for 2.14 and 2.15. The widget has been removed completely in 3.0."}}
{"actor":{"display_login":"garethbowen"}}