From 1c664b0c1d5aa8214d9cd45457fdf72c2faa3d8d Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 4 Dec 2024 20:31:57 +0530 Subject: [PATCH 1/2] TRUNK-5828 : EncounterRole Domain - Switching from Hibernate Mappings to Annotations --- .../main/java/org/openmrs/EncounterRole.java | 18 +++++++ api/src/main/resources/hibernate.cfg.xml | 1 - .../api/db/hibernate/EncounterRole.hbm.xml | 51 ------------------- .../org/openmrs/api/OrderServiceTest.java | 2 + 4 files changed, 20 insertions(+), 52 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/EncounterRole.hbm.xml diff --git a/api/src/main/java/org/openmrs/EncounterRole.java b/api/src/main/java/org/openmrs/EncounterRole.java index 0d3f7564cac1..936b6b8b38b1 100644 --- a/api/src/main/java/org/openmrs/EncounterRole.java +++ b/api/src/main/java/org/openmrs/EncounterRole.java @@ -10,6 +10,14 @@ package org.openmrs; import org.hibernate.envers.Audited; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; /** * An EncounterRole a role specific to the encounter. While these could match up to existing @@ -17,12 +25,22 @@ * * @since 1.9 */ +@Entity +@Table(name = "encounter_role") @Audited public class EncounterRole extends BaseChangeableOpenmrsMetadata { public static final String UNKNOWN_ENCOUNTER_ROLE_UUID = "a0b03050-c99b-11e0-9572-0800200c9a66"; // Fields + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "encounter_role_id_seq") + @GenericGenerator( + name = "encounter_role_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "encounter_role_encounter_role_id_seq") + ) + @Column(name = "encounter_role_id", nullable = false) private Integer encounterRoleId; // Constructors diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..ccb05824184e 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -78,7 +78,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/EncounterRole.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/EncounterRole.hbm.xml deleted file mode 100644 index f77c87b75530..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/EncounterRole.hbm.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - encounter_role_encounter_role_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..a9591726818d 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -35,6 +35,7 @@ import org.openmrs.DrugIngredient; import org.openmrs.DrugOrder; import org.openmrs.Encounter; +import org.openmrs.EncounterRole; import org.openmrs.FreeTextDosingInstructions; import org.openmrs.GlobalProperty; import org.openmrs.Location; @@ -2740,6 +2741,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) + .addAnnotatedClass(EncounterRole.class) .getMetadataBuilder().build(); From 266e20e6effe684ea98df13ab7873425a061b1f0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 4 Dec 2024 22:54:17 +0530 Subject: [PATCH 2/2] TRUNK-5828 : Update EncounterRole class --- api/src/main/java/org/openmrs/EncounterRole.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/main/java/org/openmrs/EncounterRole.java b/api/src/main/java/org/openmrs/EncounterRole.java index 936b6b8b38b1..d69d6cf6f7ad 100644 --- a/api/src/main/java/org/openmrs/EncounterRole.java +++ b/api/src/main/java/org/openmrs/EncounterRole.java @@ -16,6 +16,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; @@ -27,6 +28,7 @@ */ @Entity @Table(name = "encounter_role") +@BatchSize(size = 25) @Audited public class EncounterRole extends BaseChangeableOpenmrsMetadata {