Skip to content

Commit

Permalink
Merge pull request #1364 from TIP-Global-Health/sync-incident-auto-re…
Browse files Browse the repository at this point in the history
…covery-fix-01

Sync incident auto recovery - fix 01
  • Loading branch information
anvmn authored Oct 21, 2024
2 parents added61 + edcf4b7 commit 01d4cdf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
36 changes: 29 additions & 7 deletions client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,28 +1057,50 @@ elmApp.ports.askFromIndexDb.subscribe(function(info) {

let entities = [result[0]];

// If resolved entity is an encounter, we need to check if the
// participant it refers to is also missing from shardChanges table.
// If resolved entity is an encounter, we fetch the
// participant it refers to.
if (entities[0].type.endsWith('_encounter')) {
// Encounter was resolved. Now resolving participant.
let uuid = entities[0].individual_participant;
result = await dbSync
.shardChanges
.shards
.where('uuid')
.equals(uuid)
.limit(1)
.toArray();

if (!result[0]) {
// Entity not present in shardChanges chages table, so
// we try to resolve it from shard table.
let participant = result[0];
if (participant) {
entities.push(participant);

// Participant was resolved. Now resolving person.
uuid = participant.person;
result = await dbSync
.shards
.where('uuid')
.equals(uuid)
.limit(1)
.toArray();

entities.push(result[0]);
let person = result[0];
if (person) {
entities.push(person);
}
}
}
else if (entities[0].type == 'individual_participant') {
// Participant was resolved. Now resolving person.
let uuid = entities[0].person;
result = await dbSync
.shards
.where('uuid')
.equals(uuid)
.limit(1)
.toArray();

let person = result[0];
if (person) {
entities.push(person);
}
}

Expand Down
10 changes: 9 additions & 1 deletion server/hedley/modules/custom/hedley_user/hedley_user.module
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ function hedley_user_user_presave(&$edit, $account, $category) {
return;
}

$entities_data = array_reverse(json_decode($edit['field_incident_details'][LANGUAGE_NONE][0]['value']));
$decoded = json_decode($edit['field_incident_details'][LANGUAGE_NONE][0]['value']);
$entities_data = array_reverse($decoded);
foreach ($entities_data as $data) {
$nid = hedley_restful_resolve_nid_for_uuid($data->uuid);
if ($nid !== FALSE) {
// Node with provided UUID is found, which indicates that
// content exists already on back-end, and can be skipped.
continue;
}

$bundle = $data->type;
$function = "hedley_user_create_{$bundle}_by_sync_incident";
if (function_exists($function)) {
Expand Down

0 comments on commit 01d4cdf

Please sign in to comment.