OpenClinica / enketo-oc

OpenClinica's fork of the Enketo web forms monorepo
Apache License 2.0
0 stars 1 forks source link

Opening a form to a specific query thread on a non-last page for an item brings user to the following page of the form, not the requested query #36

Open Apotischman opened 1 year ago

Apotischman commented 1 year ago

Describe the bug If a form has more than 1 page, where any of the pages (except the last page) has a query, and the user tries to "view query within form", they are brought to the last page of the form instead of the location where the active query is.

To Reproduce Use the attached XForm. Add a query to the first item Open a form to a specific query thread You are brought to the last page of the form, not the page where the query exists

query_issue.txt

*

MartijnR commented 1 year ago

regular form: http://localhost:8005/single/fs/i/QcnTqhg0?ecid=a

regular question when editing record (no issue):

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=query_issue&ecid=a&go_to=/data/Extra/Q1&instance=<data><Extra><Q1>bla</Q1></Extra></daa>&instance_id=aa" http://localhost:8005/oc/api/v1/instance/edit 

dn for question when editing a record (also no issue):

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=query_issue&ecid=a&go_to=/data/Extra/Q1_comment&instance=<data><Extra><Q1>bla</Q1></Extra></data>&instance_id=aa" http://localhost:8005/oc/api/v1/instance/edit
MartijnR commented 1 year ago

This issue may have something to do with how enketo's API is used.

@Apotischman, can you please share the URL of the Enketo form? I'm interested in the hash (#) part of the URL. It should be #%2Fdata%2FExtra%2FQ1_comment (or #%2F%2FQ1_comment), for the query on the last question, but you probably see something else.

Update: it might be related to going to a specific query thread.

pbowen-oc commented 1 year ago

@MartijnR - Our URLs for accessing a specific query thread have parameters like this:

%2F%2Fpulse_comment%23e5da1ea2-6fd5-43e0-8eba-dc4c9a210d65

MartijnR commented 1 year ago

with thread id, single page form (cannot reproduce issue):

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=query_issue&ecid=a&go_to=/data/Extra/Q1&instance=<data><Extra><Q1>bla</Q1></Extra></daa>&instance_id=aa" http://localhost:8005/oc/api/v1/instance/edit 

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=language.test&ecid=a&instance=\
<data xmlns:OpenClinica=\"http://openclinica.com/odm\" xmlns:enk=\"http://enketo.org/xforms\" xmlns:jr=\"http://openrosa.org/javarosa\" xmlns:oc=\"http://openclinica.org/xforms\" xmlns:orx=\"http://openrosa.org/xforms\" id=\"language.test\" version=\"1\">\
<page1><locale_note/><yn1/><locale_note_comment oc:queryParent=\"locale_note\"/><yn1_comment oc:queryParent=\"yn1\">{\"queries\":[{\"type\":\"comment\",\"id\":\"1\",\"date_time\":\"2023-01-18 11:34:36.608 -05:00\",\"comment\":\"df\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"b\"},{\"type\":\"comment\",\"id\":\"2\",\"date_time\":\"2023-01-19 11:34:36.608 -05:00\",\"comment\":\"abc\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"a\"} ]}</yn1_comment></page1>\
<meta><instanceID>uuid:e1623dbf-bf87-4b2a-8a5a-85ae832f31f3</instanceID></meta></data>\
&instance_id=123&go_to=/data/page1/yn1_comment#a" http://localhost:8005/oc/api/v1/instance/edit

with thread_id, multi page form (can reproduce):

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=query_issue&ecid=a&go_to=/data/VS/VSHR_comment#a&instance=<data><VS><VSHR></VSHR><VSHR_comment>{\"queries\":[{\"type\":\"comment\",\"id\":\"1\",\"date_time\":\"2023-01-18 11:34:36.608 -05:00\",\"comment\":\"df\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"b\"},{\"type\":\"comment\",\"id\":\"2\",\"date_time\":\"2023-01-19 11:34:36.608 -05:00\",\"comment\":\"abc\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"a\"} ]}</VSHR_comment></VS><Extra><Q1>bla</Q1><Q1_comment></Q1_comment></Extra></data>&instance_id=aa" http://localhost:8005/oc/api/v1/instance/edit

just going to the query without a thread (same issue):

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=query_issue&ecid=a&go_to=/data/VS/VSHR_comment&instance=<data><VS><VSHR></VSHR><VSHR_comment>{\"queries\":[{\"type\":\"comment\",\"id\":\"1\",\"date_time\":\"2023-01-18 11:34:36.608 -05:00\",\"comment\":\"df\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"b\"},{\"type\":\"comment\",\"id\":\"2\",\"date_time\":\"2023-01-19 11:34:36.608 -05:00\",\"comment\":\"abc\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"a\"} ]}</VSHR_comment></VS><Extra><Q1>bla</Q1><Q1_comment></Q1_comment></Extra></data>&instance_id=aa" http://localhost:8005/oc/api/v1/instance/edit

just going to the question itself (same issue, when loading a record):

curl --user enketorules: -d "server_url=http://localhost:3000&form_id=query_issue&ecid=a&go_to=/data/VS/VSHR&instance=<data><VS><VSHR></VSHR><VSHR_comment>{\"queries\":[{\"type\":\"comment\",\"id\":\"1\",\"date_time\":\"2023-01-18 11:34:36.608 -05:00\",\"comment\":\"df\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"b\"},{\"type\":\"comment\",\"id\":\"2\",\"date_time\":\"2023-01-19 11:34:36.608 -05:00\",\"comment\":\"abc\",\"status\":\"new\",\"assigned_to\":\"\",\"notify\":false,\"thread_id\":\"a\"} ]}</VSHR_comment></VS><Extra><Q1>bla</Q1><Q1_comment></Q1_comment></Extra></data>&instance_id=aa" http://localhost:8005/oc/api/v1/instance/edit
MartijnR commented 1 year ago

I cannot reproduce the issue. Going to a specific thread works with the provided form (for Q1_comment).

MartijnR commented 1 year ago

I suspect this is because the page.next() function is called which has some asynchronous actions. After correctly going to the right question, the next() gets completed and goes to the wrong page.

Yes, the pages._setBranchHandler function (in Enketo Core) calls the next function. A branchChange (in Enketo Core) triggers the event in this handler.