dsurrao
(Dominic Surrao)
October 11, 2018, 4:31pm
1
The openmrs-module-coreapps api-2.2 version of EncounterDiagnosesElement.java uses a hardcoded encounter type when saving a diagnosis, what is the purpose of this, and can it be removed?
Context.getDiagnosisService().save(diagnosis);
}
}else{
diagnosis = new org.openmrs.Diagnosis();
diagnosis.setDiagnosis(new CodedOrFreeText(answer.getCodedAnswer(), answer.getSpecificCodedAnswer(), answer.getNonCodedAnswer()));
diagnosis.setEncounter(formEntrySession.getEncounter());
diagnosis.setCertainty(certaintyStatus);
diagnosis.setRank(rank);
diagnosis.setPatient(formEntrySession.getPatient());
diagnosis.getEncounter().setEncounterType(Context.getEncounterService().getEncounterTypeByUuid(VISIT_NOTE_ENCOUNTER_TYPE_UUID));
Context.getEncounterService().saveEncounter(diagnosis.getEncounter());
Context.getDiagnosisService().save(diagnosis);
}
}
// Remove Diagnoses that were not resubmitted
Collection<org.openmrs.Diagnosis> diagnosesToVoid = CollectionUtils
.subtract(existingDiagnoses, resubmittedDiagnoses);
@pluwum , @dkayiwa , @mogoodrich
Thanks,
Dominic
dkayiwa
(Daniel Kayiwa)
October 11, 2018, 9:15pm
2
@dsurrao what do you think would be the best way of handling this?
dsurrao
(Dominic Surrao)
October 11, 2018, 10:51pm
3
On my local instance, I removed lines 277 and 278 and was able to save a diagnosis (the DB did not have the value VISIT_NOTE_ENCOUNTER_TYPE_UUID).
But I’m trying to understand the intention of those two lines in the first place, do you know?
Thanks.
mogoodrich
(Mark Goodrich)
October 12, 2018, 12:24pm
4
@dkayiwa , I agree with @dsurrao … our opinion is that these two lines can just be removed, but we were wondering if we were missing something. Why is this element trying to change the encounter type of the HFE encounter?
mogoodrich
(Mark Goodrich)
October 15, 2018, 1:24pm
5
@dkayiwa … a ping here… do you think there is any reason not to remove lines 277 and 278? Thanks!
dkayiwa
(Daniel Kayiwa)
October 15, 2018, 7:51pm
6
@dsurrao which version of the OpenMRS platform are you running?
dsurrao
(Dominic Surrao)
October 15, 2018, 8:09pm
7
@dkayiwa 2.2.0-SNAPSHOT of openmrs-core
dkayiwa
(Daniel Kayiwa)
October 15, 2018, 8:14pm
8
And how are you saving diagnosis via the user interface?
dkayiwa
(Daniel Kayiwa)
October 15, 2018, 8:42pm
9
mogoodrich
(Mark Goodrich)
October 15, 2018, 10:02pm
10
@dkayiwa maybe I’m missing something, but although this would work, I still think your commit above is redundant?
This element would only be used to save a diagnosis via an HTML Form.
dkayiwa
(Daniel Kayiwa)
October 16, 2018, 5:54am
11
@mogoodrich yes you are correct to say that this element is used for saving diagnosis via html forms. When that line is commented out, the diagnosis’s encounter does not have an encounter type and trying to save it results into a validation exception. Could there be something am missing that leads to the encounter type being null?
mogoodrich
(Mark Goodrich)
October 16, 2018, 1:48pm
12
@dkayiwa where are you seeing this behavior (encounter type being null)? Currently, Html Forms are always in the context of an encounter, so the encounter type should come from the tag within the form… are we trying to handle a case when we use the tag without specifying an encounter type?
Per your commit, what I’m saying is is that this line seems redundant/meaningless:
Context.getDiagnosisService().save(diagnosis);
}
}else{
diagnosis = new org.openmrs.Diagnosis();
diagnosis.setDiagnosis(new CodedOrFreeText(answer.getCodedAnswer(), answer.getSpecificCodedAnswer(), answer.getNonCodedAnswer()));
diagnosis.setEncounter(formEntrySession.getEncounter());
diagnosis.setCertainty(certaintyStatus);
diagnosis.setRank(rank);
diagnosis.setPatient(formEntrySession.getPatient());
diagnosis.getEncounter().setEncounterType(formEntrySession.getForm().getEncounterType());
Context.getEncounterService().saveEncounter(diagnosis.getEncounter());
Context.getDiagnosisService().save(diagnosis);
}
}
// Remove Diagnoses that were not resubmitted
Collection<org.openmrs.Diagnosis> diagnosesToVoid = CollectionUtils
.subtract(existingDiagnoses, resubmittedDiagnoses);
… based on the previous line here:
diagnosis.setRank(rank);
diagnosis.setCertainty(certaintyStatus);
diagnosis.setDateChanged(new Date());
diagnosis.setChangedBy(Context.getAuthenticatedUser());
Context.getDiagnosisService().save(diagnosis);
}
}else{
diagnosis = new org.openmrs.Diagnosis();
diagnosis.setDiagnosis(new CodedOrFreeText(answer.getCodedAnswer(), answer.getSpecificCodedAnswer(), answer.getNonCodedAnswer()));
diagnosis.setEncounter(formEntrySession.getEncounter());
diagnosis.setCertainty(certaintyStatus);
diagnosis.setRank(rank);
diagnosis.setPatient(formEntrySession.getPatient());
diagnosis.getEncounter().setEncounterType(formEntrySession.getForm().getEncounterType());
Context.getEncounterService().saveEncounter(diagnosis.getEncounter());
Context.getDiagnosisService().save(diagnosis);
}
}
mogoodrich
(Mark Goodrich)
October 16, 2018, 1:49pm
13
(and if we aren’t changing the encounter, we don’t need this line):
}
}else{
diagnosis = new org.openmrs.Diagnosis();
diagnosis.setDiagnosis(new CodedOrFreeText(answer.getCodedAnswer(), answer.getSpecificCodedAnswer(), answer.getNonCodedAnswer()));
diagnosis.setEncounter(formEntrySession.getEncounter());
diagnosis.setCertainty(certaintyStatus);
diagnosis.setRank(rank);
diagnosis.setPatient(formEntrySession.getPatient());
diagnosis.getEncounter().setEncounterType(formEntrySession.getForm().getEncounterType());
Context.getEncounterService().saveEncounter(diagnosis.getEncounter());
Context.getDiagnosisService().save(diagnosis);
}
}
// Remove Diagnoses that were not resubmitted
Collection<org.openmrs.Diagnosis> diagnosesToVoid = CollectionUtils
.subtract(existingDiagnoses, resubmittedDiagnoses);
for (org.openmrs.Diagnosis diagnosisToVoid : diagnosesToVoid) {
dkayiwa
(Daniel Kayiwa)
October 16, 2018, 2:21pm
14
@mogoodrich am seeing this behaviour when i enter a visit note in the reference application running on platform 2.2
mogoodrich
(Mark Goodrich)
October 16, 2018, 2:30pm
15
Thanks @dkayiwa … sorry, can you point me to the underlying HTML Form that visit note uses? I’m not 100% familiar with where forms live within the reference app.
After the change to lines 277 did you confirm that the issue is still resolved?
Take care,
Mark
dkayiwa
(Daniel Kayiwa)
October 16, 2018, 2:45pm
16
This is the visit note form https://github.com/openmrs/openmrs-module-referenceapplication/blob/master/omod/src/main/webapp/resources/htmlforms/simpleVisitNote.xml
The last commit was not addressing any error. It was just addressing your comment of not hardcoding an encounter type. But without those reported lines, you cannot save any visit notes from the refapp on platform 2.2
mogoodrich
(Mark Goodrich)
October 16, 2018, 2:55pm
17
Thanks @dkayiwa !
I just meant, I wanted to confirm that after your change you are still able to save a visit note…
mogoodrich
(Mark Goodrich)
October 16, 2018, 3:01pm
18
Ah, okay @dkayiwa , I have to run to a meeting but I think I understand now, will follow up shortly…
mogoodrich
(Mark Goodrich)
October 16, 2018, 4:19pm
19
So @dkayiwa I think the issue in order to persist the diagnosis, the encounter needs to be persisted been first. Ideally instead of saving the diagnosis directly within the EncounterDiagnosisElement it would happen in the apply actions section of HFE:
/**
* Applies all the actions associated with a form submission--that is, create/update any
* Persons, Encounters, and Obs in the database as necessary, and enroll Patient in any programs
* as needed
* <p/>
* TODO: This requires that...
*
* @throws BadFormDesignException
*/
public void applyActions() throws BadFormDesignException {
// if any encounter to be created by this form is missing a required field, throw an error
// (If there's a widget but it was left blank, that would have been caught earlier--this
// is for when there was no widget in the first place.)
// the change here assumes that the encounterLocation and encounterProvider tags are validated elsewhere since they are
// not required
{
for (Encounter e : submissionActions.getEncountersToCreate()) {
if (e.getEncounterDatetime() == null) {
throw new BadFormDesignException(
But since we aren’t doing that, we need to make sure we save the encounter within the encounter diagnosis element… and we need to manually set the encounter type since in HFE the encounter type associated with the form isn’t set on the encounter until the encounter is saved:
"Please check the design of your form to make sure the following fields are mandatory to create a patient: <br/><b><personName/></b>, <b><birthDateOrAge/></b>, <b><gender/></b>, <b><identifierType/></b>, <b><identifier/></b>, and <b><identifierLocation/></b>");
}
}
Context.getPersonService().savePerson(p);
}
}
if (submissionActions.getEncountersToCreate() != null) {
for (Encounter e : submissionActions.getEncountersToCreate()) {
if (form != null) {
e.setForm(form);
if (form.getEncounterType() != null)
e.setEncounterType(form.getEncounterType());
}
Context.getEncounterService().saveEncounter(encounter);
}
}
//deal with relationships
if (submissionActions.getRelationshipsToCreate() != null) {
for (Relationship r : submissionActions.getRelationshipsToCreate()) {
if (log.isDebugEnabled()) {
So I’ll try to take a quick look to see if it would be easy to create a submission action to create a diagnosis, but otherwise I think the current implementation with your change makes sense. Thanks!
Take care,
Mark