Bahmni Connect: Ability to delete a diagnosis

Hi guys!

I have been able to partially add support for entering diagnoses in Bahmni Connect. Currently I can add diagnoses and they will be synced to the server just fine.

I am now looking at how to delete a diagnosis.

In Bahmni Connect, there is kind of 3 layers of storage:

  • The $scope.consultation object, which is used to store the consultation details such as NewlyAddedDiagnoses, SavedDiagnosesFromCurrentEncounter, PastDiagnoses, and many other fields, used in the views: consultation

  • Upon clicking on Save, the $scope.consultation object is mapped to Encounter objects that will be saved in the local IndexedDB in Encounter table. Newly added diagnoses (present in $scope.consultation.newlyAddedDiagnoses array) are saved in the DB in encounterJson.bahmniDiagnoses: encounter

  • Finally, when clicking on Sync, all Encounter objects are saved through Bahmni Core Encounter resource. offlinePush.js#L62-L63

All this chain works fine when adding new diagnoses. Not when deleting a diagnosis.

I have tried different options and one is to void the diagnosis (add a field voided:true to the right encounterJson.bahmniDiagnoses entry) but then when sync I get a server error message saying that a diagnosis can not be saved twice.

@sumanmaity112 @shashikanth @angshuonline how would you recommend to approach the problem?

@mksrom So diagnosis delete is a separate call from bahmni Apps https://product-qa04.mybahmni.org/openmrs/ws/rest/v1/bahmnicore/diagnosis/delete?obsUuid=? and its not part of encounter save. I think this (diagnosis delete) should be a separate event in the event queue in offline push. One thing to remember is whatever we do for bahmni-connect in chrome we also have to do for android.

Thanks.

Does it mean that diagnoses have to be a separate table in the DB?

Hi @mksrom,

diagnoses will not be a separate table but for all the delete diagnoses event you have to create a new event in event_queue. Check this

@mksrom We can have them in separate table or we should have the logic of modifying the diagonsis obs rows when we delete diagnosis from obs table.

OK, so I could create an event when deleting a diagnosis in the offlineDiagnosisService.

I guess something such as:

offlineDiagnosisService.js

this.deleteDiagnosis = function (diagnosis) {
    var deferred = $q.defer();

    // Create an event which will be handled when syncing with server
    var event = {type: "diagnosis", diagnosisUuid: diagnosis.uuid, dbName: offlineDbService.getCurrentDbName() };
    eventQueue.addToEventQueue(event);

    diagnosis.voided = true;
    deferred.resolve({"data": diagnosis})
    return deferred.promise;

};

Am I right?

Then what is the process that handles these events when pushed? Is it the server-side offline sync strategy?

Is that really necessary?

I could imagine that when the user deletes a diagnosis, then the diagnosis is simply voided (and saved locally as usual in the encounter table). But because the deleted diagnosis has also been recorded as an event, it will indeed correctly be handled when offline pushing.

Is that possible?

I think this should be good enough. Otherwise, check offlinePush.js

I am not sure about “deleting” a diagnosis. You should probably allow to change an existing diagnosis status to “refuted” or “entered-in-error”. OpenMRS Obs now have a status column, which should probably hold “entered-in-error”. (However, current values allowed are PRELIMINARY, FINAL,AMENDED)

@angshuonline @sumanmaity112, I am able to create an event to delete a diagnosis and getting this event processed as a GET request in offlinePush.

The event is created such as:

offlineDiagnosisService.js

var event = {type: "deleteDiagnosis", obsUuid: diagnosis.existingObs ? diagnosis.existingObs : diagnosis.previousObs, dbName: offlineDbService.getCurrentDbName() };

offlinePush.js

if (event.data.type && event.data.type == "deleteDiagnosis") {
  return $http({
    method: 'GET',
    url: Bahmni.Common.Constants.bahmniDeleteDiagnosisUrl,
    params: response,
    withCredentials: config.withCredentials,
    headers: config.headers
  });
}

Though the call returns true, it actually does not delete the diagnosis. I will troubleshoot the server side and see what’s going on…

On the server side it marks the diagnosis as voided as far as I know.

@mksrom: a related note, what are doing about looking up diagnosis when user types in Connect? you will need to sync a reference set “diagnosis set of sets” and cache that data in indexedDB. This set can be quite substantial.

Actually the simplest solution was to:

  • Modify the Python initial script to copy all children of ‘Diagnosis Set of Sets’ to the event_records table
  • In Bahmni Connect, add the diagnosisService.searchForDiagnosisConcepts(searchTerm) method (in offlineDiagnosisService.js) so that when the user starts typing in, concepts that are of class Diagnosis are searched. And in order to make things fast and efficient, I have actually added the conceptClass to the concept table (in Indexed DB) as a well as a searchKey.

Right. I think the problem is present for every event though, not only diagnoses or concepts but also address entries, encounters, observations, patients… Bahmni Connect initial sync can take forever because of this. So I guess this is something that needs to be addressed in general in Connect.


I have now manage to make this work (deleting diagnoses) but for some reason, voided diagnoses are still returned and displayed in Connect, even though they are correctly voided server-side (the online version doesn’t show them any more). I will look into that next week (I am off for few days now)