# Bahmni Connect: how to setup the LocationBasedSyncStrategy?

**URL:** <https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867>\
**Category:** Bahmni\
**Tags:** bahmni-connect\
**Created:** [October 25, 2017, 1:41pm UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867 "2017-10-25T13:41:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mksrom](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksrom/32/20221_2.png) [@mksrom](https://talk.openmrs.org/u/mksrom)\
**Post date:** [October 25, 2017, 1:41pm UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867/1 "2017-10-25T13:41:23Z")

</div>

Hi guys!

Trying to set up Bahmni Connect with Location based sync strategy.

But I get the following error: _[Please give address for this login location in openmrs]_

 ![address to login location](https://talk.openmrs.org/uploads/default/original/2X/6/6a7fe485c95056169b8380c62820334101d48c62.png)

My login location is **Subcenter 1 (BAM)** and I have set an address to it:

 ![subcenter 1 BAM](https://talk.openmrs.org/uploads/default/original/2X/b/ba1d838f260e2173e487689dc374f8b7749a90e1.png)

![login screen](https://talk.openmrs.org/uploads/default/original/2X/1/161b5317b1b2b7f7999bf8974eda39c1c585f151.png)

Any idea what additional steps I forgot to perform?

---

<div class="post-metadata">

**Author:** ![mksrom](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksrom/32/20221_2.png) [@mksrom](https://talk.openmrs.org/u/mksrom)\
**Post date:** [October 27, 2017, 9:00am UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867/2 "2017-10-27T09:00:47Z")

</div>

Thanks @shashikanth for the explanation during the call yesterday.

Could you reply to this post and explain what you explained to me yesterday? (I haven’t found any documentation about this so let’s at least write that down here.)

We will then need to update the wiki as well.

---

<div class="post-metadata">

**Author:** ![shashikanth](https://talk.openmrs.org/user_avatar/talk.openmrs.org/shashikanth/32/4533_2.png) [@shashikanth](https://talk.openmrs.org/u/shashikanth)\
**Post date:** [November 3, 2017, 9:37am UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867/3 "2017-11-03T09:37:13Z")

</div>

Hi All,

Bahmni Connect when setup with Location based sync strategy will not work by default unless, there are unique IDs for each address hierarchy entry in the OpenMRS database.

By Unique IDs I mean, in the `address_hierarchy_entry` table, each entry should have a `user_generated_id` column filled. This setup will not work if the `user_generated_id` column is null for the address entries. Based on the loggedIn location, this unique ID will be used as a filter to sync the patient data to the connect device.

Usually, the IDs are more like a PINCODE format. For example, based on the above image, the following can be the unique IDs for the address entries.

 ![00 PM](https://talk.openmrs.org/uploads/default/original/2X/c/c19bdfa7f918a7e56553b0d4180d0c333c26d2f1.png)

If the `user_generated_id` column is null, then a script can be written to generate these IDs based on the above logic.

---

<div class="post-metadata">

**Author:** ![mksrom](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksrom/32/20221_2.png) [@mksrom](https://talk.openmrs.org/u/mksrom)\
**Post date:** [January 4, 2018, 4:43pm UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867/4 "2018-01-04T16:43:11Z")

</div>

@shashikanth, another problem I encounter is when I map the Login location with higher level address hierarchy (higher than “'District”) loading the Bahmni Connect page stops working:

1/ Set the login location with a **Country + Province + District** value:

 ![District is set](https://talk.openmrs.org/uploads/default/original/2X/4/44d9418ce2c11833d88b6467e142e20f329e3481.png)

Then Connect loads just fine:

 ![Loads ok](https://talk.openmrs.org/uploads/default/original/2X/3/37a697e21600b14daf91945696ee30dd268dbe23.png)

2/ Set the login location with **Country + Province** only values:

 ![District is not set](https://talk.openmrs.org/uploads/default/original/2X/e/ef500c7e2eb4b09a886e3f727a17ac86c41183b1.png)

Then the page freezes:

 ![Page unresponsive](https://talk.openmrs.org/uploads/default/original/2X/9/986ea8f1de60f33b6ecaa5133d16c9d4542915db.png)

Any idea of what could happen here?

---

<div class="post-metadata">

**Author:** ![mksrom](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksrom/32/20221_2.png) [@mksrom](https://talk.openmrs.org/u/mksrom)\
**Post date:** [January 5, 2018, 5:55pm UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867/5 "2018-01-05T17:55:27Z")

</div>

Thanks @shruthipitta for spending the time to debug this with me 👍 .

We have found that the problem is likely coming from the fact that too many calls are made when the address set on the Login location is a high level in the address hierarchy.

Indeed, there is as many calls made as there is filter values (ie, address entries):

> <https://github.com/Bahmni/bahmni-connect/blob/2cd8e6800f9d7b3bff480ec7a6b0f2e1bbbaac68/ui/app/common/offline/services/offlineSyncService.js#L80>

In my use case, there is only one possible login location named ‘Health Center’ because the clinic is a mobile clinic and provides care across 3 provinces. So I would have to set the level to the highest one, “country”. That is 16,459 address entries.

This means that in the code below, `promises` will contain 16,459 promises.

 ![too many filters](https://talk.openmrs.org/uploads/default/original/2X/d/dc81788a9464216cb52bb2740a759200a51f02ea.png)

And as many HTTP calls will be made. This seems to freeze the Chrome window.

If one sets a lower address level to the Login location, such as a District or Village, the number of child entries is much smaller and all works. For instance, with few trials I can say that around 500~700 entries max, the page works and loads fine.

* * *

**Conclusion** : I believe the LocationBasedSyncStrategy was not created to load such a big number of entries and may just not fit for me here.

I am thinking I should create a “AllPatientsSyncStrategy” instead to simply retrieve all patients.

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [January 5, 2018, 6:29pm UTC](https://talk.openmrs.org/t/bahmni-connect-how-to-setup-the-locationbasedsyncstrategy/13867/6 "2018-01-05T18:29:30Z")

</div>

Thanks for the excellent explanation.
