From 4177d7616c81bfa2341dc9fc6bf21c83179a5f5d Mon Sep 17 00:00:00 2001 From: ManojLL Date: Sat, 9 Nov 2024 09:11:23 +0530 Subject: [PATCH] TRUNK-5799: Migrate EncounterProvider hibernate mapping from XML to annotations --- .../java/org/openmrs/EncounterProvider.java | 37 ++++++++-- api/src/main/resources/hibernate.cfg.xml | 1 - .../db/hibernate/EncounterProvider.hbm.xml | 71 ------------------- .../org/openmrs/api/OrderServiceTest.java | 2 + 4 files changed, 35 insertions(+), 76 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/EncounterProvider.hbm.xml diff --git a/api/src/main/java/org/openmrs/EncounterProvider.java b/api/src/main/java/org/openmrs/EncounterProvider.java index cf4ee70141de..584763fa3407 100644 --- a/api/src/main/java/org/openmrs/EncounterProvider.java +++ b/api/src/main/java/org/openmrs/EncounterProvider.java @@ -9,24 +9,53 @@ */ package org.openmrs; +import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; 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.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + /** * Mapping Class between Encounters and Providers which allows many to many relationship. * * @since 1.9 */ +@Entity +@Table(name = "encounter_provider") +@BatchSize(size = 25) @Audited public class EncounterProvider extends BaseChangeableOpenmrsData { public static final long serialVersionUID = 1L; - + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "encounter_provider_id_seq") + @GenericGenerator( + name = "encounter_provider_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "encounter_provider_encounter_provider_id_seq") + ) + @Column(name = "encounter_provider_id") private Integer encounterProviderId; - + + @ManyToOne + @JoinColumn(name = "encounter_id", nullable = false) private Encounter encounter; - + + @ManyToOne + @JoinColumn(name = "provider_id", nullable = false) private Provider provider; - + + @ManyToOne + @JoinColumn(name = "encounter_role_id", nullable = false) private EncounterRole encounterRole; public void setEncounterProviderId(Integer encounterProviderId) { diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..c81e5407c44f 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -77,7 +77,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/EncounterProvider.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/EncounterProvider.hbm.xml deleted file mode 100644 index 8471185e7e1c..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/EncounterProvider.hbm.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - encounter_provider_encounter_provider_id_seq - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index 6d553c038256..e5c7b5169c19 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.EncounterProvider; 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(EncounterProvider.class) .getMetadataBuilder().build();