From f5d207022406421147bf453c5ff1442d6257370a Mon Sep 17 00:00:00 2001 From: Rishabh Date: Mon, 2 Dec 2024 10:23:55 +0530 Subject: [PATCH 1/7] TRUNK-5924 : PatientIdentifier Domain - Switching from Hibernate Mappings to Annotations --- .../java/org/openmrs/PatientIdentifier.java | 23 +++++++--- api/src/main/resources/hibernate.cfg.xml | 7 +-- .../db/hibernate/PatientIdentifier.hbm.xml | 44 ------------------- .../org/openmrs/api/OrderServiceTest.java | 3 ++ 4 files changed, 25 insertions(+), 52 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/PatientIdentifier.hbm.xml diff --git a/api/src/main/java/org/openmrs/PatientIdentifier.java b/api/src/main/java/org/openmrs/PatientIdentifier.java index 516f7bf09bc5..96e34115eb27 100644 --- a/api/src/main/java/org/openmrs/PatientIdentifier.java +++ b/api/src/main/java/org/openmrs/PatientIdentifier.java @@ -14,14 +14,20 @@ import java.lang.reflect.Method; import java.util.Comparator; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.Table; + import org.codehaus.jackson.annotate.JsonIgnore; import org.hibernate.envers.Audited; import org.hibernate.search.annotations.Analyzer; import org.hibernate.search.annotations.Boost; -import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Fields; -import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.search.annotations.SortableField; import org.openmrs.api.db.hibernate.search.LuceneAnalyzers; @@ -37,7 +43,8 @@ * * @see org.openmrs.PatientIdentifierType */ -@Indexed +@Entity +@Table(name = "patient_identifier") @Audited public class PatientIdentifier extends BaseChangeableOpenmrsData implements java.io.Serializable, Cloneable, Comparable { @@ -50,10 +57,12 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java /** * @since 1.5 */ - @DocumentId + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) private Integer patientIdentifierId; @IndexedEmbedded(includeEmbeddedObjectId = true) + @JoinColumn(name = "patient_id") private Patient patient; @Fields({ @@ -63,17 +72,21 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java @Field(name = "identifierAnywhere", analyzer = @Analyzer(definition = LuceneAnalyzers.ANYWHERE_ANALYZER)) }) @SortableField(forField = "identifierExact") + @Column(name = "identifier") private String identifier; @IndexedEmbedded(includeEmbeddedObjectId = true) + @JoinColumn(name = "identifier_type") private PatientIdentifierType identifierType; + @JoinColumn(name = "location") private Location location; + @JoinColumn(name = "patient_program") private PatientProgram patientProgram; - @Field + @Column(name = "preferred", nullable = false) private Boolean preferred = false; /** default constructor */ diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..5d8b93d6d731 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -59,9 +59,10 @@ - - - + + + + diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/PatientIdentifier.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/PatientIdentifier.hbm.xml deleted file mode 100644 index 18a92025b9a8..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/PatientIdentifier.hbm.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - patient_identifier_patient_identifier_id_seq - - - - - - - - - - - - - - - - - - - - - - diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index 6d553c038256..6000391e3789 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -52,6 +52,7 @@ import org.openmrs.OrderSet; import org.openmrs.OrderType; import org.openmrs.Patient; +import org.openmrs.PatientIdentifier; import org.openmrs.PatientIdentifierType; import org.openmrs.PatientState; import org.openmrs.PersonAddress; @@ -2740,6 +2741,8 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) + .addAnnotatedClass(ConceptDatatype.class) + .addAnnotatedClass(PatientIdentifier.class) .getMetadataBuilder().build(); From 75b30337b7b33a17d91106ff786da370c36ad0e3 Mon Sep 17 00:00:00 2001 From: Rishabh <140707297+rishabhrawat05@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:42:23 +0530 Subject: [PATCH 2/7] Added GenericGenerator in Patient Identifier --- api/src/main/java/org/openmrs/PatientIdentifier.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/openmrs/PatientIdentifier.java b/api/src/main/java/org/openmrs/PatientIdentifier.java index 96e34115eb27..18db629c9813 100644 --- a/api/src/main/java/org/openmrs/PatientIdentifier.java +++ b/api/src/main/java/org/openmrs/PatientIdentifier.java @@ -21,7 +21,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.Table; - +import org.hibernate.annotations.Parameter; import org.codehaus.jackson.annotate.JsonIgnore; import org.hibernate.envers.Audited; import org.hibernate.search.annotations.Analyzer; @@ -34,7 +34,7 @@ import org.openmrs.util.OpenmrsUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import org.hibernate.annotations.GenericGenerator; /** * A Patient can have zero to n identifying PatientIdentifier(s). PatientIdentifiers * are anything from medical record numbers, to social security numbers, to driver's licenses. The @@ -59,6 +59,12 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java */ @Id @GeneratedValue(strategy=GenerationType.IDENTITY) + @GenericGenerator( + name = "patient_identifier_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "_identifier_patient_identifier_id_seq") + ) + @Column(name = "patient_identifier_id") private Integer patientIdentifierId; @IndexedEmbedded(includeEmbeddedObjectId = true) From 6209bc112c6fe09e9de4af7d41e3d269475b25ae Mon Sep 17 00:00:00 2001 From: Rishabh Date: Mon, 2 Dec 2024 22:57:25 +0530 Subject: [PATCH 3/7] TRUNK-5924 : PatientIdentifier Domain - Switching from Hibernate Mappings to Annotations --- .../java/org/openmrs/PatientIdentifier.java | 22 +++++++++++++------ api/src/main/resources/hibernate.cfg.xml | 2 -- .../org/openmrs/api/OrderServiceTest.java | 1 - 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/org/openmrs/PatientIdentifier.java b/api/src/main/java/org/openmrs/PatientIdentifier.java index 18db629c9813..859d2d7cb182 100644 --- a/api/src/main/java/org/openmrs/PatientIdentifier.java +++ b/api/src/main/java/org/openmrs/PatientIdentifier.java @@ -13,13 +13,14 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Comparator; - +import org.hibernate.search.annotations.DocumentId; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hibernate.annotations.Parameter; import org.codehaus.jackson.annotate.JsonIgnore; @@ -27,6 +28,7 @@ import org.hibernate.search.annotations.Analyzer; import org.hibernate.search.annotations.Boost; import org.hibernate.search.annotations.Field; +import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Fields; import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.search.annotations.SortableField; @@ -45,6 +47,7 @@ */ @Entity @Table(name = "patient_identifier") +@Indexed @Audited public class PatientIdentifier extends BaseChangeableOpenmrsData implements java.io.Serializable, Cloneable, Comparable { @@ -57,16 +60,18 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java /** * @since 1.5 */ + @DocumentId @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @GenericGenerator( name = "patient_identifier_id_seq", strategy = "native", - parameters = @Parameter(name = "sequence", value = "_identifier_patient_identifier_id_seq") + parameters = @Parameter(name = "sequence", value = "patient_identifier_patient_identifier_id_seq") ) @Column(name = "patient_identifier_id") private Integer patientIdentifierId; - + + @ManyToOne @IndexedEmbedded(includeEmbeddedObjectId = true) @JoinColumn(name = "patient_id") private Patient patient; @@ -78,20 +83,23 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java @Field(name = "identifierAnywhere", analyzer = @Analyzer(definition = LuceneAnalyzers.ANYWHERE_ANALYZER)) }) @SortableField(forField = "identifierExact") - @Column(name = "identifier") + @Column(name = "identifier", length = 50) private String identifier; + @ManyToOne @IndexedEmbedded(includeEmbeddedObjectId = true) @JoinColumn(name = "identifier_type") private PatientIdentifierType identifierType; - @JoinColumn(name = "location") + @ManyToOne + @JoinColumn(name = "location_id", nullable = true) private Location location; - @JoinColumn(name = "patient_program") + @ManyToOne + @JoinColumn(name = "patient_program_id", nullable = true) private PatientProgram patientProgram; - + @Field @Column(name = "preferred", nullable = false) private Boolean preferred = false; diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 5d8b93d6d731..6ac71843b7fa 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -60,8 +60,6 @@ - - diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index 6000391e3789..0ee70f2788aa 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -2741,7 +2741,6 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) - .addAnnotatedClass(ConceptDatatype.class) .addAnnotatedClass(PatientIdentifier.class) .getMetadataBuilder().build(); From 61015d3a47e4541309e91fc25c662b0c0144a905 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 3 Dec 2024 12:00:02 +0530 Subject: [PATCH 4/7] TRUNK-5924 : Updated PatientIdentifier class --- api/src/main/java/org/openmrs/PatientIdentifier.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/openmrs/PatientIdentifier.java b/api/src/main/java/org/openmrs/PatientIdentifier.java index 859d2d7cb182..8bfea0bb9f85 100644 --- a/api/src/main/java/org/openmrs/PatientIdentifier.java +++ b/api/src/main/java/org/openmrs/PatientIdentifier.java @@ -62,7 +62,7 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java */ @DocumentId @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "patient_identifier_id_seq") @GenericGenerator( name = "patient_identifier_id_seq", strategy = "native", @@ -71,8 +71,8 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java @Column(name = "patient_identifier_id") private Integer patientIdentifierId; - @ManyToOne @IndexedEmbedded(includeEmbeddedObjectId = true) + @ManyToOne @JoinColumn(name = "patient_id") private Patient patient; @@ -86,8 +86,8 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java @Column(name = "identifier", length = 50) private String identifier; - @ManyToOne @IndexedEmbedded(includeEmbeddedObjectId = true) + @ManyToOne @JoinColumn(name = "identifier_type") private PatientIdentifierType identifierType; From 40718636789641cd9692e4e2ae5da1433b5388a2 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 4 Dec 2024 17:56:07 +0530 Subject: [PATCH 5/7] TRUNK-5924 : Updated PatientIdentifier class --- .../java/org/openmrs/PatientIdentifier.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/org/openmrs/PatientIdentifier.java b/api/src/main/java/org/openmrs/PatientIdentifier.java index 8bfea0bb9f85..24ba1682b33d 100644 --- a/api/src/main/java/org/openmrs/PatientIdentifier.java +++ b/api/src/main/java/org/openmrs/PatientIdentifier.java @@ -13,30 +13,32 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Comparator; -import org.hibernate.search.annotations.DocumentId; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import org.hibernate.annotations.Parameter; + import org.codehaus.jackson.annotate.JsonIgnore; import org.hibernate.envers.Audited; import org.hibernate.search.annotations.Analyzer; import org.hibernate.search.annotations.Boost; +import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Field; -import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Fields; +import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.search.annotations.SortableField; import org.openmrs.api.db.hibernate.search.LuceneAnalyzers; import org.openmrs.util.OpenmrsUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.persistence.Column; +import javax.persistence.Entity; +import org.hibernate.annotations.Parameter; import org.hibernate.annotations.GenericGenerator; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + /** * A Patient can have zero to n identifying PatientIdentifier(s). PatientIdentifiers * are anything from medical record numbers, to social security numbers, to driver's licenses. The From d2adeebb927f1cd35bb950e4cb6a359675368be9 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 4 Dec 2024 18:05:30 +0530 Subject: [PATCH 6/7] TRUNK-5924 : Updated hibernate.cfg.xml --- api/src/main/resources/hibernate.cfg.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 6ac71843b7fa..c96dcbb5f3a3 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -59,8 +59,9 @@ - - + + + @@ -112,4 +113,4 @@ - + \ No newline at end of file From 81708f47538a79b557f476f7e976c539b78e7fc3 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 4 Dec 2024 18:32:26 +0530 Subject: [PATCH 7/7] TRUNK-5924 : Updated hibernate.cfg.xml --- api/src/main/resources/hibernate.cfg.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index c96dcbb5f3a3..02d3953351fd 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -59,7 +59,6 @@ -