Skip to content

Commit b8e01bb

Browse files
authored
Trunk 5922: Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain (#4878)
* TRUNK-5922 Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain. * TRUNK-5922 Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain. * TRUNK-5922 Switching from Hibernate Mappings to Annotations for DrugReferenceMap Domain.
1 parent bd51faf commit b8e01bb

File tree

4 files changed

+66
-72
lines changed

4 files changed

+66
-72
lines changed

api/src/main/java/org/openmrs/DrugReferenceMap.java

+64-29
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,83 @@
99
*/
1010
package org.openmrs;
1111

12+
import javax.persistence.Column;
13+
import javax.persistence.Entity;
14+
import javax.persistence.GeneratedValue;
15+
import javax.persistence.GenerationType;
16+
import javax.persistence.Id;
17+
import javax.persistence.JoinColumn;
18+
import javax.persistence.ManyToOne;
19+
import javax.persistence.Table;
1220
import java.io.Serializable;
1321
import java.util.Date;
1422

23+
import org.hibernate.annotations.Cascade;
24+
import org.hibernate.annotations.Parameter;
25+
import org.hibernate.annotations.GenericGenerator;
1526
import org.hibernate.envers.Audited;
1627
import org.hibernate.search.annotations.ContainedIn;
1728
import org.hibernate.search.annotations.DocumentId;
1829
import org.hibernate.search.annotations.IndexedEmbedded;
30+
import org.hibernate.annotations.CascadeType;
1931

2032
/**
2133
* The DrugReferenceMap map object represents a mapping between a drug and alternative drug
2234
* terminologies.
23-
*
35+
*
2436
* @since 1.10
2537
*/
38+
@Entity
39+
@Table(name="drug_reference_map")
2640
@Audited
2741
public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Serializable {
28-
42+
2943
public static final long serialVersionUID = 1L;
30-
44+
45+
@Id
46+
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "drug_reference_map_id_seq")
47+
@GenericGenerator(
48+
name = "drug_reference_map_id_seq",
49+
strategy = "native",
50+
parameters = @Parameter(name = "sequence", value = "drug_reference_map_drug_reference_map_id_seq")
51+
)
3152
@DocumentId
53+
@Column(name = "drug_reference_map_id")
3254
private Integer drugReferenceMapId;
33-
55+
56+
@ManyToOne
57+
@JoinColumn(name = "drug_id", nullable = false)
3458
@ContainedIn
3559
private Drug drug;
36-
60+
61+
@ManyToOne
62+
@JoinColumn(name = "term_id", nullable = false)
63+
@Cascade(CascadeType.SAVE_UPDATE)
3764
@IndexedEmbedded(includeEmbeddedObjectId = true)
3865
private ConceptReferenceTerm conceptReferenceTerm;
39-
66+
67+
@ManyToOne
68+
@JoinColumn(name = "concept_map_type", nullable = false)
4069
private ConceptMapType conceptMapType;
41-
70+
71+
@ManyToOne
72+
@JoinColumn(name = "creator", nullable = false)
4273
private User creator;
43-
74+
75+
@Column(name = "date_created", nullable = false, length = 19)
4476
private Date dateCreated;
4577

78+
@ManyToOne
79+
@JoinColumn(name = "changed_by")
4680
private User changedBy;
47-
81+
82+
@Column(name = "date_changed", length = 19)
4883
private Date dateChanged;
49-
84+
5085
/** default constructor */
5186
public DrugReferenceMap() {
5287
}
53-
88+
5489
/**
5590
* @param term
5691
* @param conceptMapType
@@ -59,135 +94,135 @@ public DrugReferenceMap(ConceptReferenceTerm term, ConceptMapType conceptMapType
5994
this.conceptReferenceTerm = term;
6095
this.conceptMapType = conceptMapType;
6196
}
62-
97+
6398
/**
6499
* @return Returns the drugReferenceMapId.
65100
*/
66101
public Integer getDrugReferenceMapId() {
67102
return drugReferenceMapId;
68103
}
69-
104+
70105
/**
71106
* @param drugReferenceMapId The drugReferenceMapId to set.
72107
*/
73108
public void setDrugReferenceMapId(Integer drugReferenceMapId) {
74109
this.drugReferenceMapId = drugReferenceMapId;
75110
}
76-
111+
77112
/**
78113
* @return Returns the drug.
79114
*/
80115
public Drug getDrug() {
81116
return drug;
82117
}
83-
118+
84119
/**
85120
* @param drug The drug to set.
86121
*/
87122
public void setDrug(Drug drug) {
88123
this.drug = drug;
89124
}
90-
125+
91126
/**
92127
* @return Returns the conceptReferenceTerm.
93128
*/
94129
public ConceptReferenceTerm getConceptReferenceTerm() {
95130
return conceptReferenceTerm;
96131
}
97-
132+
98133
/**
99134
* @param conceptReferenceTerm The conceptReferenceTerm to set.
100135
*/
101136
public void setConceptReferenceTerm(ConceptReferenceTerm conceptReferenceTerm) {
102137
this.conceptReferenceTerm = conceptReferenceTerm;
103138
}
104-
139+
105140
/**
106141
* @return Returns the conceptMapType.
107142
*/
108143
public ConceptMapType getConceptMapType() {
109144
return conceptMapType;
110145
}
111-
146+
112147
/**
113148
* @param conceptMapType The conceptMapType to set.
114149
*/
115150
public void setConceptMapType(ConceptMapType conceptMapType) {
116151
this.conceptMapType = conceptMapType;
117152
}
118-
153+
119154
/**
120155
* @return id - The unique Identifier for the object
121156
*/
122157
@Override
123158
public Integer getId() {
124159
return getDrugReferenceMapId();
125160
}
126-
161+
127162
/**
128163
* @param id - The unique Identifier for the object
129164
*/
130165
@Override
131166
public void setId(Integer id) {
132167
setDrugReferenceMapId(id);
133168
}
134-
169+
135170
/**
136171
* @return User - the user who created the object
137172
*/
138173
@Override
139174
public User getCreator() {
140175
return this.creator;
141176
}
142-
177+
143178
/**
144179
* @param creator - the user who created the object
145180
*/
146181
@Override
147182
public void setCreator(User creator) {
148183
this.creator = creator;
149184
}
150-
185+
151186
/**
152187
* @return Date - the date the object was created
153188
*/
154189
@Override
155190
public Date getDateCreated() {
156191
return dateCreated;
157192
}
158-
193+
159194
/**
160195
* @param dateCreated - the date the object was created
161196
*/
162197
@Override
163198
public void setDateCreated(Date dateCreated) {
164199
this.dateCreated = dateCreated;
165200
}
166-
201+
167202
/**
168203
* @return User - the user who last changed the object
169204
*/
170205
@Override
171206
public User getChangedBy() {
172207
return this.changedBy;
173208
}
174-
209+
175210
/**
176211
* @param changedBy - the user who last changed the object
177212
*/
178213
@Override
179214
public void setChangedBy(User changedBy) {
180215
this.changedBy = changedBy;
181216
}
182-
217+
183218
/**
184219
* @return Date - the date the object was last changed
185220
*/
186221
@Override
187222
public Date getDateChanged() {
188223
return this.dateChanged;
189224
}
190-
225+
191226
/**
192227
* @param dateChanged - the date the object was last changed
193228
*/

api/src/main/resources/hibernate.cfg.xml

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<mapping resource="org/openmrs/api/db/hibernate/DiagnosisAttribute.hbm.xml" />
4444
<mapping resource="org/openmrs/api/db/hibernate/DiagnosisAttributeType.hbm.xml" />
4545
<mapping resource="org/openmrs/api/db/hibernate/Drug.hbm.xml" />
46-
<mapping resource="org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml" />
4746
<mapping resource="org/openmrs/api/db/hibernate/Field.hbm.xml" />
4847
<mapping resource="org/openmrs/api/db/hibernate/FieldType.hbm.xml" />
4948
<mapping resource="org/openmrs/api/db/hibernate/Form.hbm.xml" />

api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml

-42
This file was deleted.

api/src/test/java/org/openmrs/api/OrderServiceTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openmrs.Condition;
3333
import org.openmrs.Diagnosis;
3434
import org.openmrs.Drug;
35+
import org.openmrs.DrugReferenceMap;
3536
import org.openmrs.DrugIngredient;
3637
import org.openmrs.DrugOrder;
3738
import org.openmrs.Encounter;
@@ -2735,6 +2736,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
27352736
.addAnnotatedClass(SerializedObject.class)
27362737
.addAnnotatedClass(PatientState.class)
27372738
.addAnnotatedClass(DrugIngredient.class)
2739+
.addAnnotatedClass(DrugReferenceMap.class)
27382740
.addAnnotatedClass(AlertRecipient.class)
27392741
.addAnnotatedClass(PatientIdentifierType.class)
27402742
.addAnnotatedClass(ProgramAttributeType.class)

0 commit comments

Comments
 (0)