-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TRUNK-5492 Replace Person and Patient hbm mapping file with annotations #2900
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,7 +608,7 @@ public boolean isIdentifierInUseByAnotherPatient(PatientIdentifier patientIdenti | |
&& patientIdentifier.getIdentifierType().getUniquenessBehavior() == UniquenessBehavior.LOCATION; | ||
|
||
// switched this to an hql query so the hibernate cache can be considered as well as the database | ||
String hql = "select count(*) from PatientIdentifier pi, Patient p where pi.patient.patientId = p.patient.patientId " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a bug fix? Or is it a change caused by switching to annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug fix because it was wrong before, annotations just exposed it, p is an alias for patient, and patient for sure doesn't have a patient field |
||
String hql = "select count(*) from PatientIdentifier pi, Patient p where pi.patient.patientId = p.patientId " | ||
+ "and p.voided = false and pi.voided = false and pi.identifier = :identifier and pi.identifierType = :idType"; | ||
|
||
if (checkPatient) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
import org.openmrs.User; | ||
import org.openmrs.annotation.Handler; | ||
import org.openmrs.aop.RequiredDataAdvice; | ||
import org.openmrs.api.context.Context; | ||
|
||
/** | ||
* This class deals with {@link Patient} objects when they are saved via a save* method in an | ||
|
@@ -45,5 +46,10 @@ public void handle(Patient patient, User creator, Date dateCreated, String other | |
} | ||
} | ||
} | ||
|
||
if(patient.getPatientId() == null){ | ||
patient.setCreator(Context.getAuthenticatedUser()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a bug fix? Or is it a change caused by switching to annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really but sort of, more like bad design, this is needed because creator and dateCreated fields exist both in BaseOpenmrsData and Patient, this is actually bad practice because it defeats the purpose of inheritance, and this where xml and annotations differ, because annotations are pure java whereas xml isn't, with xml you get away with bad things just like we were doing before which is why I say sort of a bug. Anyways, long story short, hibernate is unable to set these fields via the AuditableInterceptor mechanism because based on the ClassMedata it has built for Patient class, it sees the same fields on the superclass and the subclass and treats them as different because they are declared by different classes anyways, it only sets the values of the fields in the superclass and not the subclass so we have to manually set them from here as we used to do before to get around it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of adding this comment to the code? |
||
patient.setDateCreated(new Date()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
package org.openmrs.api.handler; | ||
|
||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.openmrs.Address; | ||
import org.openmrs.Person; | ||
import org.openmrs.PersonAddress; | ||
import org.openmrs.PersonAttribute; | ||
|
@@ -42,13 +45,16 @@ public void handle(Person person, User creator, Date dateCreated, String other) | |
|
||
// address collection | ||
if (person.getAddresses() != null && !person.getAddresses().isEmpty()) { | ||
Set<Address> blankAddresses = new HashSet<>(); | ||
for (PersonAddress pAddress : person.getAddresses()) { | ||
if (pAddress.isBlank()){ | ||
person.removeAddress(pAddress); | ||
if (pAddress.isBlank()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a bug fix? Or is it a change caused by switching to annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely a bug, it's java 101, you can't remove an element from the same Iterable you are looping over, you get a ConcurrentModificationException |
||
blankAddresses.add(pAddress); | ||
continue; | ||
} | ||
pAddress.setPerson(person); | ||
} | ||
|
||
person.getAddresses().removeAll(blankAddresses); | ||
} | ||
|
||
// name collection | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind explaining why you needed to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In-memory, this field is null when you create the patient record since it is technically mapped to a FK column which is why it is mapped as not insertable and not updatable, I wonder why hibernate was setting it with xml but not with annotations though, my guess is there could be a hibernate specific annotations to fix it that JPA doesn't support, will look into it a little a bit to see if there is another work around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of adding this comment to the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can but I see that you already merged the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do it as a followup commit.