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-5902: CohortMembership Domain - Switching from Hibernate Mappings to Annotations #3453

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion api/src/main/java/org/openmrs/CohortMembership.java
Expand Up @@ -14,21 +14,44 @@

import org.openmrs.util.OpenmrsUtil;

import javax.persistence.Access;
import javax.persistence.AccessType;
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 javax.persistence.Transient;

/**
* @since 2.1.0
*/
@Entity
@Table(name = "cohort_member")
public class CohortMembership extends BaseChangeableOpenmrsData implements Comparable<CohortMembership> {

public static final long serialVersionUID = 0L;

@Id
@Column(name = "cohort_member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer cohortMemberId;

@ManyToOne
@Access(AccessType.FIELD)
@JoinColumn(name = "cohort_id", nullable = false)
private Cohort cohort;

@Column(name = "patient_id", nullable = false)
private Integer patientId;

@Column(name = "start_date", nullable = false, length = 19)
private Date startDate;

@Column(name = "end_date", length = 19)
private Date endDate;

// Constructor
Expand Down Expand Up @@ -68,7 +91,19 @@ public Integer getId() {
public void setId(Integer id) {
setCohortMemberId(id);
}


@Transient
@Override
public Date getDateChanged() {
return super.getDateChanged();
}

@Transient
@Override
public User getChangedBy() {
return super.getChangedBy();
}

public Integer getCohortMemberId() {
return cohortMemberId;
}
Expand Down
1 change: 0 additions & 1 deletion api/src/main/resources/hibernate.cfg.xml
Expand Up @@ -90,7 +90,6 @@
<mapping resource="org/openmrs/api/db/hibernate/ProgramWorkflowState.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/PatientState.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Cohort.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/CohortMembership.hbm.xml"/>
<mapping resource="org/openmrs/api/db/hibernate/SerializedObject.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/OrderFrequency.hbm.xml" />

Expand Down

This file was deleted.

4 changes: 3 additions & 1 deletion api/src/test/java/org/openmrs/api/OrderServiceTest.java
Expand Up @@ -54,6 +54,7 @@
import org.junit.jupiter.api.Test;
import org.openmrs.Allergy;
import org.openmrs.CareSetting;
import org.openmrs.CohortMembership;
import org.openmrs.Concept;
import org.openmrs.ConceptClass;
import org.openmrs.ConceptDatatype;
Expand Down Expand Up @@ -2677,7 +2678,8 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
Metadata metaData = new MetadataSources(standardRegistry).addAnnotatedClass(Allergy.class)
.addAnnotatedClass(Encounter.class).addAnnotatedClass(SomeTestOrder.class)
.addAnnotatedClass(Diagnosis.class).addAnnotatedClass(Condition.class)
.addAnnotatedClass(Visit.class).getMetadataBuilder().build();
.addAnnotatedClass(Visit.class).addAnnotatedClass(CohortMembership.class)
.getMetadataBuilder().build();

Field field = adminDAO.getClass().getDeclaredField("metadata");
field.setAccessible(true);
Expand Down