Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate fields with relevance conditions fail to evaluate #133

Closed
kennsippell opened this issue Aug 30, 2021 · 7 comments
Closed

Calculate fields with relevance conditions fail to evaluate #133

kennsippell opened this issue Aug 30, 2021 · 7 comments
Assignees

Comments

@kennsippell
Copy link
Member

To Reproduce
Form supervision_with_chw_iccm in https://github.com/medic/config-muso/pull/418/checks?check_run_id=3463026173#step:6:1297

  it('#weird form', async () => {
    await harness.setNow('2000-04-30');
    const noPatientEvaluated = submissionDate => [
      submissionDate ? ['no', submissionDate] : ['yes'],
      ['yes', 'yes'],
      ['yes', 'yes'],
      ['no'],
      [...Array(16).fill('yes')],
      ['yes', 'yes'],
      ['yes'],
      ['Other comments'],
      []
    ];
    const result1 = await harness.fillForm('supervision_with_chw_iccm', ...noPatientEvaluated());
    expect(result1.errors).to.be.empty;
  });

What happened?
AssertionError: expected 'Exception in form-host fillAppForm: FormLogicError: Could not evaluate: /model/instance[1]/supervision_with_chw_iccm/s_patient_evaluation_group/s_patient_evaluation_list/s_taking_other_parameters/has_counted_resp_rate = \'yes\', message: Cannot read property \'ownerDocument\' of undefined' to be empty

What did you expect?
Can complete form.

@kennsippell kennsippell self-assigned this Aug 30, 2021
@kennsippell
Copy link
Member Author

kennsippell commented Aug 31, 2021

This reproduces on cht-core 3.10.5. I believe this is a cht-core issue not a parity issue in the harness.

@derickl
Copy link
Member

derickl commented Sep 1, 2021

This isn't a bug in cht-core. The root cause was linked to having a relevance condition to calculate expression.

This thread and this were quite informative.

If I understand well, it means that ALL calculation types are always “fired”, even in an empty repeat (count 0) or a non-relevant group. So, a relevant clause together with a calculation type NEVER makes sense. Could you confirm, please?

What was weird was that the nodes called out in the error were always in an irrelevant block.

@Marina-Kenf To fix your form, you'd need to delete any relevance expressions on calculate fields and reuse them in the calculation expression.

I'll give an example:

Under s_tdr_realisation,
we have a calculate field other_sign
with the following relevance condition selected(${which_indication_for_tdr}, 'other')
and the following calculation expression ${specify_other_indication_for_tdr}

To fix this, you'd delete the relevance expression and reuse it in the calculation as follows:
if(selected(${which_indication_for_tdr}, 'other'), ${specify_other_indication_for_tdr}, '')

@derickl derickl closed this as completed Sep 1, 2021
@derickl derickl changed the title Form fails to complete when repeat block has 0 elements Calculate fields with relevance conditions fail to evaluate Sep 1, 2021
@derickl derickl reopened this Sep 1, 2021
@derickl
Copy link
Member

derickl commented Sep 1, 2021

Investigate parity issue with #78

@kennsippell
Copy link
Member Author

kennsippell commented Sep 14, 2021

@derickl In your opinion, should the harness (or pyxform) error/fail tests when there is a relevant condition on a calculate field? Should form authors be completing avoiding that data combination?

@derickl
Copy link
Member

derickl commented Sep 27, 2021

should the harness (or pyxform) error/fail tests when there is a relevant condition on a calculate field
Yes.

Should form authors be completely avoiding that data combination?
Yes.

@kennsippell
Copy link
Member Author

@derickl I've opened medic/cht-conf#436. Do you think that would be the correct fix for this? Are there other things the harness could do before closing this issue as duplicate of medic/cht-conf#436?

@derickl
Copy link
Member

derickl commented Oct 4, 2021

Similar class of error #143. 'Note fields marked as required, will not advance in harness'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants