Skip to content

Commit

Permalink
Trunk-5661:Replace Allergy hbm mapping file with annotations (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcliff authored and wluyima committed Oct 8, 2019
1 parent 55e0f2d commit 9dc05ff
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 55 deletions.
13 changes: 13 additions & 0 deletions api/src/main/java/org/openmrs/Allergen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@
*/
package org.openmrs;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.apache.commons.lang3.StringUtils;

/**
* Represent allergen
*/
@Embeddable
public class Allergen {

@Enumerated(EnumType.STRING)
@Column(name = "allergen_type")
private AllergenType allergenType;

@ManyToOne(optional = false)
@JoinColumn(name = "coded_allergen")
private Concept codedAllergen;

@Column(name = "non_coded_allergen")
private String nonCodedAllergen;

private static String OTHER_NON_CODED_CONCEPT_UUID;
Expand Down
29 changes: 28 additions & 1 deletion api/src/main/java/org/openmrs/Allergy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,53 @@
import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.openmrs.util.OpenmrsUtil;

/**
* Represent allergy
*/
@Entity
@Table(name = "allergy")
public class Allergy extends BaseChangeableOpenmrsData {

public static final long serialVersionUID = 1;

@Id
@GeneratedValue
@Column(name = "allergy_id")
private Integer allergyId;

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

@Embedded
private Allergen allergen;

@ManyToOne
@JoinColumn(name = "severity_concept_id")
private Concept severity;

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


@OneToMany(mappedBy = "allergy", cascade = CascadeType.ALL, orphanRemoval = true)
@LazyCollection(LazyCollectionOption.FALSE)
private List<AllergyReaction> reactions = new ArrayList<>();

/**
Expand All @@ -44,7 +71,7 @@ public Allergy(){
}

/**
* @param patient the patient to set
* @param patient the patient to set.
* @param allergen the allergen to set
* @param severity the severity to set
* @param comment the comment to set
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<session-factory>
<property name="javax.persistence.validation.mode">none</property>
<!-- API -->
<mapping resource="org/openmrs/api/db/hibernate/Allergy.hbm.xml" />

<mapping resource="org/openmrs/api/db/hibernate/AllergyReaction.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Concept.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ConceptAnswer.hbm.xml" />
Expand Down

This file was deleted.

0 comments on commit 9dc05ff

Please sign in to comment.