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-5924 : PatientIdentifier Domain - Switching from Hibernate Mappings to Annotations #4855

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
33 changes: 31 additions & 2 deletions api/src/main/java/org/openmrs/PatientIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
import org.openmrs.util.OpenmrsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.Column;
import javax.persistence.Entity;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
* A <code>Patient</code> can have zero to n identifying PatientIdentifier(s). PatientIdentifiers
Expand All @@ -37,6 +47,8 @@
*
* @see org.openmrs.PatientIdentifierType
*/
@Entity
@Table(name = "patient_identifier")
@Indexed
rishabhrawat05 marked this conversation as resolved.
Show resolved Hide resolved
@Audited
public class PatientIdentifier extends BaseChangeableOpenmrsData implements java.io.Serializable, Cloneable, Comparable<PatientIdentifier> {
Expand All @@ -51,9 +63,19 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java
* @since 1.5
*/
@DocumentId
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "patient_identifier_id_seq")
@GenericGenerator(
name = "patient_identifier_id_seq",
strategy = "native",
parameters = @Parameter(name = "sequence", value = "patient_identifier_patient_identifier_id_seq")
)
@Column(name = "patient_identifier_id")
private Integer patientIdentifierId;

@IndexedEmbedded(includeEmbeddedObjectId = true)
@ManyToOne
@JoinColumn(name = "patient_id")
rishabhrawat05 marked this conversation as resolved.
Show resolved Hide resolved
private Patient patient;

@Fields({
Expand All @@ -63,17 +85,24 @@ public class PatientIdentifier extends BaseChangeableOpenmrsData implements java
@Field(name = "identifierAnywhere", analyzer = @Analyzer(definition = LuceneAnalyzers.ANYWHERE_ANALYZER))
})
@SortableField(forField = "identifierExact")
@Column(name = "identifier", length = 50)
private String identifier;

@IndexedEmbedded(includeEmbeddedObjectId = true)
@ManyToOne
@JoinColumn(name = "identifier_type")
rishabhrawat05 marked this conversation as resolved.
Show resolved Hide resolved
private PatientIdentifierType identifierType;

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

@ManyToOne
@JoinColumn(name = "patient_program_id", nullable = true)
private PatientProgram patientProgram;


@Field
rishabhrawat05 marked this conversation as resolved.
Show resolved Hide resolved
@Column(name = "preferred", nullable = false)
private Boolean preferred = false;

/** default constructor */
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 @@ -59,7 +59,6 @@
<mapping resource="org/openmrs/api/db/hibernate/Privilege.hbm.xml" />
<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/RelationshipType.hbm.xml" />
Expand Down Expand Up @@ -113,4 +112,4 @@
<mapping class="org.openmrs.ConceptReferenceRange"/>
</session-factory>

</hibernate-configuration>
</hibernate-configuration>

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 @@ -52,6 +52,7 @@
import org.openmrs.OrderSet;
import org.openmrs.OrderType;
import org.openmrs.Patient;
import org.openmrs.PatientIdentifier;
import org.openmrs.PatientIdentifierType;
import org.openmrs.PatientState;
import org.openmrs.PersonAddress;
Expand Down Expand Up @@ -2740,6 +2741,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(ProgramAttributeType.class)
.addAnnotatedClass(HL7InError.class)
.addAnnotatedClass(OrderType.class)
.addAnnotatedClass(PatientIdentifier.class)
.getMetadataBuilder().build();


Expand Down