From e0d882015f82a015e51fd11a3086f6c4d0c5c64a Mon Sep 17 00:00:00 2001 From: anvmn Date: Mon, 21 Oct 2024 15:28:37 +0300 Subject: [PATCH 1/2] Alter logic to pull all referencing entities --- client/src/js/app.js | 36 +++++++++++++++---- .../custom/hedley_user/hedley_user.module | 10 +++++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/client/src/js/app.js b/client/src/js/app.js index de3157a236..49d0b16695 100644 --- a/client/src/js/app.js +++ b/client/src/js/app.js @@ -1057,20 +1057,24 @@ 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') @@ -1078,7 +1082,25 @@ elmApp.ports.askFromIndexDb.subscribe(function(info) { .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); } } diff --git a/server/hedley/modules/custom/hedley_user/hedley_user.module b/server/hedley/modules/custom/hedley_user/hedley_user.module index 85ee5a5e71..d849a8f303 100644 --- a/server/hedley/modules/custom/hedley_user/hedley_user.module +++ b/server/hedley/modules/custom/hedley_user/hedley_user.module @@ -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'], TRUE); + $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)) { From edcf4b78f8f590e25af6256a95f3cd9135d26ac8 Mon Sep 17 00:00:00 2001 From: anvmn Date: Mon, 21 Oct 2024 16:22:14 +0300 Subject: [PATCH 2/2] A fix --- server/hedley/modules/custom/hedley_user/hedley_user.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/hedley/modules/custom/hedley_user/hedley_user.module b/server/hedley/modules/custom/hedley_user/hedley_user.module index d849a8f303..38e2195395 100644 --- a/server/hedley/modules/custom/hedley_user/hedley_user.module +++ b/server/hedley/modules/custom/hedley_user/hedley_user.module @@ -54,7 +54,7 @@ function hedley_user_user_presave(&$edit, $account, $category) { return; } - $decoded = json_decode($edit['field_incident_details'][LANGUAGE_NONE][0]['value'], TRUE); + $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);