Skip to content

Commit

Permalink
TRUNK-6277: Migrate HL7InError from Hibernate Mapping XML to JPA anno…
Browse files Browse the repository at this point in the history
…tatoions. (#4795)
  • Loading branch information
wikumChamith authored Oct 24, 2024
1 parent 214c45a commit a2064a2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 58 deletions.
29 changes: 26 additions & 3 deletions api/src/main/java/org/openmrs/hl7/HL7InError.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
19 changes: 17 additions & 2 deletions api/src/main/java/org/openmrs/hl7/HL7QueueItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand All @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public HL7InError getHL7InErrorByUuid(String uuid) throws DAOException {
@Override
@SuppressWarnings("unchecked")
public List<HL7InError> getAllHL7InErrors() throws DAOException {
return sessionFactory.getCurrentSession().createQuery("from HL7InError order by HL7InErrorId").list();
return sessionFactory.getCurrentSession().createQuery("from HL7InError order by hl7InErrorId").list();
}

/**
Expand Down
1 change: 0 additions & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
<mapping resource="org/openmrs/hl7/db/hibernate/HL7Source.hbm.xml" />
<mapping resource="org/openmrs/hl7/db/hibernate/HL7InQueue.hbm.xml" />
<mapping resource="org/openmrs/hl7/db/hibernate/HL7InArchive.hbm.xml" />
<mapping resource="org/openmrs/hl7/db/hibernate/HL7InError.hbm.xml" />

<!-- Notification -->
<mapping resource="org/openmrs/notification/db/hibernate/Template.hbm.xml" />
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2735,6 +2736,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(DrugIngredient.class)
.addAnnotatedClass(AlertRecipient.class)
.addAnnotatedClass(PatientIdentifierType.class)
.addAnnotatedClass(HL7InError.class)
.getMetadataBuilder().build();


Expand Down

0 comments on commit a2064a2

Please sign in to comment.