-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add support for event instances #56
base: develop
Are you sure you want to change the base?
Add support for event instances #56
Conversation
Unfortunately, this results in APF not working across events or in repeat instances of the same event when using the XML in this comment: #24 (comment), which does use "Repeat Entire Event" |
Strange, that's the XML I used for testing. |
In the existing record 1, I went to the Baseline Data form in Visit 1 (event3), without this PR active the fields should populate. I also spawned a new instance for the Baseline Data form in Dose 1 (event2) and the fields did not autopopulate there either. |
ExternalModule.php
Outdated
$prev_event_field_value = $data[$prev_event][$source_field]; | ||
if (isset($prev_event_field_value) && !empty($prev_event_field_value)) { | ||
$default_value = $prev_event_field_value; | ||
} elseif ($data['repeat_instances'][$prev_event][$source_form]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is the source of the breakage for cross-event autopopulation, passing $source_form
instead of ""
results in null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same results, though that gets a little funky with imported data (timestamps for data entry are all the same when you do an upload), to really test it you've got to make a new record.
I just did that and results are still the same though.
I think you've fixed this for individual instruments repeating at the loss of entire event support. If we're lucky, there might be a way to detect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize I had that enabled when testing. When that setting is enabled both event instances and "Repeat entire event" are handled the same.
I think the best option is to determine x
in $data[$prev_event][x]
on whether the event is an event instance or not. Do you know of a better way than $_GET['instance'] > 1
to check if the current event is an event instance?
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's the easiest way to do it actually. There is a something (I'm blanking on the name, possibly part of the $Proj
object) that tracks all repeating forms if the $_GET
alone doesn't cut it.
Cross-event population is working again, but cross-instance population is still failing. In cross-instance, the |
ExternalModule.php
Outdated
// Event instances share the same event id for every instance. | ||
// To support event instances we only break on the first instance, and allow execution for all future instances i.e., $_GET['instance'] greater than 1. | ||
// Event instances are enabled under: Project Setup > Enable optional modules and customizations > Repeatable instruments and events > 'Repeat instruments (repeat independently of each other)` | ||
if ($event == $_GET['event_id'] && $_GET['instance'] == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the cause of the event-id mismatch in cross-instance population. The bug I'm seeing results from this foreach
running to the end of the $events
, resulting the final event being set as $prev_event
87244a0
to
831ba09
Compare
831ba09
to
5a1933e
Compare
ExternalModule.php
Outdated
* Returns true if the event is a "Repeat Entire Event (repeat all instruments together)". | ||
*/ | ||
function isRepeatEntireEvent() { | ||
if ($_GET['instance'] > 1 && isset($_GET['oldinstance'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, but still having some inconsistency. When creating the second instance of a repeat event (repeat entire event), the fields don't autopopulate with the prior event. I think this line is the cause
When I create the 2nd instance of an event on a new record there is no oldinstance
param, so this condition doesn't fire. The third instance (and probably onward) works as expected.
To recreate
- Start a new record, fill in values for events 1 and 2.
- Observe the initial instance of event 3 will autopopulate with event 2 info.
- Create a new instance of event 3, observe that data does not autopopulate
- Fill in some info here, save and create a 3rd instance; observe that the 3rd instance does autopopulate from the 2nd.
Would love to test once working :) |
Can you elaborate on:
The expected behavior with chronological events disabled :
|
I have the chronological detection disabled. Newest REDCap version. Sometimes it populates from the previous instance of the event, sometimes it doesn't populate anything. Haven't found a pattern. What I did notice though is that when you have filled instances, then some empty instances and then a filled instance, it will populate the empty instance with the most recent instance and not with the filled instance immediately before the emepty instance. This shouldn't be happening. |
Just to make sure REDCap version 11.2.2? What you describe:
is the expected behavior of scenario 2. The instance will only look at the immediate previous saved event, regardless of whether it contains non-empty values or not. Given this scenario:
instance 3 will grab the empty values from instance 2 because it is the previous saved event. It contains values, they just happen to be empty strings or other null values. |
yes
in that case it would be good to have an option. for our use case we always want to populate from the last filled instance to the left of the instance to be populated.
that's interesting. that might explain why I'm seeing that it sometimes works and sometimes doesn't SEEM to work. |
@mschulze0 it sounds like you want autofill with last spatial filled event/instance, enabling chronological previous event population should give you your expected behavior. If your responses come in out of order you might be able to hack this "fall through until found" behavior with an auxiliary hidden field, |
ExternalModule.php
Outdated
return true; | ||
} | ||
return false; | ||
return $GLOBALS['isRepeatingForm']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm this sounds very convoluted for something that should be easy. |
79eeb8c
to
af7260d
Compare
af7260d
to
0661885
Compare
// The object returned by $instances = $data['repeat_instances'][$event] changes dependening on if the data is from an event or a form. | ||
// For repeating events, the key for $instances is an empty string ("") i.e., ["": ...] | ||
// For repeating forms, the key for $instances is the form name i.e., ["baseline_data": ...] | ||
$instances = ($data['repeat_instances'][$prev_event][$source_form]) ?? ($data['repeat_instances'][$prev_event][""]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I didn't know about the ??
operator. We'll need to bump the minimum PHP version to 7 in the config.json
.
Somewhere in that last commit APF was broken when filling forms in out of order. To recreate:
As an aside, make sure that you test surveys as well. Really this module begs for an automated testing suite. This is probably a great module to try out making a test with REDCap Cypress. |
I realize that part of the back-forth is not having all scenarios documented. Are there any scenarios missing? @ChemiKyle Project XML: APF.zip Testing Scenarios (chronological event detection OFF):
Testing scenarios (chronological event detection ON):
Aside: The changes also fix #57 |
Hi @mbentz-uf @ChemiKyle
|
any news on this? |
@mschulze0 Michael is on paternity leave until some time in October, we have a lot of COVID related work keeping us busy, if there is a lull I may have time to polish this but I don't expect much movement until October at the earliest. |
@ChemiKyle thanks for the update! |
Fix #54