Skip to content

TRUNK-5881: Order Domain - Switching from Hibernate Mappings to Annotations #4996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions api/src/main/java/org/openmrs/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
import org.openmrs.util.OpenmrsUtil;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
* Encapsulates information about the clinical action of a provider requesting something for a
Expand All @@ -32,6 +49,8 @@
* @version 1.0
*/
@Audited
@Entity
@Table(name = "orders")
public class Order extends BaseCustomizableData<OrderAttribute> implements FormRecordable {

public static final long serialVersionUID = 4334343L;
Expand Down Expand Up @@ -69,80 +88,126 @@ public enum FulfillerStatus {
COMPLETED
}

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "orders_order_id")
@SequenceGenerator(name = "orders_order_id", sequenceName = "orders_order_id_seq", allocationSize = 1)
@Column(name = "order_id")
private Integer orderId;

@ManyToOne
@JoinColumn(name = "patient_id", nullable = false)
private Patient patient;

@ManyToOne
@JoinColumn(name = "order_type_id", nullable = false)
private OrderType orderType;


@ManyToOne
@JoinColumn(name = "concept_id", nullable = false)
private Concept concept;

@Column(name = "instructions", length = 65535)
private String instructions;


@Column(name = "date_activated", nullable = false)
private Date dateActivated;


@Column(name = "auto_expire_date")
private Date autoExpireDate;

@ManyToOne
@JoinColumn(name = "encounter_id", nullable = false)
private Encounter encounter;

@ManyToOne
@JoinColumn(name = "orderer", nullable = false)
private Provider orderer;

@Column(name = "date_stopped")
private Date dateStopped;

@ManyToOne
@JoinColumn(name = "order_reason")
private Concept orderReason;

@Column(name = "accession_number", length = 255)
private String accessionNumber;

@Column(name = "order_reason_non_coded", length = 255)
private String orderReasonNonCoded;

@Enumerated(EnumType.STRING)
@Column(name = "urgency", nullable = false)
private Urgency urgency = Urgency.ROUTINE;

@Column(name = "order_number", nullable = false, length = 50)
private String orderNumber;

@Column(name = "comment_to_fulfiller", length = 1024)
private String commentToFulfiller;

@ManyToOne
@JoinColumn(name = "care_setting", nullable = false)
private CareSetting careSetting;

@Column(name = "scheduled_date")
private Date scheduledDate;

@Column(name = "form_namespace_and_path", length = 255)
private String formNamespaceAndPath;

/**
* Allows the orders if ordered as an orderGroup, to maintain a sequence of how members are
* added in the group ex - for two orders of isoniazid and ampicillin, the sequence of 1 and 2
* needed to be maintained
*/
@Column(name = "sort_weight")
private Double sortWeight;

/**
* Allows orders to be linked to a previous order - e.g., an order discontinue ampicillin linked
* to the original ampicillin order (the D/C gets its own order number)
*/
@ManyToOne
@JoinColumn(name = "previous_order_id")
private Order previousOrder;

/**
* Represents the action being taken on an order.
*
* @see org.openmrs.Order.Action
*/
@Enumerated(EnumType.STRING)
@Column(name = "action", nullable = false)
private Action action = Action.NEW;

/**
* {@link org.openmrs.OrderGroup}
*/
@ManyToOne
@JoinColumn(name = "order_group_id")
private OrderGroup orderGroup;

/**
* Represents the status of an order received from a fulfiller
* @see FulfillerStatus
*/
@Enumerated(EnumType.STRING)
@Column(name = "fulfiller_status", nullable = false)
private FulfillerStatus fulfillerStatus;

/**
* Represents the comment that goes along with with fulfiller status
*/
@Column(name = "fulfiller_comment", length = 1024)
private String fulfillerComment;

@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("voided asc")
private Set<OrderAttribute> attributes = new LinkedHashSet<>();


// Constructors

/** default constructor */
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 @@ -62,7 +62,6 @@
<mapping resource="org/openmrs/api/db/hibernate/PatientProgram.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/PatientProgramAttribute.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/RelationshipType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Order.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderAttribute.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderAttributeType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderSet.hbm.xml" />
Expand Down
167 changes: 0 additions & 167 deletions api/src/main/resources/org/openmrs/api/db/hibernate/Order.hbm.xml

This file was deleted.

1 change: 1 addition & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(ProgramAttributeType.class)
.addAnnotatedClass(HL7InError.class)
.addAnnotatedClass(OrderType.class)
.addAnnotatedClass(Order.class)
.getMetadataBuilder().build();


Expand Down