Validation Error When Editing app forms

Hi,
I’m having issues when trying to edit a custom ID variable in submitted reports.
This custom id is being loaded in calculated field using the following calculation instance(‘contact-summary’)/context/thisSubjid and works fine when the form is in the “add new record” mode.
When editing the form it is not able to load the context value so that I can compare it with current value.
Is there something that I need to do so this value to loaded in the edit mode?
As a result of this issue one is not able proceed to the next variable and therefore the form cannot be edited.
I would like this validation to done in both the add and edit modes of the app-form.
Thank you.
Erick

When editing the form

Just to clarify, by “editing” you mean actually updating an exiting report (via the “Reports” tab)?

If that is the case, then yes unfortunately I believe it is a known limitation that the contact-summary data is not visible in a form that is launched from the “Reports” tab. I believe this functionality is technically possible (when editing an existing report that is already associated with a contact), but has not been implemented yet.

Can you share more about your usecase/workflow? Why does the user need to come back and edit the report? What data is being loaded from the contact-summary? Do you expect that data to change over time (e.g. between when the report was submitted and when it was edited)? Details like this can help us understand the broader need/value of this functionality. Thanks!

[quote=“jkuester, post:2, topic:2526”]
Just to clarify, by “editing” you mean actually updating an exiting report (via the “Reports” tab)?
[/quote] Yes.
So we know from our experience that as result of data entry errors or omissions, we will flag errors on various reports and request the CHWs to make corrections on the already submitted data, which is accessible through the reports tab.
We have a unique participant/patient Id that will be entered for validating the selected participant/patient to ensure that correct person is selected (this is second check to avoid entries being made to wrong person).
This unique Id is being loaded from the contact-summary, we do expect it to change once its assigned and is compared with what the user has entered on the app form for validation purposes.
Let me know if this context is helpful.
Thank you.
Erick

1 Like

Thank you for the context! That makes sense.

we do expect it to change once its assigned

Sorry, but did you mean to say “we do not expect it to change”? (Your answer to my next question will probably help me understand why this value might change over time…)

Also, is the participant/patient_id only available on the contact-summary (is that where it is computed?) or does the value get set on the contact doc (e.g. the generate_shortcode_on_contacts Sentinel transition will set the value on the contact)? If the value is also on the contact, that does expand our options here.

If you can load the value from the contact doc, then you should be able to load it in the form using the contact selector functionality. I am thinking of a logic flow like this:

  • When adding a new report for the form (from the “People” tab with the target contact in context), set a patient_uuid calculate to the _id of the contact (available in inputs/contact)
  • Then, in the form, get the desired patient_id value using the contact selector to read the contact assoicated with the patient_uuid.
  • When editing an existing report, the contact selector should be able to properly load the patient_id from the existing contact because it will be referencing the existing patient_uuid value saved in the report.

Another alternative, if the patient_id does not actually change over time, would be to save the actual patient_id on the report. Then, when the user goes to edit the report, you can just check there input against the existing patient_id value.

1 Like

It is only available on the contact-summary and we do not expect it to change 99% of the time but their might some very few instances where this value might be edited by the system admin only. If we choose to set this value to be the patient_id, is it possible for us make changes to it?

I like the Idea of using this value as the patient_id since it can be auto-generated based on the household id.
Let me your thoughts about setting this value as the patient_id.
Thank you.
Erick

I forgot to mention that I’m indeed saving the actual patient_id on the report and for some reason this is not working, when editing the report the constraint fails.
Here is the unique participant/patient_id saved on my report (psubjid:“SP31464003-2”) and here is my constraint on the form (. = ${psubjid}).
This works fine in the add mode but its not working in the edit mode.
Thank you.
Erick

Let me your thoughts about setting this value as the patient_id.

If you are already using a different value as the patient_id, it seems unnecessary to switch that up just to solve this problem (especially since you are already saving psubjid on the report). Though, broadly speaking, it might be worth at some point evaluating if both fields are necessary, or if they could be combined (and simplify the data model a bit).

the unique participant/patient_id saved on my report (psubjid:“SP31464003-2”) and here is my constraint on the form (. = ${psubjid}).
This works fine in the add mode but its not working in the edit mode.

This is where things get interesting! So, I am assuming that when adding a report, the psubjid is getting set from the value in the contact-summary. The question is, what happens to that field when you edit the report? Can you try printing the value in a note field in the report just to see what it is when the form is actually open? I am wondering if the value is getting removed from the field when you edit the report because the contact-summary is not available…

If that is the case and the value is there when adding but the psubjid field is getting cleared when editing the report, I think you can just tweak the calculation for that field to use coalesce.

coalesce(instance(‘contact-summary’)/context/thisSubjid, .)

That should use the value from the contact-summary by default, but if one is not found it will just keep any existing value set for the field.

Thank you @jkuester,
I’ve a workaround for this now.
I think what is was happening when the form is loaded in the edit mode, instance(‘contact-summary’)/context/thisSubjid, this calculation is not returning any value and this is being replicated across all variables that depend on it. so what I have done is to try check if it is defined or has a value using the following calculation if(string-length(${psubjid})=0, ., ${psubjid})
This now works fine in both add and edit mode, but I’ll revert to using this ```
coalesce(instance(‘contact-summary’)/context/thisSubjid, .)

1 Like

I’ve confirmed, it has no value.
Thank you.

1 Like