# Find Patients to Merge throws SQLException

**URL:** <https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822>\
**Category:** GSoC\
**Created:** [June 20, 2021, 10:08am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822 "2021-06-20T10:08:41Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![navareth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/navareth/32/14224_2.png) [@navareth](https://talk.openmrs.org/u/navareth)\
**Post date:** [June 20, 2021, 10:08am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/1 "2021-06-20T10:08:41Z")

</div>

I wanted to expose “Find Patients to Merge” functionality through REST API as part of my GSoC 2021 task.

First I wanted to try out the existing UI. However, when selecting one of these 3 fields: Given, Middle, Family Name, I receive the following SQL Exception:

> **[ERROR - SqlExceptionHelper.logExceptions(142) |2021-06-20T12:03:51,081|...](https://pastebin.com/XUgsdGWg)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

I’m running OpenMRS server version: 2.4.0 Build e4adbd

---

<div class="post-metadata">

**Author:** ![navareth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/navareth/32/14224_2.png) [@navareth](https://talk.openmrs.org/u/navareth)\
**Post date:** [June 20, 2021, 10:19am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/2 "2021-06-20T10:19:48Z")

</div>

I’ve been able to reproduce the issue with [https://qa-refapp.openmrs.org/](https://qa-refapp.openmrs.org/)

> **[ERROR - SqlExceptionHelper.logExceptions(142) |2021-06-20T10:19:03,963|...](https://pastebin.com/tZFQG9Hd)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

**Author:** ![kdaud](https://talk.openmrs.org/user_avatar/talk.openmrs.org/kdaud/32/13346_2.png) [@kdaud](https://talk.openmrs.org/u/kdaud)\
**Post date:** [June 21, 2021, 9:18am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/3 "2021-06-21T09:18:27Z")

</div>

> [@navareth](#):
>
> However, when selecting one of these 3 fields: Given, Middle, Family Name, I receive the following SQL Exception:

You may need to take a look at [this](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/MergePatientTest.java) and [this](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/RecordMergeIssueTest.java)

> [@navareth](#):
>
> I’m running OpenMRS server version: 2.4.0 Build e4adbd

Am skeptical about the version you are consuming !! @sharif @herbert24 @jwnasambu do we have this version already for use ?

---

<div class="post-metadata">

**Author:** ![herbert24](https://talk.openmrs.org/user_avatar/talk.openmrs.org/herbert24/32/8178_2.png) [@herbert24](https://talk.openmrs.org/u/herbert24)\
**Post date:** [June 21, 2021, 9:20am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/4 "2021-06-21T09:20:13Z")

</div>

> [@navareth](#):
>
> OpenMRS server version: 2.4.0

the latest version of core is 2.4.0

---

<div class="post-metadata">

**Author:** ![kdaud](https://talk.openmrs.org/user_avatar/talk.openmrs.org/kdaud/32/13346_2.png) [@kdaud](https://talk.openmrs.org/u/kdaud)\
**Post date:** [June 21, 2021, 9:22am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/5 "2021-06-21T09:22:15Z")

</div>

> [@herbert24](#):
>
> the latest version of core is 2.4.0

Is it recommended for use Or still a `SNAPSHOT` ?

---

<div class="post-metadata">

**Author:** ![herbert24](https://talk.openmrs.org/user_avatar/talk.openmrs.org/herbert24/32/8178_2.png) [@herbert24](https://talk.openmrs.org/u/herbert24)\
**Post date:** [June 21, 2021, 9:23am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/6 "2021-06-21T09:23:28Z")

</div>

the snapshot is 2.5.0

---

<div class="post-metadata">

**Author:** ![navareth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/navareth/32/14224_2.png) [@navareth](https://talk.openmrs.org/u/navareth)\
**Post date:** [June 22, 2021, 3:05pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/7 "2021-06-22T15:05:24Z")

</div>

> [@kdaud](#):
>
> You may need to take a look at [this](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/MergePatientTest.java) and [this](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/RecordMergeIssueTest.java)

I’m not sure how that explains the issue with “Find Patients to Merge” which is occurring on build 2.4.0

These two links point to code that tests the merging process, not finding patients to be merged 🙂

I’m talking about this page: [https://qa-refapp.openmrs.org/openmrs/admin/patients/findDuplicatePatients.htm](https://qa-refapp.openmrs.org/openmrs/admin/patients/findDuplicatePatients.htm)

cc: @dkayiwa @gcliff

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [June 22, 2021, 9:02pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/8 "2021-06-22T21:02:53Z")

</div>

@kdaud does it mean that the existing automated tests did not catch this?

---

<div class="post-metadata">

**Author:** ![kdaud](https://talk.openmrs.org/user_avatar/talk.openmrs.org/kdaud/32/13346_2.png) [@kdaud](https://talk.openmrs.org/u/kdaud)\
**Post date:** [June 23, 2021, 4:53am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/9 "2021-06-23T04:53:15Z")

</div>

> [@dkayiwa](#):
>
> does it mean that the existing automated tests did not catch this?

We have an automated [test](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/MergePatientTest.java) that captures patient merge, one has to ensure that there exists two patient data set in the `db instance` for the action to be effective. Ideally the better way would be creating your own patient data than relying on the existing data within the `server` and then perform the action.

But if the test am pointing out does not capture @navareth use case, then we can have it automated if more light is thrown on the idea behind the use case.   
cc: @sharif

---

<div class="post-metadata">

**Author:** ![navareth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/navareth/32/14224_2.png) [@navareth](https://talk.openmrs.org/u/navareth)\
**Post date:** [June 23, 2021, 4:44pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/10 "2021-06-23T16:44:44Z")

</div>

The tests you are talking about don’t test use cases when a user wants to find mergeable patients based on their attributes (names specifically).

I know it’s not possible in the new UI, however we could do that through LegacyUI at : [https://qa-refapp.openmrs.org/openmrs/admin/patients/findDuplicatePatients.htm](https://qa-refapp.openmrs.org/openmrs/admin/patients/findDuplicatePatients.htm)

---

<div class="post-metadata">

**Author:** ![kdaud](https://talk.openmrs.org/user_avatar/talk.openmrs.org/kdaud/32/13346_2.png) [@kdaud](https://talk.openmrs.org/u/kdaud)\
**Post date:** [June 23, 2021, 4:51pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/11 "2021-06-23T16:51:53Z")

</div>

> [@navareth](#):
>
> The tests you are talking about don’t test use cases when a user wants to find mergeable patients based on their attributes (names specifically).

cc: @k.joseph @sharif

---

<div class="post-metadata">

**Author:** ![k.joseph](https://talk.openmrs.org/user_avatar/talk.openmrs.org/k.joseph/32/8097_2.png) [@k.joseph](https://talk.openmrs.org/u/k.joseph)\
**Post date:** [June 23, 2021, 5:06pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/12 "2021-06-23T17:06:06Z")

</div>

There’s a way to search for patients in ref app 2.x and selecting the first and second inputs the first and second patient ids automatically and this works perfectly at [https://qa-refapp.openmrs.org/](https://qa-refapp.openmrs.org/). The legacy ui doesn’t perhaps support finding patients by name, it relies on knowing the patient ids, please go ahead and create a ticket for this @navareth in [https://issues.openmrs.org/projects/LUI/issues](https://issues.openmrs.org/projects/LUI/issues) and if you have time and desperately need this work on it.

The [automated test](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/MergePatientTest.java) doesn’t use the search option in ref app 2.x, @grace @christine can we can this feature in one of our workflows and include the search for patient in that instead?

---

<div class="post-metadata">

**Author:** ![sharif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/sharif/32/11982_2.png) [@sharif](https://talk.openmrs.org/u/sharif)\
**Post date:** [June 23, 2021, 6:14pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/13 "2021-06-23T18:14:02Z")

</div>

> [@k.joseph](#):
>
> please go ahead and create a ticket for this @navareth in [Dashboard - OpenMRS Issues](https://issues.openmrs.org/projects/LUI/issues) and if you have time and desperately need this work on it.

@navareth thanks for the catch, Feel free to let us know incase of help or resolvng the issue because we might as well need to automate it ,

---

<div class="post-metadata">

**Author:** ![navareth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/navareth/32/14224_2.png) [@navareth](https://talk.openmrs.org/u/navareth)\
**Post date:** [June 23, 2021, 9:54pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/14 "2021-06-23T21:54:35Z")

</div>

> [@k.joseph](#):
>
> The legacy ui doesn’t perhaps support finding patients by name, it relies on knowing the patient ids, please go ahead and create a ticket for this @navareth in [Dashboard - OpenMRS Issues](https://issues.openmrs.org/projects/LUI/issues) and if you have time and desperately need this work on it.

The legacy UI does support finding patients by name, however, the core webapp throws an exception when trying to do so. That’s why I think creating an issue in the TRUNK project makes more sense.

[https://issues.openmrs.org/browse/TRUNK-6008](https://issues.openmrs.org/browse/TRUNK-6008)

Apart from that, we could create an issue for adding a refapp test that will use the search options, on the merging page.

---

<div class="post-metadata">

**Author:** ![grace](https://talk.openmrs.org/user_avatar/talk.openmrs.org/grace/32/16942_2.png) [@grace](https://talk.openmrs.org/u/grace)\
**Post date:** [June 26, 2021, 12:17am UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/15 "2021-06-26T00:17:56Z")

</div>

> [@k.joseph](#):
>
> The [automated test](https://github.com/openmrs/openmrs-distro-referenceapplication/blob/master/ui-tests/src/test/java/org/openmrs/reference/MergePatientTest.java) doesn’t use the search option in ref app 2.x, @grace @christine can we can this feature in one of our workflows and include the search for patient in that instead?

Good catch Kaweesi. @christine can you update the workflow test tickets accordingly?

---

<div class="post-metadata">

**Author:** ![navareth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/navareth/32/14224_2.png) [@navareth](https://talk.openmrs.org/u/navareth)\
**Post date:** [June 26, 2021, 1:37pm UTC](https://talk.openmrs.org/t/find-patients-to-merge-throws-sqlexception/33822/16 "2021-06-26T13:37:39Z")

</div>

I’ve posted a PR with a fix for the issue above: [https://github.com/openmrs/openmrs-core/pull/3810](https://github.com/openmrs/openmrs-core/pull/3810)
