Skip to content

Commit 45b70e2

Browse files
gitahingangawluyima
authored andcommittedJan 9, 2014
Add support for mapping drugs to other terminologies - TRINK-4143
Added the DrugReferenceMap class and its hibernate mapping XML file. - TRUNK-4143 Updated the Drug.java and Drug.hbm.xml to include references to the new DrugReferenceMap class. - TRUNK-4143 Fixed issues in liquibase-schema-only.xml. - TRUNK-4143 Added addDrugReferenceMap method to Drug.java. Minor code fixes and improvements to Drug.java. - TRUNK-4143 Minor improvements to Drug.hbm.xml. Changed serialVersionUuid in DrugReferenceMap.java to conform to convention. - TRUNK-4143 Code and documentation improvemment to the addDrugReferenceMap method of the Drug.java class. - TRUNK-4143 Moved the changeset to create the drug_reference_map table from liquibase-schema-only.xml to liquibase-update-to-latest.xml. - TRUNK-4143 Follow up due to bad conflict resolution - TRUNK-4143
1 parent 3863412 commit 45b70e2

File tree

7 files changed

+424
-7
lines changed

7 files changed

+424
-7
lines changed
 

‎api/src/main/java/org/openmrs/Drug.java

+43-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
*/
1414
package org.openmrs;
1515

16-
import java.util.Locale;
17-
1816
import org.apache.commons.lang.StringUtils;
17+
import org.openmrs.api.context.Context;
18+
19+
import java.util.HashSet;
20+
import java.util.Locale;
21+
import java.util.Set;
1922

2023
/**
2124
* Drug
@@ -43,6 +46,8 @@ public class Drug extends BaseOpenmrsMetadata implements java.io.Serializable {
4346
private String units;
4447

4548
private Concept concept;
49+
50+
private Set<DrugReferenceMap> drugReferenceMaps;
4651

4752
// Constructors
4853

@@ -235,4 +240,40 @@ public String getDisplayName() {
235240
return getConcept().getName().getName();
236241
return "";
237242
}
243+
244+
/**
245+
* @return Returns the drugReferenceMaps.
246+
* @since 1.10
247+
*/
248+
public Set<DrugReferenceMap> getDrugReferenceMaps() {
249+
if (drugReferenceMaps == null) {
250+
drugReferenceMaps = new HashSet<DrugReferenceMap>();
251+
}
252+
return drugReferenceMaps;
253+
}
254+
255+
/**
256+
* @param drugReferenceMaps The drugReferenceMaps to set.
257+
* @since 1.10
258+
*/
259+
public void setDrugReferenceMaps(Set<DrugReferenceMap> drugReferenceMaps) {
260+
this.drugReferenceMaps = drugReferenceMaps;
261+
}
262+
263+
/**
264+
* Add the given DrugReferenceMap object to this drug's list of drug reference mappings. If there is
265+
* already a corresponding DrugReferenceMap object for this concept, this one will not be added.
266+
*
267+
* @param drugReferenceMap
268+
* @since 1.10
269+
*/
270+
public void addDrugReferenceMap(DrugReferenceMap drugReferenceMap) {
271+
if (drugReferenceMap != null && !getDrugReferenceMaps().contains(drugReferenceMap)) {
272+
drugReferenceMap.setDrug(this);
273+
if (drugReferenceMap.getConceptMapType() == null) {
274+
drugReferenceMap.setConceptMapType(Context.getConceptService().getDefaultConceptMapType());
275+
}
276+
getDrugReferenceMaps() .add(drugReferenceMap);
277+
}
278+
}
238279
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
/**
2+
* The contents of this file are subject to the OpenMRS Public License
3+
* Version 1.0 (the "License"); you may not use this file except in
4+
* compliance with the License. You may obtain a copy of the License at
5+
* http://license.openmrs.org
6+
*
7+
* Software distributed under the License is distributed on an "AS IS"
8+
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9+
* License for the specific language governing rights and limitations
10+
* under the License.
11+
*
12+
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
13+
*/
14+
package org.openmrs;
15+
16+
import org.simpleframework.xml.Attribute;
17+
18+
import java.io.Serializable;
19+
import java.util.Date;
20+
21+
/**
22+
* The DrugReferenceMap map object represents a mapping between a drug and alternative drug terminologies.
23+
*
24+
* @since 1.10
25+
*/
26+
public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Retireable, Serializable {
27+
28+
public static final long serialVersionUID = 1L;
29+
30+
private Integer drugReferenceMapId;
31+
32+
private Drug drug;
33+
34+
private ConceptReferenceTerm conceptReferenceTerm;
35+
36+
private ConceptMapType conceptMapType;
37+
38+
private User creator;
39+
40+
private Date dateCreated;
41+
42+
private Boolean retired = false;
43+
44+
private User retiredBy;
45+
46+
private Date dateRetired;
47+
48+
private User changedBy;
49+
50+
private Date dateChanged;
51+
52+
private String retireReason;
53+
54+
/**
55+
* @return Returns the drugReferenceMapId.
56+
*/
57+
public Integer getDrugReferenceMapId() {
58+
return drugReferenceMapId;
59+
}
60+
61+
/**
62+
* @param drugReferenceMapId The drugReferenceMapId to set.
63+
*/
64+
public void setDrugReferenceMapId(Integer drugReferenceMapId) {
65+
this.drugReferenceMapId = drugReferenceMapId;
66+
}
67+
68+
/**
69+
* @return Returns the drug.
70+
*/
71+
public Drug getDrug() {
72+
return drug;
73+
}
74+
75+
/**
76+
* @param drug The drug to set.
77+
*/
78+
public void setDrug(Drug drug) {
79+
this.drug = drug;
80+
}
81+
82+
/**
83+
* @return Returns the conceptReferenceTerm.
84+
*/
85+
public ConceptReferenceTerm getConceptReferenceTerm() {
86+
return conceptReferenceTerm;
87+
}
88+
89+
/**
90+
* @param conceptReferenceTerm The conceptReferenceTerm to set.
91+
*/
92+
public void setConceptReferenceTerm(ConceptReferenceTerm conceptReferenceTerm) {
93+
this.conceptReferenceTerm = conceptReferenceTerm;
94+
}
95+
96+
/**
97+
* @return Returns the conceptMapType.
98+
*/
99+
public ConceptMapType getConceptMapType() {
100+
return conceptMapType;
101+
}
102+
103+
/**
104+
* @param conceptMapType The conceptMapType to set.
105+
*/
106+
public void setConceptMapType(ConceptMapType conceptMapType) {
107+
this.conceptMapType = conceptMapType;
108+
}
109+
110+
/**
111+
* @return id - The unique Identifier for the object
112+
*/
113+
@Override
114+
public Integer getId() {
115+
return getDrugReferenceMapId();
116+
}
117+
118+
/**
119+
* @param id - The unique Identifier for the object
120+
*/
121+
@Override
122+
public void setId(Integer id) {
123+
setDrugReferenceMapId(id);
124+
}
125+
126+
/**
127+
* @return User - the user who created the object
128+
*/
129+
@Override
130+
public User getCreator() {
131+
return this.creator;
132+
}
133+
134+
/**
135+
* @param creator - the user who created the object
136+
*/
137+
@Override
138+
public void setCreator(User creator) {
139+
this.creator = creator;
140+
}
141+
142+
/**
143+
* @return Date - the date the object was created
144+
*/
145+
@Override
146+
public Date getDateCreated() {
147+
return dateCreated;
148+
}
149+
150+
/**
151+
* @param dateCreated - the date the object was created
152+
*/
153+
@Override
154+
public void setDateCreated(Date dateCreated) {
155+
this.dateCreated = dateCreated;
156+
}
157+
158+
/**
159+
* @return User - the user who last changed the object
160+
*/
161+
@Override
162+
public User getChangedBy() {
163+
return this.changedBy;
164+
}
165+
166+
/**
167+
* @param changedBy - the user who last changed the object
168+
*/
169+
@Override
170+
public void setChangedBy(User changedBy) {
171+
this.changedBy = changedBy;
172+
}
173+
174+
/**
175+
* @return Date - the date the object was last changed
176+
*/
177+
@Override
178+
public Date getDateChanged() {
179+
return this.dateChanged;
180+
}
181+
182+
/**
183+
* @param dateChanged - the date the object was last changed
184+
*/
185+
@Override
186+
public void setDateChanged(Date dateChanged) {
187+
this.dateChanged = dateChanged;
188+
}
189+
190+
/**
191+
* @return Boolean - whether of not this object is retired
192+
*/
193+
@Override
194+
public Boolean isRetired() {
195+
return this.retired;
196+
}
197+
198+
/**
199+
* This method exists to satisfy spring and hibernates slightly bung use of Boolean object
200+
* getters and setters.
201+
*
202+
* @see org.openmrs.Concept#isRetired()
203+
* @deprecated Use the "proper" isRetired method.
204+
*/
205+
@Deprecated
206+
@Attribute
207+
public Boolean getRetired() {
208+
return isRetired();
209+
}
210+
211+
/**
212+
* @param retired - whether of not this object is retired
213+
*/
214+
@Override
215+
public void setRetired(Boolean retired) {
216+
this.retired = retired;
217+
}
218+
219+
/**
220+
* @return User - the user who retired the object
221+
*/
222+
@Override
223+
public User getRetiredBy() {
224+
return this.retiredBy;
225+
}
226+
227+
/**
228+
* @param retiredBy - the user who retired the object
229+
*/
230+
@Override
231+
public void setRetiredBy(User retiredBy) {
232+
this.retiredBy = retiredBy;
233+
}
234+
235+
/**
236+
* @return Date - the date the object was retired
237+
*/
238+
@Override
239+
public Date getDateRetired() {
240+
return dateRetired;
241+
}
242+
243+
/**
244+
* @param dateRetired - the date the object was retired
245+
*/
246+
@Override
247+
public void setDateRetired(Date dateRetired) {
248+
this.dateRetired = dateRetired;
249+
}
250+
251+
/**
252+
* @return String - the reason the object was retired
253+
*/
254+
@Override
255+
public String getRetireReason() {
256+
return this.retireReason;
257+
}
258+
259+
/**
260+
* @param retireReason - the reason the object was retired
261+
*/
262+
@Override
263+
public void setRetireReason(String retireReason) {
264+
this.retireReason = retireReason;
265+
}
266+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<mapping resource="org/openmrs/api/db/hibernate/ConceptReferenceTermMap.hbm.xml" />
4848
<mapping resource="org/openmrs/api/db/hibernate/Drug.hbm.xml" />
4949
<mapping resource="org/openmrs/api/db/hibernate/DrugIngredient.hbm.xml" />
50+
<mapping resource="org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml" />
5051
<mapping resource="org/openmrs/api/db/hibernate/Field.hbm.xml" />
5152
<mapping resource="org/openmrs/api/db/hibernate/FieldAnswer.hbm.xml" />
5253
<mapping resource="org/openmrs/api/db/hibernate/FieldType.hbm.xml" />

‎api/src/main/resources/liquibase-schema-only.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@
23592359
<addForeignKeyConstraint constraintName="provider_person_id_fk"
23602360
baseTableName="provider" baseColumnNames="person_id"
23612361
referencedTableName="person" referencedColumnNames="person_id" />
2362-
2362+
23632363
<addForeignKeyConstraint constraintName="provider_retired_by_fk"
23642364
baseTableName="provider" baseColumnNames="retired_by"
23652365
referencedTableName="users" referencedColumnNames="user_id" />
@@ -2596,7 +2596,7 @@
25962596
<createIndex tableName="form" indexName="form_published_and_retired_index">
25972597
<column name="published"/>
25982598
<column name="retired"/>
2599-
</createIndex>
2599+
</createIndex>
26002600
</changeSet>
26012601
<changeSet id="20110915-1103" author="sunbiz">
26022602
<createIndex tableName="hl7_in_archive" indexName="hl7_in_archive_message_state_idx">
@@ -3291,7 +3291,7 @@
32913291
<addForeignKeyConstraint constraintName="visit_type_fk" baseTableName="visit" baseColumnNames="visit_type_id" referencedTableName="visit_type" referencedColumnNames="visit_type_id"/>
32923292
</changeSet>
32933293
<changeSet id="20110915-1241" author="sunbiz">
3294-
<addForeignKeyConstraint constraintName="visit_location_fk" baseTableName="visit" baseColumnNames="location_id" referencedTableName="location" referencedColumnNames="location_id"/>
3294+
<addForeignKeyConstraint constraintName="visit_location_fk" baseTableName="visit" baseColumnNames="location_id" referencedTableName="location" referencedColumnNames="location_id"/>
32953295
</changeSet>
32963296
<changeSet id="20110915-1242" author="sunbiz">
32973297
<addForeignKeyConstraint constraintName="visit_patient_fk" baseTableName="visit" baseColumnNames="patient_id" referencedTableName="patient" referencedColumnNames="patient_id"/>
@@ -3413,7 +3413,7 @@
34133413
<changeSet id="20110915-1536" author="sunbiz">
34143414
<addForeignKeyConstraint constraintName="mapped_concept_reference_term" referencedTableName="concept_reference_term" referencedColumnNames="concept_reference_term_id" baseTableName="concept_reference_map" baseColumnNames="concept_reference_term_id"/>
34153415
</changeSet>
3416-
3416+
34173417
<!-- Skip changesets from liquibase-update-to-latest when new installation -->
34183418
<!-- TODO: CustomChange to avoid replicated columns-->
34193419
<!-- TODO: Add all changesets that are not required. Only blockers now-->

‎api/src/main/resources/liquibase-update-to-latest.xml

+64-1
Original file line numberDiff line numberDiff line change
@@ -6913,7 +6913,6 @@
69136913
<addNotNullConstraint tableName="orders" columnName="care_setting" columnDataType="int(11)"/>
69146914
</changeSet>
69156915

6916-
69176916
<changeSet id="201312271829-TRUNK-4156" author="vinay">
69186917
<preConditions onFail="MARK_RAN">
69196918
<not><foreignKeyConstraintExists foreignKeyName="orders_care_setting"/></not>
@@ -6923,4 +6922,68 @@
69236922
baseTableName="orders" baseColumnNames="care_setting"
69246923
referencedTableName="care_setting" referencedColumnNames="care_setting_id"/>
69256924
</changeSet>
6925+
6926+
<changeSet id="20131216-1636" author="gitahi">
6927+
<preConditions onFail="MARK_RAN">
6928+
<not>
6929+
<tableExists tableName="drug_reference_map" />
6930+
</not>
6931+
</preConditions>
6932+
<createTable tableName="drug_reference_map">
6933+
<column name="drug_reference_map_id" type="int" autoIncrement="true">
6934+
<constraints nullable="false" primaryKey="true"/>
6935+
</column>
6936+
<column name="drug_id" type="int">
6937+
<constraints nullable="false"/>
6938+
</column>
6939+
<column name="term_id" type="int">
6940+
<constraints nullable="false"/>
6941+
</column>
6942+
<column name="map_type" type="int">
6943+
<constraints nullable="false"/>
6944+
</column>
6945+
<column name="creator" type="int" defaultValueNumeric="0">
6946+
<constraints nullable="false"/>
6947+
</column>
6948+
<column name="date_created" type="DATETIME">
6949+
<constraints nullable="false"/>
6950+
</column>
6951+
<column name="retired" type="BOOLEAN" defaultValueBoolean="false">
6952+
<constraints nullable="false"/>
6953+
</column>
6954+
<column name="retired_by" type="int"/>
6955+
<column name="date_retired" type="DATETIME"/>
6956+
<column name="retire_reason" type="VARCHAR(255)"/>
6957+
<column name="changed_by" type="int"/>
6958+
<column name="date_changed" type="DATETIME"/>
6959+
<column name="uuid" type="char(38)">
6960+
<constraints nullable="false" unique="true"/>
6961+
</column>
6962+
</createTable>
6963+
<addForeignKeyConstraint baseTableName="drug_reference_map" baseColumnNames="drug_id"
6964+
constraintName="drug_for_drug_reference_map"
6965+
referencedTableName="drug"
6966+
referencedColumnNames="drug_id"/>
6967+
<addForeignKeyConstraint baseTableName="drug_reference_map" baseColumnNames="term_id"
6968+
constraintName="concept_reference_term_for_drug_reference_map"
6969+
referencedTableName="concept_reference_term"
6970+
referencedColumnNames="concept_reference_term_id"/>
6971+
<addForeignKeyConstraint baseTableName="drug_reference_map" baseColumnNames="map_type"
6972+
constraintName="concept_map_type_for_drug_reference_map"
6973+
referencedTableName="concept_map_type"
6974+
referencedColumnNames="concept_map_type_id"/>
6975+
<addForeignKeyConstraint baseColumnNames="changed_by" baseTableName="drug_reference_map"
6976+
constraintName="user_who_changed_drug_reference_map"
6977+
referencedColumnNames="user_id"
6978+
referencedTableName="users"/>
6979+
<addForeignKeyConstraint baseColumnNames="creator" baseTableName="drug_reference_map"
6980+
constraintName="drug_reference_map_creator"
6981+
referencedColumnNames="user_id"
6982+
referencedTableName="users"/>
6983+
<addForeignKeyConstraint baseColumnNames="retired_by" baseTableName="drug_reference_map"
6984+
constraintName="user_who_retired_drug_reference_map"
6985+
referencedColumnNames="user_id"
6986+
referencedTableName="users"/>
6987+
</changeSet>
6988+
69266989
</databaseChangeLog>

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

+5
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,10 @@
7171
<many-to-one name="retiredBy" class="org.openmrs.User"
7272
not-null="false" column="retired_by" />
7373

74+
<set name="drugReferenceMaps" inverse="true" cascade="all,delete-orphan,evict">
75+
<key column="drug_id" />
76+
<one-to-many class="org.openmrs.DrugReferenceMap" />
77+
</set>
78+
7479
</class>
7580
</hibernate-mapping>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE hibernate-mapping PUBLIC
3+
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
4+
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
5+
6+
<hibernate-mapping package="org.openmrs">
7+
<class name="DrugReferenceMap" table="drug_reference_map">
8+
9+
<id name="drugReferenceMapId" type="java.lang.Integer" column="drug_reference_map_id">
10+
<generator class="native">
11+
<param name="sequence">drug_reference_map_drug_reference_map_id_seq</param>
12+
</generator>
13+
</id>
14+
15+
<discriminator column="drug_reference_map_id" insert="false"/>
16+
17+
<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" not-null="true"/>
18+
19+
<many-to-one name="drug" class="Drug" column="drug_id" not-null="true"/>
20+
21+
<many-to-one name="conceptReferenceTerm" class="ConceptReferenceTerm" column="term_id" not-null="true"/>
22+
23+
<many-to-one name="conceptMapType" class="ConceptMapType" column="map_type" not-null="true"/>
24+
25+
<many-to-one name="creator" class="User" column="creator" not-null="true"/>
26+
27+
<property name="dateCreated" type="java.util.Date" column="date_created" length="19" not-null="true"/>
28+
29+
<many-to-one name="changedBy" class="User" column="changed_by"/>
30+
31+
<property name="dateChanged" type="java.util.Date" column="date_changed" length="19"/>
32+
33+
<property name="retired" type="java.lang.Boolean" column="retired" length="1" not-null="true"/>
34+
35+
<many-to-one name="retiredBy" class="User" column="retired_by"/>
36+
37+
<property name="dateRetired" type="java.util.Date" column="date_retired" length="19"/>
38+
39+
<property name="retireReason" type="java.lang.String" column="retire_reason" length="255"/>
40+
</class>
41+
</hibernate-mapping>

0 commit comments

Comments
 (0)
Please sign in to comment.