[bug bahmni 0.92] Patient duplicated on the clinical queue: happening for a patient that has been merged

Steps to replicate the bug (this can be done on the bahmni demo environment as well: https://demo.mybahmni.org/)

1 - Create 2 patients with very similar names without starting a visit for both patients

2 - Merge the 2 patients in openmrs

3 - Start a new OPD visit with the remaining patient; the clinical module queue now displays 4 entries: 2 entries for each of the patients previously created.

Expected outcome: only one entry should be displayed; the second patient (id: BAH205283) that was merged into the first should not be displayed anymore.

I am not sure if this issue has been resolved in 0.93, or if there is a ticket or perhaps an open PR for this?

cc: @gsluthra @angshuonline

Seems to be an open ticket: [BAH-1236] All patients involved in a merge are being displayed under the Active tab of the Clinical module - Bahmni - JIRA. Plz check if this is same.

Thanks @gsluthra; we have temporarily resolved this issue by updating the SQL query in the global property emrapi.sqlSearch.activePatients (https://[host]/openmrs/admin/maintenance/globalProps.form). We have added new conditions to the joins to use only person_name and patient_identifier records where the flag preferred is true.

Note: when patients are merged, only one patient is maintained and the other records are ‘soft-deleted’ (i.e. the flags “voided” is set to 1 and “preferred” is set to 0). The list of active patients is showing duplicates because the corresponding SQL query does not exclude non-preferred patient_identifier records.

select distinct concat(pn.given_name," ", ifnull(pn.family_name,'')) as name,
      pn.given_name as givenName,
      pn.family_name as familyName,
      pi.identifier as identifier,
      concat("",p.uuid) as uuid,
      concat("",v.uuid) as activeVisitUuid,
      IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted
 from
      visit v join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 and v.voided=0  and pn.preferred = 1
      join patient_identifier pi on v.patient_id = pi.patient_id and pi.voided=0 and pi.preferred = 1
      join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id
      join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid
      join person p on p.person_id = v.patient_id and p.voided=0
      join encounter en on en.visit_id = v.visit_id and en.voided=0
      join location loc on loc.uuid = ${location_uuid}
      join obs o on o.encounter_id = en.encounter_id and o.voided=0 and o.value_coded=(select concept_id from concept_name where name=loc.name limit 1)
      left outer join visit_attribute va on va.visit_id = v.visit_id and va.attribute_type_id = (
          select visit_attribute_type_id from visit_attribute_type where name="Admission Status")
where
      v.date_stopped is null
order by en.encounter_datetime desc;
1 Like

Hello @tmvumbi . We have fixed this behaviour for the Active tab . This is the PR for the same BAH-1236 | Bug fix. Modified query to display only preferred patients… by SooryaKumaranC-tw · Pull Request #110 · Bahmni/bahmni-core · GitHub. We will be fixing the behaviour for the other tabs as well.

1 Like

great, thanks @abhinab for the heads up :ok_hand: