Skip to content
Open
29 changes: 26 additions & 3 deletions api/src/main/java/org/openmrs/Cohort.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
package org.openmrs;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.envers.Audited;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
Expand All @@ -22,17 +32,30 @@
/**
* This class represents a list of patientIds.
*/
@Entity
@Table(name = "cohort")
@Audited
public class Cohort extends BaseChangeableOpenmrsData {

public static final long serialVersionUID = 0L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "cohort_id_seq")
@GenericGenerator(
name = "cohort_id_seq",
strategy = "native",
parameters = @Parameter(name = "sequence", value = "cohort_cohort_id_seq")
)
@Column(name = "cohort_id", nullable = false)
private Integer cohortId;

@Column(name = "name", nullable = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you just forget to specify the length as was in the xml mapping file?

private String name;

@Column(name = "description", nullable = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the length?

private String description;

@OneToMany(mappedBy = "cohort", cascade = CascadeType.ALL, orphanRemoval = true)
private Collection<CohortMembership> memberships;

public Cohort() {
Expand Down Expand Up @@ -349,12 +372,12 @@ public void setMemberIds(Set<Integer> memberIds) {
}

public void setMemberships(Collection<CohortMembership> members) {
this.memberships = members;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something minor. Do we need the space here :) ?

this.memberships = members;
}

/**
* @since 1.5
* @see org.openmrs.OpenmrsObject#getId()
* @see OpenmrsObject#getId()
*/
@Override
public Integer getId() {
Expand All @@ -364,7 +387,7 @@ public Integer getId() {

/**
* @since 1.5
* @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
* @see OpenmrsObject#setId(Integer)
*/
@Override
public void setId(Integer id) {
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 @@ -82,7 +82,6 @@
<mapping resource="org/openmrs/api/db/hibernate/Program.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ProgramWorkflow.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ProgramWorkflowState.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/OrderFrequency.hbm.xml" />

Expand Down
55 changes: 0 additions & 55 deletions api/src/main/resources/org/openmrs/api/db/hibernate/Cohort.hbm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion api/src/test/java/org/openmrs/CohortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void constructorWithCommaSeparatedIntegers_shouldAddMembersToCohort() {
@Test
public void getCommaSeparatedPatientIds_shouldReturnCommaSeparatedListOfPatients() {

List<Patient> patients = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change required as part of the ticket?

Set<Patient> patients = new HashSet<>();
Arrays.stream(ids).forEach(id -> patients.add(new Patient(id)));

Cohort cohort = new Cohort("name", "description", patients);
Expand Down
1 change: 1 addition & 0 deletions api/src/test/java/org/openmrs/api/CohortServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.time.DateUtils;
import org.junit.jupiter.api.BeforeEach;
Expand Down
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 @@ -21,6 +21,7 @@

import org.openmrs.Allergy;
import org.openmrs.CareSetting;
import org.openmrs.Cohort;
import org.openmrs.Concept;
import org.openmrs.ConceptClass;
import org.openmrs.ConceptDatatype;
Expand Down Expand Up @@ -2740,6 +2741,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(ProgramAttributeType.class)
.addAnnotatedClass(HL7InError.class)
.addAnnotatedClass(OrderType.class)
.addAnnotatedClass(Cohort.class)
.getMetadataBuilder().build();


Expand Down
Loading