Skip to content

Commit

Permalink
Add support for mapping drugs to other terminologies - TRINK-4143
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitahinganga authored and wluyima committed Jan 9, 2014
1 parent 3863412 commit 45b70e2
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 7 deletions.
45 changes: 43 additions & 2 deletions api/src/main/java/org/openmrs/Drug.java
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +46,8 @@ public class Drug extends BaseOpenmrsMetadata implements java.io.Serializable {
private String units;

private Concept concept;

private Set<DrugReferenceMap> drugReferenceMaps;

// Constructors

Expand Down Expand Up @@ -235,4 +240,40 @@ public String getDisplayName() {
return getConcept().getName().getName();
return "";
}

/**
* @return Returns the drugReferenceMaps.
* @since 1.10
*/
public Set<DrugReferenceMap> getDrugReferenceMaps() {
if (drugReferenceMaps == null) {
drugReferenceMaps = new HashSet<DrugReferenceMap>();
}
return drugReferenceMaps;
}

/**
* @param drugReferenceMaps The drugReferenceMaps to set.
* @since 1.10
*/
public void setDrugReferenceMaps(Set<DrugReferenceMap> 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);
}
}
}
266 changes: 266 additions & 0 deletions 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;
}
}
1 change: 1 addition & 0 deletions api/src/main/resources/hibernate.cfg.xml
Expand Up @@ -47,6 +47,7 @@
<mapping resource="org/openmrs/api/db/hibernate/ConceptReferenceTermMap.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Drug.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/DrugIngredient.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Field.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FieldAnswer.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FieldType.hbm.xml" />
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/resources/liquibase-schema-only.xml
Expand Up @@ -2359,7 +2359,7 @@
<addForeignKeyConstraint constraintName="provider_person_id_fk"
baseTableName="provider" baseColumnNames="person_id"
referencedTableName="person" referencedColumnNames="person_id" />

<addForeignKeyConstraint constraintName="provider_retired_by_fk"
baseTableName="provider" baseColumnNames="retired_by"
referencedTableName="users" referencedColumnNames="user_id" />
Expand Down Expand Up @@ -2596,7 +2596,7 @@
<createIndex tableName="form" indexName="form_published_and_retired_index">
<column name="published"/>
<column name="retired"/>
</createIndex>
</createIndex>
</changeSet>
<changeSet id="20110915-1103" author="sunbiz">
<createIndex tableName="hl7_in_archive" indexName="hl7_in_archive_message_state_idx">
Expand Down Expand Up @@ -3291,7 +3291,7 @@
<addForeignKeyConstraint constraintName="visit_type_fk" baseTableName="visit" baseColumnNames="visit_type_id" referencedTableName="visit_type" referencedColumnNames="visit_type_id"/>
</changeSet>
<changeSet id="20110915-1241" author="sunbiz">
<addForeignKeyConstraint constraintName="visit_location_fk" baseTableName="visit" baseColumnNames="location_id" referencedTableName="location" referencedColumnNames="location_id"/>
<addForeignKeyConstraint constraintName="visit_location_fk" baseTableName="visit" baseColumnNames="location_id" referencedTableName="location" referencedColumnNames="location_id"/>
</changeSet>
<changeSet id="20110915-1242" author="sunbiz">
<addForeignKeyConstraint constraintName="visit_patient_fk" baseTableName="visit" baseColumnNames="patient_id" referencedTableName="patient" referencedColumnNames="patient_id"/>
Expand Down Expand Up @@ -3413,7 +3413,7 @@
<changeSet id="20110915-1536" author="sunbiz">
<addForeignKeyConstraint constraintName="mapped_concept_reference_term" referencedTableName="concept_reference_term" referencedColumnNames="concept_reference_term_id" baseTableName="concept_reference_map" baseColumnNames="concept_reference_term_id"/>
</changeSet>

<!-- Skip changesets from liquibase-update-to-latest when new installation -->
<!-- TODO: CustomChange to avoid replicated columns-->
<!-- TODO: Add all changesets that are not required. Only blockers now-->
Expand Down

0 comments on commit 45b70e2

Please sign in to comment.