From a2064a242602942212f75608bfec5b968cebf627 Mon Sep 17 00:00:00 2001 From: Wikum Weerakutti Date: Fri, 25 Oct 2024 00:43:12 +0530 Subject: [PATCH] TRUNK-6277: Migrate HL7InError from Hibernate Mapping XML to JPA annotatoions. (#4795) --- .../main/java/org/openmrs/hl7/HL7InError.java | 29 +++++++++-- .../java/org/openmrs/hl7/HL7QueueItem.java | 19 ++++++- .../hl7/db/hibernate/HibernateHL7DAO.java | 2 +- api/src/main/resources/hibernate.cfg.xml | 1 - .../hl7/db/hibernate/HL7InError.hbm.xml | 51 ------------------- .../org/openmrs/api/OrderServiceTest.java | 2 + 6 files changed, 46 insertions(+), 58 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7InError.hbm.xml diff --git a/api/src/main/java/org/openmrs/hl7/HL7InError.java b/api/src/main/java/org/openmrs/hl7/HL7InError.java index a2eb90dfdaca..e2c64f83e564 100644 --- a/api/src/main/java/org/openmrs/hl7/HL7InError.java +++ b/api/src/main/java/org/openmrs/hl7/HL7InError.java @@ -9,24 +9,47 @@ */ package org.openmrs.hl7; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; import org.hibernate.envers.Audited; import org.openmrs.api.APIException; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + /** - * Represents a error in processing an hl7 message. + * Represents an error in processing an hl7 message. * * @see HL7InQueue * @see HL7Service */ +@Entity +@Table(name = "hl7_in_error") @Audited public class HL7InError extends HL7QueueItem { private static final int MAX_ERROR_DETAILS_LENGTH = 16777215; - + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hl7_in_error_id_seq") + @GenericGenerator( + name = "hl7_in_error_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "hl7_in_error_hl7_in_error_id_seq") + ) + @Column(name = "hl7_in_error_id", nullable = false) private Integer hl7InErrorId; - + + @Column(name = "error", nullable = false) private String error; + @Column(name = "error_details", columnDefinition = "mediumtext") + @Lob private String errorDetails; /** diff --git a/api/src/main/java/org/openmrs/hl7/HL7QueueItem.java b/api/src/main/java/org/openmrs/hl7/HL7QueueItem.java index 4b20ac210026..087bf00451f0 100644 --- a/api/src/main/java/org/openmrs/hl7/HL7QueueItem.java +++ b/api/src/main/java/org/openmrs/hl7/HL7QueueItem.java @@ -11,8 +11,15 @@ import java.util.Date; +import org.hibernate.envers.Audited; import org.openmrs.BaseOpenmrsObject; +import javax.persistence.Column; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; + /** * Common representation of {@link HL7InQueue}, {@link HL7InArchive} and {@link HL7InError}. * @@ -21,14 +28,22 @@ * @see HL7InArchive * @see HL7InError */ +@MappedSuperclass +@Audited public abstract class HL7QueueItem extends BaseOpenmrsObject { - + + @ManyToOne(optional = false) + @JoinColumn(name = "hl7_source") private HL7Source hl7Source; + @Column(name = "hl7_source_key", length = 1024) private String hl7SourceKey; + @Column(name = "hl7_data", nullable = false, columnDefinition = "text") + @Lob private String hl7Data; - + + @Column(name = "date_created", nullable = false, length = 19) private Date dateCreated; /** diff --git a/api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java b/api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java index f3a99fa6f2a5..efffad372d9d 100644 --- a/api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java +++ b/api/src/main/java/org/openmrs/hl7/db/hibernate/HibernateHL7DAO.java @@ -348,7 +348,7 @@ public HL7InError getHL7InErrorByUuid(String uuid) throws DAOException { @Override @SuppressWarnings("unchecked") public List getAllHL7InErrors() throws DAOException { - return sessionFactory.getCurrentSession().createQuery("from HL7InError order by HL7InErrorId").list(); + return sessionFactory.getCurrentSession().createQuery("from HL7InError order by hl7InErrorId").list(); } /** diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 60ccdf2099b0..8bcc951d75b0 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -92,7 +92,6 @@ - diff --git a/api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7InError.hbm.xml b/api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7InError.hbm.xml deleted file mode 100644 index 194a2b470174..000000000000 --- a/api/src/main/resources/org/openmrs/hl7/db/hibernate/HL7InError.hbm.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - hl7_in_error_hl7_in_error_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 e47ce608ad47..c357f0d95101 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -72,6 +72,7 @@ import org.openmrs.api.db.hibernate.HibernateSessionFactoryBean; import org.openmrs.api.impl.OrderServiceImpl; import org.openmrs.customdatatype.datatype.FreeTextDatatype; +import org.openmrs.hl7.HL7InError; import org.openmrs.messagesource.MessageSourceService; import org.openmrs.notification.AlertRecipient; import org.openmrs.order.OrderUtil; @@ -2735,6 +2736,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(DrugIngredient.class) .addAnnotatedClass(AlertRecipient.class) .addAnnotatedClass(PatientIdentifierType.class) + .addAnnotatedClass(HL7InError.class) .getMetadataBuilder().build();