From 45b70e2fdc585f3449d77522554f0921017a564c Mon Sep 17 00:00:00 2001 From: Gitahi Ng'ang'a Date: Tue, 17 Dec 2013 15:04:50 +0300 Subject: [PATCH] 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 --- api/src/main/java/org/openmrs/Drug.java | 45 ++- .../java/org/openmrs/DrugReferenceMap.java | 266 ++++++++++++++++++ api/src/main/resources/hibernate.cfg.xml | 1 + .../main/resources/liquibase-schema-only.xml | 8 +- .../resources/liquibase-update-to-latest.xml | 65 ++++- .../org/openmrs/api/db/hibernate/Drug.hbm.xml | 5 + .../api/db/hibernate/DrugReferenceMap.hbm.xml | 41 +++ 7 files changed, 424 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/org/openmrs/DrugReferenceMap.java create mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml diff --git a/api/src/main/java/org/openmrs/Drug.java b/api/src/main/java/org/openmrs/Drug.java index 8214b639de3a..64899d5a2c1e 100644 --- a/api/src/main/java/org/openmrs/Drug.java +++ b/api/src/main/java/org/openmrs/Drug.java @@ -13,9 +13,12 @@ */ package org.openmrs; -import java.util.Locale; - import org.apache.commons.lang.StringUtils; +import org.openmrs.api.context.Context; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; /** * Drug @@ -43,6 +46,8 @@ public class Drug extends BaseOpenmrsMetadata implements java.io.Serializable { private String units; private Concept concept; + + private Set drugReferenceMaps; // Constructors @@ -235,4 +240,40 @@ public String getDisplayName() { return getConcept().getName().getName(); return ""; } + + /** + * @return Returns the drugReferenceMaps. + * @since 1.10 + */ + public Set getDrugReferenceMaps() { + if (drugReferenceMaps == null) { + drugReferenceMaps = new HashSet(); + } + return drugReferenceMaps; + } + + /** + * @param drugReferenceMaps The drugReferenceMaps to set. + * @since 1.10 + */ + public void setDrugReferenceMaps(Set drugReferenceMaps) { + this.drugReferenceMaps = drugReferenceMaps; + } + + /** + * Add the given DrugReferenceMap object to this drug's list of drug reference mappings. If there is + * already a corresponding DrugReferenceMap object for this concept, this one will not be added. + * + * @param drugReferenceMap + * @since 1.10 + */ + public void addDrugReferenceMap(DrugReferenceMap drugReferenceMap) { + if (drugReferenceMap != null && !getDrugReferenceMaps().contains(drugReferenceMap)) { + drugReferenceMap.setDrug(this); + if (drugReferenceMap.getConceptMapType() == null) { + drugReferenceMap.setConceptMapType(Context.getConceptService().getDefaultConceptMapType()); + } + getDrugReferenceMaps() .add(drugReferenceMap); + } + } } diff --git a/api/src/main/java/org/openmrs/DrugReferenceMap.java b/api/src/main/java/org/openmrs/DrugReferenceMap.java new file mode 100644 index 000000000000..903ad8220ade --- /dev/null +++ b/api/src/main/java/org/openmrs/DrugReferenceMap.java @@ -0,0 +1,266 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs; + +import org.simpleframework.xml.Attribute; + +import java.io.Serializable; +import java.util.Date; + +/** + * The DrugReferenceMap map object represents a mapping between a drug and alternative drug terminologies. + * + * @since 1.10 + */ +public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Retireable, Serializable { + + public static final long serialVersionUID = 1L; + + private Integer drugReferenceMapId; + + private Drug drug; + + private ConceptReferenceTerm conceptReferenceTerm; + + private ConceptMapType conceptMapType; + + private User creator; + + private Date dateCreated; + + private Boolean retired = false; + + private User retiredBy; + + private Date dateRetired; + + private User changedBy; + + private Date dateChanged; + + private String retireReason; + + /** + * @return Returns the drugReferenceMapId. + */ + public Integer getDrugReferenceMapId() { + return drugReferenceMapId; + } + + /** + * @param drugReferenceMapId The drugReferenceMapId to set. + */ + public void setDrugReferenceMapId(Integer drugReferenceMapId) { + this.drugReferenceMapId = drugReferenceMapId; + } + + /** + * @return Returns the drug. + */ + public Drug getDrug() { + return drug; + } + + /** + * @param drug The drug to set. + */ + public void setDrug(Drug drug) { + this.drug = drug; + } + + /** + * @return Returns the conceptReferenceTerm. + */ + public ConceptReferenceTerm getConceptReferenceTerm() { + return conceptReferenceTerm; + } + + /** + * @param conceptReferenceTerm The conceptReferenceTerm to set. + */ + public void setConceptReferenceTerm(ConceptReferenceTerm conceptReferenceTerm) { + this.conceptReferenceTerm = conceptReferenceTerm; + } + + /** + * @return Returns the conceptMapType. + */ + public ConceptMapType getConceptMapType() { + return conceptMapType; + } + + /** + * @param conceptMapType The conceptMapType to set. + */ + public void setConceptMapType(ConceptMapType conceptMapType) { + this.conceptMapType = conceptMapType; + } + + /** + * @return id - The unique Identifier for the object + */ + @Override + public Integer getId() { + return getDrugReferenceMapId(); + } + + /** + * @param id - The unique Identifier for the object + */ + @Override + public void setId(Integer id) { + setDrugReferenceMapId(id); + } + + /** + * @return User - the user who created the object + */ + @Override + public User getCreator() { + return this.creator; + } + + /** + * @param creator - the user who created the object + */ + @Override + public void setCreator(User creator) { + this.creator = creator; + } + + /** + * @return Date - the date the object was created + */ + @Override + public Date getDateCreated() { + return dateCreated; + } + + /** + * @param dateCreated - the date the object was created + */ + @Override + public void setDateCreated(Date dateCreated) { + this.dateCreated = dateCreated; + } + + /** + * @return User - the user who last changed the object + */ + @Override + public User getChangedBy() { + return this.changedBy; + } + + /** + * @param changedBy - the user who last changed the object + */ + @Override + public void setChangedBy(User changedBy) { + this.changedBy = changedBy; + } + + /** + * @return Date - the date the object was last changed + */ + @Override + public Date getDateChanged() { + return this.dateChanged; + } + + /** + * @param dateChanged - the date the object was last changed + */ + @Override + public void setDateChanged(Date dateChanged) { + this.dateChanged = dateChanged; + } + + /** + * @return Boolean - whether of not this object is retired + */ + @Override + public Boolean isRetired() { + return this.retired; + } + + /** + * This method exists to satisfy spring and hibernates slightly bung use of Boolean object + * getters and setters. + * + * @see org.openmrs.Concept#isRetired() + * @deprecated Use the "proper" isRetired method. + */ + @Deprecated + @Attribute + public Boolean getRetired() { + return isRetired(); + } + + /** + * @param retired - whether of not this object is retired + */ + @Override + public void setRetired(Boolean retired) { + this.retired = retired; + } + + /** + * @return User - the user who retired the object + */ + @Override + public User getRetiredBy() { + return this.retiredBy; + } + + /** + * @param retiredBy - the user who retired the object + */ + @Override + public void setRetiredBy(User retiredBy) { + this.retiredBy = retiredBy; + } + + /** + * @return Date - the date the object was retired + */ + @Override + public Date getDateRetired() { + return dateRetired; + } + + /** + * @param dateRetired - the date the object was retired + */ + @Override + public void setDateRetired(Date dateRetired) { + this.dateRetired = dateRetired; + } + + /** + * @return String - the reason the object was retired + */ + @Override + public String getRetireReason() { + return this.retireReason; + } + + /** + * @param retireReason - the reason the object was retired + */ + @Override + public void setRetireReason(String retireReason) { + this.retireReason = retireReason; + } +} diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 70a9348fa7d2..eb8fa32e80e0 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -47,6 +47,7 @@ + diff --git a/api/src/main/resources/liquibase-schema-only.xml b/api/src/main/resources/liquibase-schema-only.xml index 8d984ce704c4..ae06a9ae27cc 100644 --- a/api/src/main/resources/liquibase-schema-only.xml +++ b/api/src/main/resources/liquibase-schema-only.xml @@ -2359,7 +2359,7 @@ - + @@ -2596,7 +2596,7 @@ - + @@ -3291,7 +3291,7 @@ - + @@ -3413,7 +3413,7 @@ - + diff --git a/api/src/main/resources/liquibase-update-to-latest.xml b/api/src/main/resources/liquibase-update-to-latest.xml index dc440f258e22..3c2baa7629cb 100644 --- a/api/src/main/resources/liquibase-update-to-latest.xml +++ b/api/src/main/resources/liquibase-update-to-latest.xml @@ -6913,7 +6913,6 @@ - @@ -6923,4 +6922,68 @@ baseTableName="orders" baseColumnNames="care_setting" referencedTableName="care_setting" referencedColumnNames="care_setting_id"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/Drug.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/Drug.hbm.xml index 5055574065f8..874647a9de2e 100644 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/Drug.hbm.xml +++ b/api/src/main/resources/org/openmrs/api/db/hibernate/Drug.hbm.xml @@ -71,5 +71,10 @@ + + + + + diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml new file mode 100644 index 000000000000..35bc3a01f935 --- /dev/null +++ b/api/src/main/resources/org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml @@ -0,0 +1,41 @@ + + + + + + + + + drug_reference_map_drug_reference_map_id_seq + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +