Bahmni Connect: Error 400 (Bad Request) on `event-log-service/rest/eventlog/events/encounter`

Hi !

Starting from a fresh installation of Bahmni 0.89 (no Odoo), I have followed the different wiki steps to install Bahmni Connect. Installing+Bahmni+Connect+on+Server Bahmni+Connect+Deployment+Steps

Plus I have added to the SSL certs (OpenMRS Talk: Bahmni Connect (0.89): ERR_INSECURE_RESPONSE).

The Bahmni Connect initial sync is starting (I am asked to log in) but then quickly returns an error:

Could not connect to the server. Please check your connection and try again

Initial sync failed. Please contact system administrator.

In the Chrome console:

GET https://infra-79.mekomsolutions.net/event-log-service/rest/eventlog/events/encounter 400 (Bad Request)

Any idea what could cause this?

Event log service is correctly running:

$ sudo service bahmni-event-log-service status
Service bahmni-event-log-service is running with pid: 5204

Thanks

Romain

Hi @mksrom,

It would be worth checking openMRS login credentials in the application.properties file at the below location.

/opt/bahmni-event-log-service/bahmni-event-log-service/WEB-INF/classes

In the OpenMRS, Administration – Advanced Settings, you will have to configure the sync strategy to be either ID based or address based.

ID Based bahmniOfflineSync.strategy = org.bahmni.module.bahmniOfflineSync.strategy.IDBasedSyncStrategy

Location Based. bahmniOfflineSync.strategy = org.bahmni.module.bahmniOfflineSync.strategy.LocationBasedSyncStrategy

Additionally, if its Location based, then the login location should in OpenMRS should be assigned address hierarchy.

Please check the logs in /var/log/bahmni-event-log-service and gather more information on the cause of issue. Also please refer to the link below as there have been improvements in initial sync for Connect. https://bahmni.atlassian.net/wiki/display/BAH/Server+Requirements

Sorry for the late response. I am still experiencing this problem.

$ cat /opt/bahmni-event-log-service/bahmni-event-log-service/WEB-INF/classes/application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/openmrs
spring.datasource.username=openmrs-user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# Keep the connection alive if idle for a long time
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1

spring.jpa.generate-ddl=false
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
server.port=8057

liquibase.change-log=classpath:db/changelog/liquibase.xml

enable.scheduling=true

bahmni.eventlog.uri=http://localhost:8050/openmrs/ws/rest/v1/eventlog/filter/
openmrs.auth.uri=http://localhost:8050/openmrs/ws/rest/v1/session

openmrs.user=admin
openmrs.password=test
openmrs.connectionTimeoutInMilliseconds=500000
openmrs.replyTimeoutInMilliseconds=20000

Is there anything abnormal in this? I have tried to change the credentials to:

openmrs.user=superman
openmrs.password=Admin123

But this didn’t change anything. Still the same error…

This is configured with the ID based strategy:

Here is the Bahmni Event Log Service log: http://paste.ubuntu.com/24840693/


Now looking at the error message returned:

‘filterBy’ is not present… ?

Does anyone have successfully installed Bahmni Connect (from version 0.89)?

@darius, @gsluthra, are you aware of any implementation that uses Bahmni Connect installed on server, preferably on version 0.89?

In short:

filterBy is empty because EventLogFilterController is returning empty arrays.

Call made:

https://infra-79.mekomsolutions.net/openmrs/ws/rest/v1/eventlog/filter/markers/c1c26908-3f10-11e4-adec-0800271c1b75/613031c6-cd03-4483-b90c-e86a15c9f032/baf7bd38-d225-11e4-9c67-080027b662ec

Response returned: {"patient":[],"offline-concepts":[],"addressHierarchy":[],"encounter":[]}

In the demo server, the call made is the following (note that the addressUuid is different for some reason):

https://demo.mybahmni.org/openmrs/ws/rest/v1/eventlog/filter/markers/c1c26908-3f10-11e4-adec-0800271c1b75/2c0e6cae-5d96-446e-9b94-341cce23c06e/baf7bd38-d225-11e4-9c67-080027b662ec

{"patient":["GAN"],"offline-concepts":[],"addressHierarchy":[],"encounter":["GAN"]}

(Q) Why is it returned empty in my freshly installed server, but it returns ‘GAN’ in the demo server? Is there some metadata that I need to manually add or something?


Debugging details (optional to read):

  • The filterBy parameter is indeed required by the EventLog resource (here):
...@RequestParam(value = "filterBy", required = true) String[] filterBy) {

###In BahmniApps (front-end):

  • filterBy is set to marker.filters (here).But it is an empty array.
  • skipping few steps
  • Markers are fetched by offlineMarkerDbService#getMarkers
  • But the marker for category “encouner” contains an empty array for filters

marker.filters is empty

  • Empty filters seems to be normal for the first time sync. So there is
marker.filters = offlineService.getItem("initSyncFilter");

(here) that is run at the fisrt syncing.

  • the item “initSyncFilter” is set as the “categoryFilterMap” object contents
offlineService.setItem("initSyncFilter", categoryFilterMap[category]);
  • And finally, categoryFilterMap is fetched from the server here:
var getFilterForCategoryAndLoginLocation = function (providerUuid, addressUuid, loginlocationUuid) {
    var url = Bahmni.Common.Constants.eventlogFilterUrl + "/markers/" + providerUuid + "/" + addressUuid + "/" + loginlocationUuid;
    return $http.get(url, {method: "GET", withCredentials: true});
};

This call returns empty filters for the encounters:

URL called: https://infra-79.mekomsolutions.net/openmrs/ws/rest/v1/eventlog/filter/markers/c1c26908-3f10-11e4-adec-0800271c1b75/613031c6-cd03-4483-b90c-e86a15c9f032/baf7bd38-d225-11e4-9c67-080027b662ec Result returned: {"patient":[],"offline-concepts":[],"addressHierarchy":[],"encounter":[]}


###In Bahmni Offline Sync (back-end)

The call is handled by the Bahmni Offline Sync module (here) which then calls the IDBasedSyncStrategy.java. So here is where the filters are set empty:

        Location location = locationService.getLocationByUuid(loginLocationUuid);
        Map<String, List<String>> categoryFilterMap = new HashMap();
        final Collection<LocationAttribute> activeAttributes = location.getActiveAttributes();
        ArrayList<String> filters = new ArrayList<String>();

        for (LocationAttribute attr : activeAttributes) {
            if (attr.getAttributeType().getName().equals("IdentifierSourceName")) {
                String prefix = getPrefixFor(attr.getValue().toString());
                if (prefix == null) {
                    RuntimeException exception = new RuntimeException("Please check [IdentifierSourceName] config for [" + location.getName() + "]");
                    logger.error(exception);
                    throw exception;
                }
                filters.add(prefix);
            }
        }

        categoryFilterMap.put("patient", filters);
        categoryFilterMap.put("encounter", filters);
        categoryFilterMap.put("addressHierarchy", new ArrayList<String>());
        categoryFilterMap.put("offline-concepts", new ArrayList<String>());

        return categoryFilterMap;
    }

Hi mksrom,

By looking at your freshly installed server, the global property ‘bahmniOfflineSync.strategy’ is different from the demo server.

and if you are using IDBasedStrategy, you need to set the IdentifierSourceName as one of the Prefixes of Patient Identifier like GAN.

1 Like

That is just because I have tried different Offline Sync strategies. At the time I’ve written this post and all troubleshooting steps, the strategy was set to IDBasedSyncStrategy.

However, I haven’t seen that I was missing the IdentifierSourceName to be mapped with the prefix. Thanks a lot for looking into this.

That will probably solve my problem. I try and let you know.

It works. Thanks a lot. :thumbsup: Though very quickly I encounter another error in the clinical screen which will be the subject of another thread.

1 Like