avniproject/LAHI

[LAHI SUPPORT] Ticket 2474

Closed this issue · 4 comments

https://avni.freshdesk.com/a/tickets/2474

Corresponding product bug card - https://app.zenhub.com/workspaces/avni-product-635b73bded85e50018871ae6/issues/gh/avniproject/avni-client/914

-- 317
-- 325
-- 1085

// Currently above are assigned to user "alims@lahi" with id = 5904;

set role lahi;
update user_subject_assignment
set is_voided = true,
last_modified_date_time = current_timestamp,
last_modified_by_id = (select id from users where username = 'taqi@lahi')
where id = 1085;

  • WRITE A SCRIPT TO DELETE ALL THE DATA RELEVANT TO A VOIDED PROGRAM

  • REVERT THE SUBJECT ASSIGNMENT CHANGE

Analysis Notes:

-- The encounter for which sync fails, which is already voided, its related to program_enrolment_id = 255647 and encounter_type = 1810
select * from program_encounter where uuid = '988cc628-44fe-4ea2-b485-d2624cdcf5de';

-- Its mapped to encounter_type which is not voided
select * from encounter_type where id = 1810;

-- Its mapped to program_enrolment which is also voided, its related to program_id = 564
select * from program_enrolment where id = 255647;

-- This is mapped to a voided program "Karigar" which is also voided
select * from program where id = 564;

-- This Program has only voided form_mappings
select * from form_mapping join form f on form_mapping.form_id = f.id where entity_id = 564 and f.form_type = 'ProgramEnrolment' and form_mapping.is_voided = true;

-- Based on above data, the encounter should not have been attempted to sync as its related program's form_mapping is voided.
-- But, the issue is caused due to re-use of the same encounter_type for 2 different programs (564, 613),
-- Program with id 613 has 2 non-voided entries that map to forms with id in (5289, 5290)
select * from form_mapping where entity_id in (564, 613) and observations_type_entity_id = 1810;

-- The program "Karigar" which is not voided
select * from program where id = 613;

-- There are forms corresponding to the
select * from form where id in (5289, 5290);

-- Because of the below 2 non-voided form-mappings with observations_type_entity_id = 1810,
-- during sync we attempt to sync encounters that belong to encounter_type_id = 1810, uuid = 3acfc167-0124-4292-8c66-8fdb3e34ef95
select * from form_mapping where entity_id in (564, 613) and observations_type_entity_id = 1810;
select * from encounter_type where id = 1810;

-- DEBUG [2:32:31:250] [Requests][Debug] GET: https://server.avniproject.org/programEncounter?programEncounterTypeUuid=3acfc167-0124-4292-8c66-8fdb3e34ef95&lastModifiedDateTime=1900-01-01T00:00:00.000Z&now=2023-04-11T09:05:40.087Z&size=100&page=0
-- INFO [2:32:31:251] [AuthService][Info] Found token
-- ERROR SyncComponent-Sync ProgramEncounter{uuid='988cc628-44fe-4ea2-b485-d2624cdcf5de'} is unable to find
-- ProgramEnrolment{uuid='23f4b86b-514b-48d8-98cb-554450ca930b'}, {"errorCode":"Association error 10","errorText":"ProgramEncounter{uuid='988cc628-44fe-4ea2-b485-d2624cdcf5de'}
-- is unable to find ProgramEnrolment{uuid='23f4b86b-514b-48d8-98cb-554450ca930b'}","line":118433,"column":29,
-- "sourceURL":"http://localhost:8081/index.android.bundle?platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true"}

-- At this point we return to the encounter for which sync fails, which is already voided,
-- its related to encounter_type = 1810 and program = 564 and not program = 613.
-- While our intention is to get encounters of type encounter_type = 1810 and program = 613,
-- which is not factored in, due to missing program filter program_id = 613 and not program_id = 564.
select * from program_encounter where uuid = '988cc628-44fe-4ea2-b485-d2624cdcf5de';

Analysis Conclusion:

  • As, we do not have capability to include relatedEntityType and relatedEntityTypeUUID information while creating SyncableItem, we'll not be able to provide additional information to client, to make it request for ProgramEncounters of specific Program for given encounterTypeUUID.
    public class SyncableItem {
    private String name;
    private String entityTypeUuid;
    }
  • Therefore, the only recourse to correct this issue, is to delete the transactional data related to the voided ProgramEncounters and ProgramEnrolments and then attempt fresh sync.
  • WRITE A SCRIPT TO DELETE ALL THE DATA RELEVANT TO A VOIDED PROGRAM
    -- select * from program_encounter pe join program_enrolment enr on pe.program_enrolment_id = enr.id
    join program p on enr.program_id = p.id where enr.is_voided = true and p.is_voided= true;
    -- delete from program_encounter where uuid in ();

  • REVERT THE SUBJECT ASSIGNMENT CHANGE
    -- update user_subject_assignment
    set is_voided = false,
    last_modified_date_time = current_timestamp,
    last_modified_by_id = 5912
    where id in (317, 325, 1085);

arjunk commented

@himeshr @nupoorkhandelwal @utkarshavni any idea if anything is remaining on this card or should i mark it as closed?

There was no action pending on this, there were multiple cards related to the ticket, must have missed out closing this card.