From 7c19c6c9781b2cde8e5ba0633409388bfdccaa32 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Fri, 8 Nov 2024 12:27:37 +0530 Subject: [PATCH] TRUNK-5793: Migrate AllergyReaction from Hibernate mapping XML to annotations --- .../java/org/openmrs/AllergyReaction.java | 33 ++++++++++++++++--- api/src/main/resources/hibernate.cfg.xml | 3 +- .../api/db/hibernate/AllergyReaction.hbm.xml | 30 ----------------- .../org/openmrs/api/OrderServiceTest.java | 2 ++ 4 files changed, 32 insertions(+), 36 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/AllergyReaction.hbm.xml diff --git a/api/src/main/java/org/openmrs/AllergyReaction.java b/api/src/main/java/org/openmrs/AllergyReaction.java index 28d5e416e95c..e087d87ccd13 100644 --- a/api/src/main/java/org/openmrs/AllergyReaction.java +++ b/api/src/main/java/org/openmrs/AllergyReaction.java @@ -10,24 +10,49 @@ package org.openmrs; import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; import org.hibernate.envers.Audited; import org.openmrs.util.OpenmrsUtil; +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; + /** * Represent allergy reactions */ +@Entity +@Table(name = "allergy_reaction") @Audited public class AllergyReaction extends BaseOpenmrsObject implements java.io.Serializable{ public static final long serialVersionUID = 1; - + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "allergy_reaction_id_seq") + @GenericGenerator( + name = "allergy_reaction_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "allergy_reaction_allergy_reaction_id_seq") + ) + @Column(name = "allergy_reaction_id") private Integer allergyReactionId; - + + @ManyToOne + @JoinColumn(name = "allergy_id", nullable = false) private Allergy allergy; - + + @ManyToOne + @JoinColumn(name = "reaction_concept_id", nullable = false) private Concept reaction; - + + @Column(name = "reaction_non_coded") private String reactionNonCoded; /** diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..fc645d164ea8 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -21,8 +21,7 @@ org.openmrs.api.db.hibernate.search.LuceneAnalyzerFactory - - + diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/AllergyReaction.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/AllergyReaction.hbm.xml deleted file mode 100644 index 087d9d966074..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/AllergyReaction.hbm.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - allergy_reaction_allergy_reaction_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..325ee8e3720f 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test; import org.openmrs.Allergy; +import org.openmrs.AllergyReaction; import org.openmrs.CareSetting; import org.openmrs.Concept; import org.openmrs.ConceptClass; @@ -2740,6 +2741,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) .addAnnotatedClass(OrderType.class) + .addAnnotatedClass(AllergyReaction.class) .getMetadataBuilder().build();