From b95c4a11d19a94f0393d62c2a70147fc83b09e5b Mon Sep 17 00:00:00 2001 From: UNCANNY69 Date: Tue, 24 Dec 2024 23:54:02 +0530 Subject: [PATCH 1/3] TRUNK-5922 Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain. --- .../java/org/openmrs/DrugReferenceMap.java | 87 ++++++++++++------- api/src/main/resources/hibernate.cfg.xml | 1 - .../api/db/hibernate/DrugReferenceMap.hbm.xml | 42 --------- .../org/openmrs/api/OrderServiceTest.java | 2 + 4 files changed, 60 insertions(+), 72 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml diff --git a/api/src/main/java/org/openmrs/DrugReferenceMap.java b/api/src/main/java/org/openmrs/DrugReferenceMap.java index bd28135ea9a6..4c4aab24b96d 100644 --- a/api/src/main/java/org/openmrs/DrugReferenceMap.java +++ b/api/src/main/java/org/openmrs/DrugReferenceMap.java @@ -12,45 +12,74 @@ import java.io.Serializable; import java.util.Date; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.Audited; import org.hibernate.search.annotations.ContainedIn; import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.IndexedEmbedded; +import org.hibernate.annotations.CascadeType; + +import javax.persistence.*; /** * The DrugReferenceMap map object represents a mapping between a drug and alternative drug * terminologies. - * + * * @since 1.10 */ +@Entity +@Table(name="drug_reference_map") @Audited public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Serializable { - + public static final long serialVersionUID = 1L; - + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "drug_reference_map_id_seq") + @GenericGenerator( + name = "drug_reference_map_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "drug_reference_map_drug_reference_map_id_seq") + ) @DocumentId + @Column(name = "drug_reference_map_id") private Integer drugReferenceMapId; - + + @ManyToOne + @JoinColumn(name = "drug_id", nullable = false) @ContainedIn private Drug drug; - + + @ManyToOne + @JoinColumn(name = "term_id", nullable = false) + @Cascade(CascadeType.SAVE_UPDATE) @IndexedEmbedded(includeEmbeddedObjectId = true) private ConceptReferenceTerm conceptReferenceTerm; - + + @ManyToOne + @JoinColumn(name = "concept_map_type", nullable = false) private ConceptMapType conceptMapType; - + + @ManyToOne + @JoinColumn(name = "creator", nullable = false) private User creator; - + + @Column(name = "date_created", nullable = false, length = 19) private Date dateCreated; + @ManyToOne + @JoinColumn(name = "changed_by") private User changedBy; - + + @Column(name = "date_changed", length = 19) private Date dateChanged; - + /** default constructor */ public DrugReferenceMap() { } - + /** * @param term * @param conceptMapType @@ -59,63 +88,63 @@ public DrugReferenceMap(ConceptReferenceTerm term, ConceptMapType conceptMapType this.conceptReferenceTerm = term; this.conceptMapType = conceptMapType; } - + /** * @return Returns the drugReferenceMapId. */ public Integer getDrugReferenceMapId() { return drugReferenceMapId; } - + /** * @param drugReferenceMapId The drugReferenceMapId to set. */ public void setDrugReferenceMapId(Integer drugReferenceMapId) { this.drugReferenceMapId = drugReferenceMapId; } - + /** * @return Returns the drug. */ public Drug getDrug() { return drug; } - + /** * @param drug The drug to set. */ public void setDrug(Drug drug) { this.drug = drug; } - + /** * @return Returns the conceptReferenceTerm. */ public ConceptReferenceTerm getConceptReferenceTerm() { return conceptReferenceTerm; } - + /** * @param conceptReferenceTerm The conceptReferenceTerm to set. */ public void setConceptReferenceTerm(ConceptReferenceTerm conceptReferenceTerm) { this.conceptReferenceTerm = conceptReferenceTerm; } - + /** * @return Returns the conceptMapType. */ public ConceptMapType getConceptMapType() { return conceptMapType; } - + /** * @param conceptMapType The conceptMapType to set. */ public void setConceptMapType(ConceptMapType conceptMapType) { this.conceptMapType = conceptMapType; } - + /** * @return id - The unique Identifier for the object */ @@ -123,7 +152,7 @@ public void setConceptMapType(ConceptMapType conceptMapType) { public Integer getId() { return getDrugReferenceMapId(); } - + /** * @param id - The unique Identifier for the object */ @@ -131,7 +160,7 @@ public Integer getId() { public void setId(Integer id) { setDrugReferenceMapId(id); } - + /** * @return User - the user who created the object */ @@ -139,7 +168,7 @@ public void setId(Integer id) { public User getCreator() { return this.creator; } - + /** * @param creator - the user who created the object */ @@ -147,7 +176,7 @@ public User getCreator() { public void setCreator(User creator) { this.creator = creator; } - + /** * @return Date - the date the object was created */ @@ -155,7 +184,7 @@ public void setCreator(User creator) { public Date getDateCreated() { return dateCreated; } - + /** * @param dateCreated - the date the object was created */ @@ -163,7 +192,7 @@ public Date getDateCreated() { public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; } - + /** * @return User - the user who last changed the object */ @@ -171,7 +200,7 @@ public void setDateCreated(Date dateCreated) { public User getChangedBy() { return this.changedBy; } - + /** * @param changedBy - the user who last changed the object */ @@ -179,7 +208,7 @@ public User getChangedBy() { public void setChangedBy(User changedBy) { this.changedBy = changedBy; } - + /** * @return Date - the date the object was last changed */ @@ -187,7 +216,7 @@ public void setChangedBy(User changedBy) { public Date getDateChanged() { return this.dateChanged; } - + /** * @param dateChanged - the date the object was last changed */ diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..1cad8cc6aa43 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -43,7 +43,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml deleted file mode 100644 index 5248f9dde87b..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - drug_reference_map_drug_reference_map_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..12f636a67082 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -32,6 +32,7 @@ import org.openmrs.Condition; import org.openmrs.Diagnosis; import org.openmrs.Drug; +import org.openmrs.DrugReferenceMap; import org.openmrs.DrugIngredient; import org.openmrs.DrugOrder; import org.openmrs.Encounter; @@ -2735,6 +2736,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(SerializedObject.class) .addAnnotatedClass(PatientState.class) .addAnnotatedClass(DrugIngredient.class) + .addAnnotatedClass(DrugReferenceMap.class) .addAnnotatedClass(AlertRecipient.class) .addAnnotatedClass(PatientIdentifierType.class) .addAnnotatedClass(ProgramAttributeType.class) From 7ca5140c39064a40df20d02c30f6d54910a9af79 Mon Sep 17 00:00:00 2001 From: UNCANNY69 Date: Wed, 25 Dec 2024 17:38:59 +0530 Subject: [PATCH 2/3] TRUNK-5922 Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain. --- api/src/main/java/org/openmrs/DrugReferenceMap.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/DrugReferenceMap.java b/api/src/main/java/org/openmrs/DrugReferenceMap.java index 4c4aab24b96d..ced2b03431d0 100644 --- a/api/src/main/java/org/openmrs/DrugReferenceMap.java +++ b/api/src/main/java/org/openmrs/DrugReferenceMap.java @@ -9,6 +9,14 @@ */ package org.openmrs; +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 java.io.Serializable; import java.util.Date; @@ -21,7 +29,7 @@ import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.annotations.CascadeType; -import javax.persistence.*; + /** * The DrugReferenceMap map object represents a mapping between a drug and alternative drug From 74ae4b12018ae4a2efea92c78d6c2cc482abc74b Mon Sep 17 00:00:00 2001 From: UNCANNY69 Date: Thu, 26 Dec 2024 13:22:14 +0530 Subject: [PATCH 3/3] TRUNK-5922 Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain. --- api/src/main/java/org/openmrs/DrugReferenceMap.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/src/main/java/org/openmrs/DrugReferenceMap.java b/api/src/main/java/org/openmrs/DrugReferenceMap.java index ced2b03431d0..af1f145ae4fb 100644 --- a/api/src/main/java/org/openmrs/DrugReferenceMap.java +++ b/api/src/main/java/org/openmrs/DrugReferenceMap.java @@ -29,8 +29,6 @@ import org.hibernate.search.annotations.IndexedEmbedded; import org.hibernate.annotations.CascadeType; - - /** * The DrugReferenceMap map object represents a mapping between a drug and alternative drug * terminologies.