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:
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:
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.
@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.
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?
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.
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)
@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.
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)