Skip to content
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

TRUNK-5841 : PatientProgram Domain - Switching from Hibernate Mappings to Annotations #4857

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
51 changes: 50 additions & 1 deletion api/src/main/java/org/openmrs/PatientProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package org.openmrs;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.envers.Audited;
import org.openmrs.customdatatype.CustomValueDescriptor;
import org.openmrs.customdatatype.Customizable;
Expand All @@ -25,9 +27,24 @@
import java.util.Map;
import java.util.Set;

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.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
* PatientProgram
*/
@Entity
@Table(name = "patient_program")
@Audited
public class PatientProgram extends BaseChangeableOpenmrsData implements Customizable<PatientProgramAttribute>{

Expand All @@ -36,23 +53,55 @@ public class PatientProgram extends BaseChangeableOpenmrsData implements Customi
// ******************
// Properties
// ******************

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "")
rishabhrawat05 marked this conversation as resolved.
Show resolved Hide resolved
@GenericGenerator(
name = "patient_program_id_seq",
strategy = "native",
parameters = @Parameter(name = "sequence", value = "patient_program_patient_program_id_seq")
)
@Column(name = "patient_program_id")
rishabhrawat05 marked this conversation as resolved.
Show resolved Hide resolved
private Integer patientProgramId;

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

@ManyToOne
@JoinColumn(name = "program_id", nullable = false)
private Program program;

@ManyToOne
@JoinColumn(name = "location_id")
private Location location;

@Column(name = "date_enrolled", nullable = true)
private Date dateEnrolled;

@Column(name = "date_completed", nullable = true)
private Date dateCompleted;

@ManyToOne
@JoinColumn(name = "outcome_concept_id", nullable = true)
private Concept outcome;


@OneToMany
@JoinTable(
name = "patient_state_set",
joinColumns = @JoinColumn(name = "patient_program_id", nullable = false),
inverseJoinColumns = @JoinColumn(name = "patient_state_id"),
uniqueConstraints = @UniqueConstraint(columnNames = {"patient_program_id","patient_state_id"})
)
private Set<PatientState> states = new HashSet<>();

@OneToMany
@JoinTable(
name = "patient_attribute_set",
joinColumns = @JoinColumn(name = "patient_program_id"),
inverseJoinColumns = @JoinColumn(name = "patient_program_attribute_id"),
uniqueConstraints = @UniqueConstraint(columnNames = {"patient_program_id","patient_program_attribute_id"})
)
private Set<PatientProgramAttribute> attributes = new LinkedHashSet<>();

// ******************
Expand Down
3 changes: 1 addition & 2 deletions api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
<mapping resource="org/openmrs/api/db/hibernate/Role.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Patient.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/PatientIdentifier.hbm.xml" />
<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/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" />
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 @@ -53,6 +53,7 @@
import org.openmrs.OrderType;
import org.openmrs.Patient;
import org.openmrs.PatientIdentifierType;
import org.openmrs.PatientProgram;
import org.openmrs.PatientState;
import org.openmrs.PersonAddress;
import org.openmrs.PersonAttributeType;
Expand Down Expand Up @@ -2740,6 +2741,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(ProgramAttributeType.class)
.addAnnotatedClass(HL7InError.class)
.addAnnotatedClass(OrderType.class)
.addAnnotatedClass(PatientProgram.class)
.getMetadataBuilder().build();


Expand Down