Skip to content

Commit

Permalink
Removed Retireable from DrugReferenceMap.
Browse files Browse the repository at this point in the history
Renamed the column drug_reference_map.map_type to drug_reference_map.concept_map_type.

Added equals() and toString() methods to api/src/main/java/org/openmrs/DrugReferenceMap.java.

Added DrugTest.java class.

Removed toString(), equals() and hashCode() methods fromDrugReferenceMap. Improved tests for the Drug class.
  • Loading branch information
gitahinganga authored and wluyima committed Jan 14, 2014
1 parent d27777b commit 4854047
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 89 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/org/openmrs/Drug.java
Expand Up @@ -266,6 +266,10 @@ public void setDrugReferenceMaps(Set<DrugReferenceMap> drugReferenceMaps) {
*
* @param drugReferenceMap
* @since 1.10
*
* @should set drug as the drug to which a mapping is being added
*
* @should should not add duplicate drug reference maps
*/
public void addDrugReferenceMap(DrugReferenceMap drugReferenceMap) {
if (drugReferenceMap != null && !getDrugReferenceMaps().contains(drugReferenceMap)) {
Expand Down
96 changes: 9 additions & 87 deletions api/src/main/java/org/openmrs/DrugReferenceMap.java
Expand Up @@ -13,8 +13,6 @@
*/
package org.openmrs;

import org.simpleframework.xml.Attribute;

import java.io.Serializable;
import java.util.Date;

Expand All @@ -23,7 +21,7 @@
*
* @since 1.10
*/
public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Retireable, Serializable {
public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Serializable {

This comment has been minimized.

Copy link
@rkorytkowski

rkorytkowski Jan 15, 2014

Member

Shouldn't this be BaseOpenmrsData?

This comment has been minimized.

Copy link
@wluyima

wluyima Jan 15, 2014

Member

No, mappings are neither retireable nor voidable we just delete them from the database once they are dropped, atleast this is how we have handled concept and reference terms mappings in the past, @djazayeri and @bmamlin what do you think?

This comment has been minimized.

Copy link
@djazayeri

djazayeri via email Jan 15, 2014

Member

public static final long serialVersionUID = 1L;

Expand All @@ -39,17 +37,18 @@ public class DrugReferenceMap extends BaseOpenmrsObject implements Auditable, Re

private Date dateCreated;

private Boolean retired = false;

private User retiredBy;

private Date dateRetired;

private User changedBy;

private Date dateChanged;

private String retireReason;
/** default constructor */
public DrugReferenceMap() {
}

/** constructor with concept reference term map id */
public DrugReferenceMap(Integer drugReferenceMapId) {
this.drugReferenceMapId = drugReferenceMapId;
}

/**
* @return Returns the drugReferenceMapId.
Expand Down Expand Up @@ -186,81 +185,4 @@ public Date getDateChanged() {
public void setDateChanged(Date dateChanged) {
this.dateChanged = dateChanged;
}

/**
* @return Boolean - whether of not this object is retired
*/
@Override
public Boolean isRetired() {

This comment has been minimized.

Copy link
@rkorytkowski

rkorytkowski Jan 15, 2014

Member

You forgot to remove retired from hbm, which breaks the build. Shouldn't this be voidable instead?

This comment has been minimized.

Copy link
@wluyima

wluyima Jan 15, 2014

Member

@rkorytkowski i see that you fixed the hbm files, thanks!

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;
}
}
4 changes: 2 additions & 2 deletions api/src/main/resources/liquibase-update-to-latest.xml
Expand Up @@ -6987,7 +6987,7 @@
<column name="term_id" type="int">
<constraints nullable="false"/>
</column>
<column name="map_type" type="int">
<column name="concept_map_type" type="int">
<constraints nullable="false"/>
</column>
<column name="creator" type="int">
Expand Down Expand Up @@ -7016,7 +7016,7 @@
constraintName="concept_reference_term_for_drug_reference_map"
referencedTableName="concept_reference_term"
referencedColumnNames="concept_reference_term_id"/>
<addForeignKeyConstraint baseTableName="drug_reference_map" baseColumnNames="map_type"
<addForeignKeyConstraint baseTableName="drug_reference_map" baseColumnNames="concept_map_type"
constraintName="concept_map_type_for_drug_reference_map"
referencedTableName="concept_map_type"
referencedColumnNames="concept_map_type_id"/>
Expand Down
66 changes: 66 additions & 0 deletions api/src/test/java/org/openmrs/DrugTest.java
@@ -0,0 +1,66 @@
/**
* 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.junit.Assert;
import org.junit.Test;

/**
* Contains test methods for {@link org.openmrs.Drug}.
*/
public class DrugTest {

private final static String UUID_1 = "333cd82c-7d3d-11e3-8633-13f177b345d8";

private final static String UUID_2 = "4eef1530-7d3d-11e3-ac6d-e388e198a21e";

/**
* @verifies set drug as the drug to which a mapping is being added
* @see Drug#addDrugReferenceMap(DrugReferenceMap)
*/
@Test
public void addDrugReferenceMap_shouldSetDrugAsTheDrugToWhichAMappingIsBeingAdded() throws Exception {
Drug drug1 = new Drug();
drug1.setUuid(UUID_1);
Drug drug2 = new Drug();
drug2.setUuid(UUID_2);

DrugReferenceMap map = new DrugReferenceMap(1);
map.setDrug(drug2);
drug1.addDrugReferenceMap(map);
Assert.assertEquals(drug1, drug1.getDrugReferenceMaps().iterator().next().getDrug());
}

/**
* @verifies should not add duplicate drug reference maps
* @see Drug#addDrugReferenceMap(DrugReferenceMap)
*/
@Test
public void addDrugReferenceMap_shouldShouldNotAddDuplicateDrugReferenceMaps() throws Exception {
Drug drug = new Drug();

DrugReferenceMap map1 = new DrugReferenceMap();
map1.setUuid(UUID_1);
DrugReferenceMap map2 = new DrugReferenceMap();
map2.setUuid(UUID_2);
DrugReferenceMap map2Duplicate = new DrugReferenceMap();
map2Duplicate.setUuid(UUID_2);

drug.addDrugReferenceMap(map1);
drug.addDrugReferenceMap(map2);
drug.addDrugReferenceMap(map2Duplicate);

Assert.assertEquals(2, drug.getDrugReferenceMaps().size());
}
}

0 comments on commit 4854047

Please sign in to comment.