diff --git a/condition-list/pom.xml b/condition-list/pom.xml deleted file mode 100644 index d04702e25..000000000 --- a/condition-list/pom.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - 4.0.0 - - emrapi - org.openmrs.module - 2.0.0-SNAPSHOT - - - emrapi-condition-list - jar - EMR API Condition List - - - 1.10.2 - - - - - org.openmrs.api - openmrs-api - ${openMRSVersion} - provided - - - javassist - javassist - - - - - - org.openmrs.api - openmrs-api - test-jar - ${openMRSVersion} - test - - - javassist - javassist - - - - - - org.openmrs.test - openmrs-test - ${openMRSVersion} - pom - test - - - - - - - - src/main/resources - true - - - - - - src/test/resources - - **/*.properties - **/*.xml - - true - - - src/test/resources - - **/*.properties - **/*.xml - - false - - - - - - \ No newline at end of file diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/Condition.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/Condition.java deleted file mode 100644 index 97f44e935..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/Condition.java +++ /dev/null @@ -1,325 +0,0 @@ -/** - * 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.module.emrapi.conditionslist; - -import java.util.Date; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.openmrs.BaseOpenmrsData; -import org.openmrs.Concept; -import org.openmrs.OpenmrsObject; -import org.openmrs.Patient; - -/** - * Defines a Condition in the system. - * - * @version 2.0 - */ -public class Condition extends BaseOpenmrsData implements java.io.Serializable { - - public static final long serialVersionUID = 2L; - - protected final Log log = LogFactory.getLog(getClass()); - - /** - * default empty constructor - */ - public Condition() { - } - - /** - * @param conditionId Integer to create this Condition object from - */ - public Condition(Integer conditionId) { - this.conditionId = conditionId; - } - - public enum Status { - ACTIVE, INACTIVE, HISTORY_OF - } - - private Integer conditionId; - - private Condition previousCondition; - - private Patient patient; - - private Status status = Status.ACTIVE; - - private Concept concept; - - private String conditionNonCoded; - - private Date onsetDate; - - private String additionalDetail; - - private Date endDate; - - private Concept endReason; - - public static Condition newInstance(Condition condition) { - return copy(condition, new Condition()); - } - - public static Condition copy(Condition fromCondition, Condition toCondition) { - toCondition.setPreviousCondition(fromCondition.getPreviousCondition()); - toCondition.setPatient(fromCondition.getPatient()); - toCondition.setStatus(fromCondition.getStatus()); - toCondition.setConcept(fromCondition.getConcept()); - toCondition.setConditionNonCoded(fromCondition.getConditionNonCoded()); - toCondition.setOnsetDate(fromCondition.getOnsetDate()); - toCondition.setAdditionalDetail(fromCondition.getAdditionalDetail()); - toCondition.setEndDate(fromCondition.getEndDate()); - toCondition.setEndReason(fromCondition.getEndReason()); - toCondition.setVoided(fromCondition.getVoided()); - toCondition.setVoidedBy(fromCondition.getVoidedBy()); - toCondition.setVoidReason(fromCondition.getVoidReason()); - toCondition.setDateVoided(fromCondition.getDateVoided()); - return toCondition; - } - - /** - * @return Returns the conditionId. - */ - public Integer getConditionId() { - return conditionId; - } - - /** - * @param conditionId The conditionId to set. - */ - public void setConditionId(Integer conditionId) { - this.conditionId = conditionId; - } - - /** - * @return Returns the previousCondition. - */ - public Condition getPreviousCondition() { - return previousCondition; - } - - /** - * @param previousCondition The previousCondition to set. - * When a condition is altered (e.g., a symptom explicitly converted into a diagnosis), this - * field - * is used to link the new condition to the condition(s) it has replaced. - */ - public void setPreviousCondition(Condition previousCondition) { - this.previousCondition = previousCondition; - } - - /** - * @return Returns the patient. - */ - public Patient getPatient() { - return patient; - } - - /** - * @param patient The patient to set. - */ - public void setPatient(Patient patient) { - if (getConditionId() != null && getPatient() != null && !getPatient().equals(patient)) { - throw new IllegalArgumentException("Patient cannot be changed"); - } - this.patient = patient; - } - - /** - * @return Returns the status. - */ - public Status getStatus() { - return status; - } - - /** - * @param status The status to set. - * The clinical status of the condition. Default is ACTIVE. - * - */ - public void setStatus(Status status) { - this.status = status; - } - - /** - * @return Returns the concept. - */ - public Concept getConcept() { - return concept; - } - - /** - * @param concept The concept to set. - */ - public void setConcept(Concept concept) { - if (getConditionId() != null && getConcept() != null && !getConcept().equals(concept)) { - throw new IllegalArgumentException("Concept cannot be changed"); - } - this.concept = concept; - } - - /** - * @return Returns the conditionNonCoded. - */ - public String getConditionNonCoded() { - return conditionNonCoded; - } - - /** - * @param conditionNonCoded The conditionNonCoded to set. - * When a condition is not codified, the concept for the condition is set to a concept for - * NON-CODED and the free text representation of the condition is stored here. - */ - public void setConditionNonCoded(String conditionNonCoded) { - if (getConditionId() != null && getConditionNonCoded() != null && !getConditionNonCoded().equals( - conditionNonCoded)) { - throw new IllegalArgumentException("Condition non coded cannot be changed"); - } - this.conditionNonCoded = conditionNonCoded; - } - - /** - * @return Returns the onsetDate. - */ - public Date getOnsetDate() { - return onsetDate; - } - - /** - * @param onsetDate The onsetDate to set. - */ - public void setOnsetDate(Date onsetDate) { - this.onsetDate = onsetDate; - } - - /** - * @return Returns the additionalDetail. - */ - public String getAdditionalDetail() { - return additionalDetail; - } - - /** - * @param additionalDetail The additionalDetail to set. - * Additional detail about the condition. This is used to further refine the concept and - * not meant for encounter-specific detail or notes. For example, detail - * such as "left more than right" or "diagnosed by chest x-ray 5-June-2010" would be - * appropriate additional detail; however, "hurts worse today" would not, since the - * additional detail is assumed to be refining the condition and not providing encounter- - * specific information. - */ - public void setAdditionalDetail(String additionalDetail) { - this.additionalDetail = additionalDetail; - } - - /** - * @return Returns the endDate. - */ - - public Date getEndDate() { - return endDate; - } - - /** - * @param endDate The endDate to set. - */ - - public void setEndDate(Date endDate) { - this.endDate = endDate; - } - - /** - * @return Returns the endReason. - */ - - public Concept getEndReason() { - return endReason; - } - - /** - * @param endReason The endReason to set. - */ - - public void setEndReason(Concept endReason) { - this.endReason = endReason; - } - - /** - * @see org.openmrs.OpenmrsObject#getId() - */ - @Override - public Integer getId() { - return getConditionId(); - } - - /** - * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer) - */ - @Override - public void setId(Integer conditionId) { - setConditionId(conditionId); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - if (!super.equals(o)) { - return false; - } - - Condition condition = (Condition) o; - - if (!patient.equals(condition.patient)) { - return false; - } - if (status != condition.status) { - return false; - } - if (!concept.equals(condition.concept)) { - return false; - } - if (conditionNonCoded != null ? - !conditionNonCoded.equals(condition.conditionNonCoded) : - condition.conditionNonCoded != null) { - return false; - } - if (onsetDate != null ? !onsetDate.equals(condition.onsetDate) : condition.onsetDate != null) { - return false; - } - if (additionalDetail != null ? - !additionalDetail.equals(condition.additionalDetail) : - condition.additionalDetail != null) { - return false; - } - if (endDate != null ? !endDate.equals(condition.endDate) : condition.endDate != null) { - return false; - } - return endReason != null ? endReason.equals(condition.endReason) : condition.endReason == null; - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionHistory.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionHistory.java deleted file mode 100644 index 1c52eda6b..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionHistory.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.module.emrapi.conditionslist; - -import java.util.List; - -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.openmrs.Concept; - -public class ConditionHistory { - - private String nonCodedCondition; - - private Concept condition; - - private List conditions; - - public String getNonCodedCondition() { - return nonCodedCondition; - } - - public void setNonCodedCondition(String nonCodedCondition) { - this.nonCodedCondition = nonCodedCondition; - } - - public Concept getCondition() { - return condition; - } - - public void setCondition(Concept condition) { - this.condition = condition; - } - - public List getConditions() { - return conditions; - } - - public void setConditions(List conditions) { - this.conditions = conditions; - } - - @Override - public String toString() { - String name = nonCodedCondition; - if (name != null && condition != null && condition.getName() != null) { - name = condition.getName().getName(); - } - - return new ToStringBuilder(this).append("condition", name).append("count", conditions.size()).build(); - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionListConstants.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionListConstants.java deleted file mode 100644 index 46abbc92c..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionListConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.module.emrapi.conditionslist; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Constants used in ConditionList. Contents built from build properties (version, version_short, and - * expected_database). Some are set at runtime (database, database version). This file should - * contain all privilege names and global property names. Those strings added to the static CORE_* - * methods will be written to the database at startup if they don't exist yet. - */ - -public final class ConditionListConstants { - - private static Log log = LogFactory.getLog(ConditionListConstants.class); - - public static final String GP_END_REASON_CONCEPT_SET_UUID = "conditionList.endReasonConceptSetUuid"; - - public static final String GLOBAL_PROPERTY_NON_CODED_UUID = "conditionList.nonCodedUuid"; - -} \ No newline at end of file diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionService.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionService.java deleted file mode 100644 index c4fe14060..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/ConditionService.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.module.emrapi.conditionslist; - -import java.util.List; - -import org.openmrs.Concept; -import org.openmrs.Patient; -import org.openmrs.annotation.Authorized; -import org.openmrs.api.OpenmrsService; - -/** - * @deprecated as of 1.25.0, replaced by {@link ConditionService} in the openmrs core platform 2.2.0 - */ -@Deprecated -public interface ConditionService extends OpenmrsService { - - @Authorized({ PrivilegeConstants.EDIT_CONDITIONS }) - Condition save(Condition condition); - - @Authorized({ PrivilegeConstants.EDIT_CONDITIONS }) - Condition voidCondition(Condition condition, String voidReason); - - Condition getConditionByUuid(String uuid); - - List getConditionHistory(Patient patient); - - @Authorized({ PrivilegeConstants.GET_CONDITIONS }) - List getActiveConditions(Patient patient); - - List getEndReasonConcepts(); -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/DateConverter.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/DateConverter.java deleted file mode 100644 index 04b365f0b..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/DateConverter.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormat; - -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -/** - * This converter mimics the behavior in the rest webservices ConversionUtil method for dates - * This ensures that the system timezone is used to interpret dates unless UTC is explicitly indicated - * This is implemented as a - */ -public class DateConverter { - - public static final String ISO_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; - - private static final Log log = LogFactory.getLog(DateConverter.class); - - public static final List SUPPORTED_FORMATS = Arrays.asList( - ISO_DATE_FORMAT, - "yyyy-MM-dd'T'HH:mm:ss.SSS", - "yyyy-MM-dd'T'HH:mm:ssZ", - "yyyy-MM-dd'T'HH:mm:ssXXX", - "yyyy-MM-dd'T'HH:mm:ss", - "yyyy-MM-dd HH:mm:ss", - "yyyy-MM-dd" - ); - - /** - * @return the given dateString parsed into a Date, defaulting to using the system timezone - */ - public static Date deserialize(String dateString) { - if (StringUtils.isBlank(dateString)) { - return null; - } - for (String dateFormat : SUPPORTED_FORMATS) { - try { - return DateTime.parse(dateString, DateTimeFormat.forPattern(dateFormat)).toDate(); - } - catch (Exception e) { - if (log.isTraceEnabled()) { - log.trace("Unable to parse '" + dateString + "' using format " + dateFormat, e); - } - } - } - throw new RuntimeException("Unable to parse '" + dateString + "' using any of: " + SUPPORTED_FORMATS); - } - - /** - * @return the given date, serialized in ISO format - */ - public static String serialize(Date date) { - if (date == null) { - return null; - } - return new SimpleDateFormat(ISO_DATE_FORMAT).format(date); - } -} \ No newline at end of file diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/EmrConditionValidator.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/EmrConditionValidator.java deleted file mode 100644 index 795fcf058..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/EmrConditionValidator.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * 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.module.emrapi.conditionslist; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.openmrs.Concept; -import org.openmrs.annotation.Handler; -import org.openmrs.api.AdministrationService; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -@Handler(supports = { Condition.class }) -public class EmrConditionValidator implements Validator { - - /** - * Log for this class and subclasses - */ - protected final Log log = LogFactory.getLog(getClass()); - - private AdministrationService administrationService; - - private ConditionService conditionService; - - public EmrConditionValidator(ConditionService conditionService, AdministrationService administrationService) { - this.conditionService = conditionService; - this.administrationService = administrationService; - } - - /** - * Determines if the command object being submitted is a valid type - * - * @see org.springframework.validation.Validator#supports(java.lang.Class) - */ - @SuppressWarnings("unchecked") - public boolean supports(Class c) { - return Condition.class.isAssignableFrom(c); - } - - @Override - public void validate(Object obj, Errors errors) { - - Condition condition = (Condition) obj; - if (condition == null) { - errors.reject("error.general"); - } else { - ValidationUtils.rejectIfEmpty(errors, "patient", "error.null"); - ValidationUtils.rejectIfEmpty(errors, "status", "error.null"); - ValidationUtils.rejectIfEmpty(errors, "creator", "error.null"); - ValidationUtils.rejectIfEmpty(errors, "concept", "error.null"); - ValidationUtils.rejectIfEmpty(errors, "voided", "error.null"); - ValidationUtils.rejectIfEmpty(errors, "dateCreated", "error.null"); - ValidationUtils.rejectIfEmpty(errors, "uuid", "error.null"); - - validateNonCodedCondition(condition, errors); - validateDuplicateConditions(condition, errors); - validateEndReasonConcept(condition, errors); - } - - } - - private void validateEndReasonConcept(Condition condition, Errors errors) { - if (condition.getEndReason() == null) { - if (condition.getEndDate() != null) { - errors.rejectValue("endReason", "Condition.error.endReasonIsMandatory"); - } - } else { - List endReasonConcepts = conditionService.getEndReasonConcepts(); - if (!endReasonConcepts.contains(condition.getEndReason())) { - errors.rejectValue("endReason", "Condition.error.notAmongAllowedConcepts"); - } - } - } - - private void validateDuplicateConditions(Condition condition, Errors errors) { - List conditionsForPatient = conditionService.getActiveConditions(condition.getPatient()); - if (condition.getConditionNonCoded() != null) { - for (Condition eachCondition : conditionsForPatient) { - if (eachCondition.getConcept().equals(condition.getConcept()) - && eachCondition.getConditionNonCoded().equalsIgnoreCase( - condition.getConditionNonCoded().replaceAll("\\s", "")) && !eachCondition.getUuid().equals( - condition.getUuid())) { - errors.rejectValue("concept", "Condition.error.duplicatesNotAllowed"); - } - } - } - } - - private void validateNonCodedCondition(Condition condition, Errors errors) { - String nonCodedConditionUuid = administrationService.getGlobalProperty( - ConditionListConstants.GLOBAL_PROPERTY_NON_CODED_UUID); - if (condition.getConditionNonCoded() != null) { - if (!condition.getConcept().getUuid().equals(nonCodedConditionUuid)) { - errors.rejectValue("conditionNonCoded", - "Condition.error.conditionNonCodedValueNotSupportedForCodedCondition"); - } - } else { - if (condition.getConcept().getUuid().equals(nonCodedConditionUuid)) { - errors.rejectValue("conditionNonCoded", "Condition.error.conditionNonCodedValueNeededForNonCodedCondition"); - } - } - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/PrivilegeConstants.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/PrivilegeConstants.java deleted file mode 100644 index f1d476cf6..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/PrivilegeConstants.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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.module.emrapi.conditionslist; - -public class PrivilegeConstants { - - // these are added in the EMR API config.xml - - public static final String EDIT_CONDITIONS = "Edit conditions"; - - public static final String GET_CONDITIONS = "Get conditions"; -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/Concept.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/Concept.java deleted file mode 100644 index 43db8c8bc..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/Concept.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import org.codehaus.jackson.annotate.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class Concept { - - private String uuid; - - private String name; - - private String shortName; - - public Concept() { - } - - public Concept(String uuid, String name) { - this.uuid = uuid; - this.name = name; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getName() { - return name; - } - - public String getShortName() { - return shortName; - } - - public void setShortName(String shortName) { - this.shortName = shortName; - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/Condition.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/Condition.java deleted file mode 100644 index 0cb8a8415..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/Condition.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import java.util.Date; - -import org.codehaus.jackson.annotate.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class Condition { - - public String uuid; - - private String patientUuid; - - private Concept concept; - - private String conditionNonCoded; - - private org.openmrs.module.emrapi.conditionslist.Condition.Status status; - - private String onSetDate; - - private String endDate; - - private Concept endReason; - - private String additionalDetail; - - private Boolean voided; - - private String voidReason; - - private String creator; - - private Date dateCreated; - - private String previousConditionUuid; - - public String getPreviousConditionUuid() { - return previousConditionUuid; - } - - public void setPreviousConditionUuid(String previousConditionUuid) { - this.previousConditionUuid = previousConditionUuid; - } - - public Date getDateCreated() { - return dateCreated; - } - - public void setDateCreated(Date dateCreated) { - this.dateCreated = dateCreated; - } - - public String getCreator() { - return creator; - } - - public void setCreator(String creator) { - this.creator = creator; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getConditionNonCoded() { - return conditionNonCoded; - } - - public void setConditionNonCoded(String conditionNonCoded) { - this.conditionNonCoded = conditionNonCoded; - } - - public String getOnSetDate() { - return onSetDate; - } - - public void setOnSetDate(String onSetDate) { - this.onSetDate = onSetDate; - } - - public String getEndDate() { - return endDate; - } - - public void setEndDate(String endDate) { - this.endDate = endDate; - } - - public Concept getEndReason() { - return endReason; - } - - public void setEndReason(Concept endReason) { - this.endReason = endReason; - } - - public String getAdditionalDetail() { - return additionalDetail; - } - - public void setAdditionalDetail(String additionalDetail) { - this.additionalDetail = additionalDetail; - } - - public Boolean getVoided() { - return voided; - } - - public void setVoided(Boolean voided) { - this.voided = voided; - } - - public String getVoidReason() { - return voidReason; - } - - public void setVoidReason(String voidReason) { - this.voidReason = voidReason; - } - - public org.openmrs.module.emrapi.conditionslist.Condition.Status getStatus() { - return status; - } - - public void setStatus(org.openmrs.module.emrapi.conditionslist.Condition.Status status) { - this.status = status; - } - - public String getPatientUuid() { - return patientUuid; - } - - public void setPatientUuid(String patientUuid) { - this.patientUuid = patientUuid; - } - - public Concept getConcept() { - return concept; - } - - public void setConcept(Concept concept) { - this.concept = concept; - } - -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistory.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistory.java deleted file mode 100644 index 04289fb83..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistory.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import java.util.List; - -public class ConditionHistory { - - private String conditionNonCoded; - - private String conceptUuid; - - private List conditions; - - public String getConditionNonCoded() { - return conditionNonCoded; - } - - public void setConditionNonCoded(String conditionNonCoded) { - this.conditionNonCoded = conditionNonCoded; - } - - public String getConceptUuid() { - return conceptUuid; - } - - public void setConceptUuid(String conceptUuid) { - this.conceptUuid = conceptUuid; - } - - public List getConditions() { - return conditions; - } - - public void setConditions(List conditions) { - this.conditions = conditions; - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistoryMapper.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistoryMapper.java deleted file mode 100644 index 2040c82e7..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistoryMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import java.util.ArrayList; -import java.util.List; - -public class ConditionHistoryMapper { - - private ConditionMapper conditionMapper; - - public ConditionHistoryMapper(ConditionMapper conditionMapper) { - this.conditionMapper = conditionMapper; - } - - public ConditionHistory map(org.openmrs.module.emrapi.conditionslist.ConditionHistory conditionHistory) { - ConditionHistory conditionHistoryContract = new ConditionHistory(); - conditionHistoryContract.setConceptUuid(conditionHistory.getCondition().getUuid()); - - ArrayList conditions = new ArrayList(); - for (org.openmrs.module.emrapi.conditionslist.Condition condition : conditionHistory.getConditions()) { - conditions.add(conditionMapper.map(condition)); - } - conditionHistoryContract.setConditions(conditions); - conditionHistoryContract.setConditionNonCoded(conditionHistory.getNonCodedCondition()); - return conditionHistoryContract; - } - - public List map(List conditionHistories100) { - List conditionHistories101 = new ArrayList(); - for (org.openmrs.module.emrapi.conditionslist.ConditionHistory conditionHistory : conditionHistories100) { - conditionHistories101.add(map(conditionHistory)); - } - return conditionHistories101; - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionMapper.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionMapper.java deleted file mode 100644 index 39342bc50..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionMapper.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import static org.apache.commons.lang3.StringUtils.isEmpty; -import static org.openmrs.util.LocaleUtility.getDefaultLocale; - -import org.openmrs.ConceptName; -import org.openmrs.Patient; -import org.openmrs.api.context.Context; -import org.openmrs.module.emrapi.conditionslist.ConditionListConstants; -import org.openmrs.module.emrapi.conditionslist.DateConverter; - -import java.util.Locale; - -public class ConditionMapper { - - public Condition map(org.openmrs.module.emrapi.conditionslist.Condition openmrsCondition) { - Concept concept = mapConcept(openmrsCondition.getConcept()); - Condition condition = new Condition(); - condition.setUuid(openmrsCondition.getUuid()); - condition.setAdditionalDetail(openmrsCondition.getAdditionalDetail()); - condition.setStatus(openmrsCondition.getStatus()); - condition.setConcept(concept); - condition.setPatientUuid(openmrsCondition.getPatient().getUuid()); - condition.setConditionNonCoded(openmrsCondition.getConditionNonCoded()); - condition.setOnSetDate(DateConverter.serialize(openmrsCondition.getOnsetDate())); - condition.setVoided(openmrsCondition.getVoided()); - condition.setVoidReason(openmrsCondition.getVoidReason()); - condition.setEndDate(DateConverter.serialize(openmrsCondition.getEndDate())); - condition.setCreator(openmrsCondition.getCreator().getDisplayString()); - condition.setDateCreated(openmrsCondition.getDateCreated()); - if (openmrsCondition.getPreviousCondition() != null) { - condition.setPreviousConditionUuid(openmrsCondition.getPreviousCondition().getUuid()); - } - if (openmrsCondition.getEndReason() != null) { - condition.setEndReason(mapConcept(openmrsCondition.getEndReason())); - } - return condition; - } - - public org.openmrs.module.emrapi.conditionslist.Condition map(Condition condition) { - org.openmrs.Concept concept = Context.getConceptService().getConceptByUuid(condition.getConcept().getUuid()); - Patient patient = Context.getPatientService().getPatientByUuid(condition.getPatientUuid()); - String nonCodedConditionConcept = Context.getAdministrationService().getGlobalProperty( - ConditionListConstants.GLOBAL_PROPERTY_NON_CODED_UUID); - - org.openmrs.module.emrapi.conditionslist.Condition openmrsCondition = new org.openmrs.module.emrapi.conditionslist.Condition(); - - if (!isEmpty(condition.getConditionNonCoded())) { - concept = Context.getConceptService().getConceptByUuid(nonCodedConditionConcept); - } - if (condition.getEndReason() != null) { - org.openmrs.Concept endReason = Context.getConceptService().getConceptByUuid( - condition.getEndReason().getUuid()); - openmrsCondition.setEndReason(endReason); - } - if (condition.getUuid() != null) { - openmrsCondition.setUuid(condition.getUuid()); - } - openmrsCondition.setAdditionalDetail(condition.getAdditionalDetail()); - openmrsCondition.setStatus(condition.getStatus()); - openmrsCondition.setConcept(concept); - openmrsCondition.setPatient(patient); - openmrsCondition.setConditionNonCoded(condition.getConditionNonCoded()); - openmrsCondition.setOnsetDate(DateConverter.deserialize(condition.getOnSetDate())); - openmrsCondition.setEndDate(DateConverter.deserialize(condition.getEndDate())); - openmrsCondition.setVoided(condition.getVoided()); - openmrsCondition.setVoidReason(condition.getVoidReason()); - - return openmrsCondition; - } - - private Concept mapConcept(org.openmrs.Concept openmrsConcept) { - ConceptName fullySpecifiedName = openmrsConcept.getFullySpecifiedName(Context.getLocale()); - if(fullySpecifiedName == null){ - fullySpecifiedName = openmrsConcept.getFullySpecifiedName(getDefaultLocale()); - } - if(fullySpecifiedName == null){ - fullySpecifiedName = openmrsConcept.getFullySpecifiedName(new Locale("en")); - } - Concept concept = new Concept(openmrsConcept.getUuid(), fullySpecifiedName.getName()); - ConceptName shortName = openmrsConcept.getShortNameInLocale(Context.getLocale()); - - if (shortName != null) { - concept.setShortName(shortName.getName()); - } - return concept; - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/db/ConditionDAO.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/db/ConditionDAO.java deleted file mode 100644 index 0872a85f3..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/db/ConditionDAO.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.module.emrapi.conditionslist.db; - -import java.util.List; - -import org.openmrs.Patient; -import org.openmrs.module.emrapi.conditionslist.Condition; - -public interface ConditionDAO { - - Condition saveOrUpdate(Condition condition); - - Condition getConditionByUuid(String uuid); - - List getConditionHistory(Patient patient); - - List getActiveConditions(Patient patient); -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/db/hibernate/HibernateConditionDAO.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/db/hibernate/HibernateConditionDAO.java deleted file mode 100644 index 818245225..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/db/hibernate/HibernateConditionDAO.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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.module.emrapi.conditionslist.db.hibernate; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Query; -import org.openmrs.Patient; -import org.openmrs.api.db.hibernate.DbSessionFactory; -import org.openmrs.module.emrapi.conditionslist.Condition; -import org.openmrs.module.emrapi.conditionslist.db.ConditionDAO; -import org.springframework.transaction.annotation.Transactional; - -public class HibernateConditionDAO implements ConditionDAO { - - protected static final Log log = LogFactory.getLog(ConditionDAO.class); - - /** - * Hibernate session factory - */ - - private DbSessionFactory sessionFactory; - - /** - * Set session factory - * - * @param sessionFactory - */ - public void setSessionFactory(DbSessionFactory sessionFactory) { - this.sessionFactory = sessionFactory; - } - - @Override - @Transactional - public Condition saveOrUpdate(Condition condition) { - sessionFactory.getCurrentSession().saveOrUpdate(condition); - return condition; - } - - @Override - @Transactional(readOnly = true) - public Condition getConditionByUuid(String uuid) { - return (Condition) sessionFactory.getCurrentSession().createQuery("from org.openmrs.module.emrapi.conditionslist.Condition c where c.uuid = :uuid") - .setString("uuid", uuid).uniqueResult(); - } - - @Override - @Transactional(readOnly = true) - public List getConditionHistory(Patient patient) { - Query query = sessionFactory.getCurrentSession().createQuery( - "select con from org.openmrs.module.emrapi.conditionslist.Condition as con where con.patient.patientId = :patientId and con.voided = false " + - "order by con.dateCreated desc"); - query.setInteger("patientId", patient.getId()); - return query.list(); - } - - @Override - @Transactional(readOnly = true) - public List getActiveConditions(Patient patient) { - Query query = sessionFactory.getCurrentSession().createQuery( - "from org.openmrs.module.emrapi.conditionslist.Condition c where c.patient.patientId = :patientId and c.voided = false and c.endDate is null order " - + "by c.dateCreated desc"); - query.setInteger("patientId", patient.getId()); - return query.list(); - } -} diff --git a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/impl/ConditionServiceImpl.java b/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/impl/ConditionServiceImpl.java deleted file mode 100644 index 77d16d1d0..000000000 --- a/condition-list/src/main/java/org/openmrs/module/emrapi/conditionslist/impl/ConditionServiceImpl.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * 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.module.emrapi.conditionslist.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.openmrs.Concept; -import org.openmrs.Patient; -import org.openmrs.api.AdministrationService; -import org.openmrs.api.ConceptService; -import org.openmrs.api.impl.BaseOpenmrsService; -import org.openmrs.module.emrapi.conditionslist.Condition; -import org.openmrs.module.emrapi.conditionslist.ConditionHistory; -import org.openmrs.module.emrapi.conditionslist.ConditionListConstants; -import org.openmrs.module.emrapi.conditionslist.ConditionService; -import org.openmrs.module.emrapi.conditionslist.db.ConditionDAO; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -/** - * @deprecated as of 1.25.0, replaced by {@link ConditionServiceImpl} in the openmrs core platform 2.2.0 - */ -@Deprecated -public class ConditionServiceImpl extends BaseOpenmrsService implements ConditionService { - - private ConditionDAO conditionDAO; - - private ConceptService conceptService; - - private AdministrationService administrationService; - - public ConditionServiceImpl(ConditionDAO conditionDAO, ConceptService conceptService, - AdministrationService administrationService) { - this.conditionDAO = conditionDAO; - this.conceptService = conceptService; - this.administrationService = administrationService; - } - - @Override - public Condition save(Condition condition) { - Date endDate = condition.getEndDate() != null ? condition.getEndDate() : new Date(); - if (condition.getEndReason() != null) { - condition.setEndDate(endDate); - } - Condition existingCondition = getConditionByUuid(condition.getUuid()); - if (condition.equals(existingCondition)) { - return existingCondition; - } - if (existingCondition == null) { - return conditionDAO.saveOrUpdate(condition); - } - condition = Condition.newInstance(condition); - condition.setPreviousCondition(existingCondition); - if (existingCondition.getStatus().equals(condition.getStatus())) { - existingCondition.setVoided(true); - conditionDAO.saveOrUpdate(existingCondition); - return conditionDAO.saveOrUpdate(condition); - } - Date onSetDate = condition.getOnsetDate() != null ? condition.getOnsetDate() : new Date(); - existingCondition.setEndDate(onSetDate); - conditionDAO.saveOrUpdate(existingCondition); - condition.setOnsetDate(onSetDate); - return conditionDAO.saveOrUpdate(condition); - } - - public List getConditionHistory(Patient patient) { - List conditionList = conditionDAO.getConditionHistory(patient); - Map allConditions = new LinkedHashMap(); - for (Condition condition : conditionList) { - Concept concept = condition.getConcept(); - - String nonCodedConceptUuid = administrationService.getGlobalProperty( - ConditionListConstants.GLOBAL_PROPERTY_NON_CODED_UUID); - - String key = concept.getUuid().equals(nonCodedConceptUuid) ? - condition.getConditionNonCoded() : - concept.getUuid(); - ConditionHistory conditionHistory = allConditions.get(key); - if (conditionHistory != null) { - conditionHistory.getConditions().add(condition); - } else { - conditionHistory = new ConditionHistory(); - List conditions = new ArrayList(); - conditions.add(condition); - conditionHistory.setConditions(conditions); - conditionHistory.setCondition(condition.getConcept()); - if (concept.getUuid().equals(nonCodedConceptUuid)) { - conditionHistory.setNonCodedCondition(condition.getConditionNonCoded()); - } - } - allConditions.put(key, conditionHistory); - } - return new ArrayList(allConditions.values()); - } - - @Override - public Condition voidCondition(Condition condition, String voidReason) { - if (!StringUtils.hasLength(voidReason)) { - throw new IllegalArgumentException("voidReason cannot be empty or null"); - } - return conditionDAO.saveOrUpdate(condition); - } - - @Override - public Condition getConditionByUuid(String uuid) { - return conditionDAO.getConditionByUuid(uuid); - } - - @Override - public List getActiveConditions(Patient patient) { - return conditionDAO.getActiveConditions(patient); - } - - @Override - @Transactional(readOnly = true) - public List getEndReasonConcepts() { - return getSetMembersOfConceptSetFromGP(ConditionListConstants.GP_END_REASON_CONCEPT_SET_UUID); - } - - private List getSetMembersOfConceptSetFromGP(String globalProperty) { - String conceptUuid = administrationService.getGlobalProperty(globalProperty); - Concept concept = conceptService.getConceptByUuid(conceptUuid); - if (concept != null && concept.isSet()) { - return concept.getSetMembers(); - } - return Collections.emptyList(); - } -} diff --git a/condition-list/src/main/resources/Condition.hbm.xml b/condition-list/src/main/resources/Condition.hbm.xml deleted file mode 100644 index baa5d8f75..000000000 --- a/condition-list/src/main/resources/Condition.hbm.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - conditions_condition_id_seq - - - - - - - - - org.openmrs.module.emrapi.conditionslist.Condition$Status - 12 - - - - - - - - - - - - - - - - - - - - diff --git a/condition-list/src/main/resources/moduleApplicationContext.xml b/condition-list/src/main/resources/moduleApplicationContext.xml deleted file mode 100644 index d3f5541bd..000000000 --- a/condition-list/src/main/resources/moduleApplicationContext.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.openmrs.module.emrapi.conditionslist.ConditionService - - - - - diff --git a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistoryMapperTest.java b/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistoryMapperTest.java deleted file mode 100644 index cd6eb1b2c..000000000 --- a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionHistoryMapperTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import java.util.Arrays; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.openmrs.Concept; -import org.openmrs.Patient; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class ConditionHistoryMapperTest { - - @Mock - public ConditionMapper conditionMapper; - - private ConditionHistoryMapper conditionHistoryMapper; - - @Before - public void setUp() throws Exception { - initMocks(this); - - conditionHistoryMapper = new ConditionHistoryMapper(conditionMapper); - - when(conditionMapper.map(any(org.openmrs.module.emrapi.conditionslist.Condition.class))).then(new Answer() { - - @Override - public Condition answer(final InvocationOnMock invocationOnMock) throws Throwable { - return new Condition() {{ - setUuid(((org.openmrs.module.emrapi.conditionslist.Condition) invocationOnMock.getArguments()[0]).getUuid()); - }}; - } - }); - } - - @Test - public void shouldMapConditionHistoryModalToContract() throws Exception { - org.openmrs.module.emrapi.conditionslist.ConditionHistory conditionHistory = new org.openmrs.module.emrapi.conditionslist.ConditionHistory(); - org.openmrs.module.emrapi.conditionslist.Condition condition1 = getCondition("uuid_one"); - org.openmrs.module.emrapi.conditionslist.Condition condition2 = getCondition("uuid_two"); - org.openmrs.module.emrapi.conditionslist.Condition condition3 = getCondition("uuid_three"); - conditionHistory.setConditions(Arrays.asList(condition1, condition2, condition3)); - conditionHistory.setCondition(new Concept()); - - ConditionHistory conditionHistoryContract = conditionHistoryMapper.map(conditionHistory); - - assertEquals("uuid_one", conditionHistoryContract.getConditions().get(0).getUuid()); - assertEquals("uuid_two", conditionHistoryContract.getConditions().get(1).getUuid()); - assertEquals("uuid_three", conditionHistoryContract.getConditions().get(2).getUuid()); - } - - @Test - public void shouldMapConditionHistoryModalsToListOfContracts() throws Exception { - org.openmrs.module.emrapi.conditionslist.ConditionHistory conditionHistory1 = new org.openmrs.module.emrapi.conditionslist.ConditionHistory(); - org.openmrs.module.emrapi.conditionslist.Condition condition1 = getCondition("uuid_one"); - org.openmrs.module.emrapi.conditionslist.Condition condition2 = getCondition("uuid_two"); - org.openmrs.module.emrapi.conditionslist.Condition condition3 = getCondition("uuid_three"); - conditionHistory1.setConditions(Arrays.asList(condition1, condition2, condition3)); - conditionHistory1.setCondition(new Concept()); - - org.openmrs.module.emrapi.conditionslist.ConditionHistory conditionHistory2 = new org.openmrs.module.emrapi.conditionslist.ConditionHistory(); - org.openmrs.module.emrapi.conditionslist.Condition condition4 = getCondition("uuid_four"); - org.openmrs.module.emrapi.conditionslist.Condition condition5 = getCondition("uuid_five"); - org.openmrs.module.emrapi.conditionslist.Condition condition6 = getCondition("uuid_six"); - conditionHistory2.setConditions(Arrays.asList(condition4, condition5, condition6)); - conditionHistory2.setCondition(new Concept()); - - List conditionHistoryContracts = conditionHistoryMapper.map(Arrays.asList(conditionHistory1, - conditionHistory2)); - - List conditions1 = conditionHistoryContracts.get(0).getConditions(); - List conditions2 = conditionHistoryContracts.get(1).getConditions(); - assertEquals("uuid_one", conditions1.get(0).getUuid()); - assertEquals("uuid_two", conditions1.get(1).getUuid()); - assertEquals("uuid_three", conditions1.get(2).getUuid()); - - assertEquals("uuid_four", conditions2.get(0).getUuid()); - assertEquals("uuid_five", conditions2.get(1).getUuid()); - assertEquals("uuid_six", conditions2.get(2).getUuid()); - } - - private org.openmrs.module.emrapi.conditionslist.Condition getCondition(String uuid) { - org.openmrs.module.emrapi.conditionslist.Condition condition = new org.openmrs.module.emrapi.conditionslist.Condition(); - condition.setPatient(new Patient()); - condition.setConcept(new Concept()); - condition.setUuid(uuid); - return condition; - } -} \ No newline at end of file diff --git a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionMapperTest.java b/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionMapperTest.java deleted file mode 100644 index 11b21901b..000000000 --- a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/contract/ConditionMapperTest.java +++ /dev/null @@ -1,189 +0,0 @@ -package org.openmrs.module.emrapi.conditionslist.contract; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.openmrs.module.emrapi.conditionslist.Condition.Status.INACTIVE; - -import java.util.Date; -import java.util.Locale; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.openmrs.Concept; -import org.openmrs.ConceptName; -import org.openmrs.Patient; -import org.openmrs.User; -import org.openmrs.api.AdministrationService; -import org.openmrs.api.ConceptService; -import org.openmrs.api.PatientService; -import org.openmrs.api.context.Context; -import org.openmrs.module.emrapi.conditionslist.ConditionListConstants; -import org.openmrs.module.emrapi.conditionslist.DateConverter; -import org.openmrs.util.LocaleUtility; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(value = {Context.class, LocaleUtility.class}) -public class ConditionMapperTest { - - @Mock - public PatientService patientService; - - @Mock - public ConceptService conceptService; - - @Mock - public AdministrationService administrationService; - - private ConditionMapper conditionMapper; - - @Before - public void before() { - initMocks(this); - PowerMockito.mockStatic(Context.class); - PowerMockito.mockStatic(LocaleUtility.class); - when(Context.getConceptService()).thenReturn(conceptService); - when(Context.getPatientService()).thenReturn(patientService); - when(Context.getAdministrationService()).thenReturn(administrationService); - when(Context.getLocale()).thenReturn(Locale.ENGLISH); - - String nonCodedUuid = "nonCodedUuid"; - Concept nonCodedConcept = new Concept(); - nonCodedConcept.setUuid(nonCodedUuid); - when(administrationService.getGlobalProperty(ConditionListConstants.GLOBAL_PROPERTY_NON_CODED_UUID)).thenReturn( - nonCodedUuid); - when(conceptService.getConceptByUuid(nonCodedUuid)).thenReturn(nonCodedConcept); - - conditionMapper = new ConditionMapper(); - } - - @Test - public void shouldMapOpenmrsConditionToContractCondition() throws Exception { - String uuid = "13a1234-asdf23-ad23425as-sas90"; - Date today = new Date(); - String conceptUuid = "10924-1294124-1284u12-12841"; - String patientUuid = "13a1234-asdf23-ad2354-sas23"; - String additionalDetail = "some notes"; - String endReasonUuid = "end-reason-uuid-288a-asdf"; - - org.openmrs.module.emrapi.conditionslist.Condition prevOpenmrsCondition = new org.openmrs.module.emrapi.conditionslist.Condition(); - org.openmrs.module.emrapi.conditionslist.Condition openmrsCondition = new org.openmrs.module.emrapi.conditionslist.Condition(); - openmrsCondition.setDateCreated(new Date()); - openmrsCondition.setPreviousCondition(prevOpenmrsCondition); - openmrsCondition.setOnsetDate(today); - openmrsCondition.setUuid(uuid); - - Concept concept = new Concept(); - concept.setFullySpecifiedName(new ConceptName("dog bite", Locale.ENGLISH)); - Concept endReason = new Concept(); - endReason.setFullySpecifiedName(new ConceptName("end", Locale.ENGLISH)); - endReason.setUuid(endReasonUuid); - openmrsCondition.setEndReason(endReason); - - concept.setUuid(conceptUuid); - Patient patient = new Patient(); - patient.setUuid(patientUuid); - openmrsCondition.setConcept(concept); - openmrsCondition.setPatient(patient); - openmrsCondition.setStatus(INACTIVE); - openmrsCondition.setAdditionalDetail(additionalDetail); - - User creator = new User(); - creator.setUsername("CREATOR"); - openmrsCondition.setCreator(creator); - - Condition condition = conditionMapper.map(openmrsCondition); - - assertEquals(uuid, condition.getUuid()); - assertEquals(prevOpenmrsCondition.getUuid(), condition.getPreviousConditionUuid()); - assertEquals(conceptUuid, condition.getConcept().getUuid()); - assertEquals(patientUuid, condition.getPatientUuid()); - assertEquals(openmrsCondition.getDateCreated(), condition.getDateCreated()); - assertEquals(today, DateConverter.deserialize(condition.getOnSetDate())); - assertEquals(additionalDetail, condition.getAdditionalDetail()); - - assertEquals(null, condition.getEndDate()); - assertEquals(endReasonUuid, condition.getEndReason().getUuid()); - assertEquals(INACTIVE, condition.getStatus()); - - assertEquals("(CREATOR)", condition.getCreator()); - } - - @Test - public void shouldMapContractConditionToOpenmrsCondition() throws Exception { - String uuid = "13a1234-asdf23-ad23425as-sas90"; - Date today = new Date(); - String conceptUuid = "10924-1294124-1284u12-12841"; - String patientUuid = "13a1234-asdf23-ad2354-sas23"; - String additionalDetail = "some notes"; - String endReasonUuid = "end-reason-uuid-288a-asdf"; - - Condition condition = new Condition(); - condition.setOnSetDate(DateConverter.serialize(today)); - condition.setUuid(uuid); - - Concept concept = new Concept(); - Concept endReason = new Concept(); - endReason.setUuid(endReasonUuid); - condition.setEndReason(new org.openmrs.module.emrapi.conditionslist.contract.Concept(endReasonUuid, "somename")); - condition.setEndDate(DateConverter.serialize(today)); - - concept.setUuid(conceptUuid); - Patient patient = new Patient(); - patient.setUuid(patientUuid); - condition.setConcept(new org.openmrs.module.emrapi.conditionslist.contract.Concept(conceptUuid, "somename")); - condition.setPatientUuid(patientUuid); - condition.setStatus(INACTIVE); - condition.setAdditionalDetail(additionalDetail); - - when(patientService.getPatientByUuid(patientUuid)).thenReturn(patient); - when(conceptService.getConceptByUuid(conceptUuid)).thenReturn(concept); - when(conceptService.getConceptByUuid(endReasonUuid)).thenReturn(endReason); - - org.openmrs.module.emrapi.conditionslist.Condition openmrsCondition = conditionMapper.map(condition); - - assertEquals(uuid, openmrsCondition.getUuid()); - assertEquals(conceptUuid, openmrsCondition.getConcept().getUuid()); - assertEquals(patientUuid, openmrsCondition.getPatient().getUuid()); - assertEquals(today, openmrsCondition.getOnsetDate()); - assertEquals(additionalDetail, openmrsCondition.getAdditionalDetail()); - - assertEquals(today, openmrsCondition.getEndDate()); - assertEquals(endReasonUuid, openmrsCondition.getEndReason().getUuid()); - assertEquals(INACTIVE, openmrsCondition.getStatus()); - - } - - @Test - public void shouldUseDefaultLocaleWhenConceptNameNotInUseLocale() throws Exception{ - String patientUuid = "13a1234-asdf23-ad2354-sas23"; - Concept concept = new Concept(); - String conceptUuid = "conceptUuid"; - ConceptName conceptNameInUK = new ConceptName("Name in Uk", Locale.UK); - concept.setUuid(conceptUuid); - concept.setFullySpecifiedName(conceptNameInUK); - - org.openmrs.module.emrapi.conditionslist.Condition openmrsCondition = new org.openmrs.module.emrapi.conditionslist.Condition(); - openmrsCondition.setConcept(concept); - - Patient patient = new Patient(); - patient.setUuid(patientUuid); - openmrsCondition.setPatient(patient); - - User creator = new User(); - creator.setUsername("CREATOR"); - openmrsCondition.setCreator(creator); - - when(Context.getLocale()).thenReturn(Locale.FRANCE); - when(LocaleUtility.getDefaultLocale()).thenReturn(Locale.UK); - - Condition condition = conditionMapper.map(openmrsCondition); - - assertEquals(condition.getConcept().getName(),"Name in Uk"); - } -} \ No newline at end of file diff --git a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/db/ConditionDAOTest.java b/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/db/ConditionDAOTest.java deleted file mode 100644 index db484d971..000000000 --- a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/db/ConditionDAOTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * 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.module.emrapi.conditionslist.db; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openmrs.Patient; -import org.openmrs.api.PatientService; -import org.openmrs.module.emrapi.conditionslist.Condition; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; - -public class ConditionDAOTest extends BaseModuleContextSensitiveTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Autowired - ConditionDAO conditionDao; - - @Autowired - PatientService patientService; - - @Before - public void setUp() throws Exception { - executeDataSet("conditionListDataSet.xml"); - } - - @Test - public void shouldGetConditionByUuid() { - Condition condition = conditionDao.getConditionByUuid("2cc6880e-2c46-11e4-9038-a6c5e4d22fb7"); - assertEquals(Condition.Status.INACTIVE, condition.getStatus()); - assertEquals("Tuberculosis", condition.getConcept().getName().getName()); - assertEquals("2015-01-12 00:00:00.0", condition.getDateCreated().toString()); - } - - @Test - public void shouldGetConditionsReturnNonVoidedConditionsInReverseChronologicalOrder() { - Patient patient = patientService.getPatient(3); - List conditionHistoryForPatient = conditionDao.getConditionHistory(patient); - assertEquals(4, conditionHistoryForPatient.size()); - assertEquals("wq4i8o0e-2n46-1zx4-58f4-a6i5trd22fb7", conditionHistoryForPatient.get(0).getUuid()); - assertEquals("p8ri8o0s-2m46-11e4-5df4-a6p5e4dh2fb7", conditionHistoryForPatient.get(1).getUuid()); - assertEquals("c84i8o0e-2n46-11e4-58f4-a6i5e4d22fb7", conditionHistoryForPatient.get(2).getUuid()); - assertEquals("p84i8o0r-2n46-mse4-58f4-a6i5e4du2fb7", conditionHistoryForPatient.get(3).getUuid()); - } - - @Test - public void shouldGetActiveConditionsForPatient() { - Patient patient = patientService.getPatient(3); - List activeConditions = conditionDao.getActiveConditions(patient); - assertEquals(3, activeConditions.size()); - } - - @Test - public void shouldGetActiveConditionsInReverseChronologicalOrderPatient() { - Patient patient = patientService.getPatient(3); - List activeConditions = conditionDao.getActiveConditions(patient); - assertEquals(3, activeConditions.size()); - assertEquals("wq4i8o0e-2n46-1zx4-58f4-a6i5trd22fb7", activeConditions.get(0).getUuid()); - assertEquals("p8ri8o0s-2m46-11e4-5df4-a6p5e4dh2fb7", activeConditions.get(1).getUuid()); - assertEquals("c84i8o0e-2n46-11e4-58f4-a6i5e4d22fb7", activeConditions.get(2).getUuid()); - } - - @Test - public void shouldThrowErrorWhenChangingConcept() { - Condition condition = conditionDao.getConditionByUuid("2cc6880e-2c46-11e4-9038-a6c5e4d22fb7"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Concept cannot be changed"); - condition.setConcept(conditionDao.getConditionByUuid("wq4i8o0e-2n46-1zx4-58f4-a6i5trd22fb7").getConcept()); - } - - @Test - public void shouldThrowErrorWhenChangingPatient() { - Condition condition = conditionDao.getConditionByUuid("2cc6880e-2c46-11e4-9038-a6c5e4d22fb7"); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Patient cannot be changed"); - condition.setPatient(conditionDao.getConditionByUuid("wq4i8o0e-2n46-1zx4-58f4-a6i5trd22fb7").getPatient()); - } -} \ No newline at end of file diff --git a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/impl/ConditionServiceImplTest.java b/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/impl/ConditionServiceImplTest.java deleted file mode 100644 index 3c377352b..000000000 --- a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/impl/ConditionServiceImplTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/** - * 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.module.emrapi.conditionslist.impl; - -import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.openmrs.module.emrapi.conditionslist.Condition.Status.ACTIVE; -import static org.openmrs.module.emrapi.conditionslist.Condition.Status.INACTIVE; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openmrs.Concept; -import org.openmrs.Patient; -import org.openmrs.api.ConceptService; -import org.openmrs.api.PatientService; -import org.openmrs.api.UserService; -import org.openmrs.module.emrapi.conditionslist.Condition; -import org.openmrs.module.emrapi.conditionslist.ConditionHistory; -import org.openmrs.module.emrapi.conditionslist.ConditionService; -import org.openmrs.module.emrapi.conditionslist.EmrConditionValidator; -import org.openmrs.module.emrapi.conditionslist.db.ConditionDAO; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; - -public class ConditionServiceImplTest extends BaseModuleContextSensitiveTest { - - @Autowired - ConditionService conditionService; - - @Autowired - ConceptService conceptService; - - @Autowired - PatientService patientService; - - @Autowired - UserService userService; - - @Autowired - EmrConditionValidator conditionValidator; - - @Autowired - ConditionDAO conditionDAO; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - executeDataSet("conditionListDataSet.xml"); - } - - @Test - public void shouldCreateNewCondition() { - Condition condition = createCondition(Condition.Status.ACTIVE, "Tuberculosis", 2, - "3584c584-c291-46c8-8584-96dc33d19584", null); - conditionService.save(condition); - List conditionsList = conditionDAO.getConditionHistory(condition.getPatient()); - assertEquals(conditionsList.size(), 3); - assertTrue(condition.getId() > 0); - assertEquals("3584c584-c291-46c8-8584-96dc33d19584", condition.getUuid()); - assertEquals(Condition.Status.ACTIVE, condition.getStatus()); - assertEquals("Tuberculosis", condition.getConcept().getName().getName()); - } - - @Test - public void shouldNotCreateDuplicateCondition() { - Condition condition = conditionService.getConditionByUuid("2cc6880e-2c46-11e4-9038-a6c5e4d22fb7"); - conditionService.save(condition); - List conditionsList = conditionDAO.getConditionHistory(condition.getPatient()); - assertEquals(conditionsList.size(), 4); - } - - @Test - public void shouldUpdateExistingCondition() { - Condition condition = conditionService.getConditionByUuid("2cc5840e-2c84-11e4-9038-a6c5e4d22fb7"); - condition.setStatus(Condition.Status.HISTORY_OF); - Condition savedCondition = conditionService.save(condition); - - assertEquals("Angina", savedCondition.getConcept().getDisplayString()); - assertEquals(Condition.Status.HISTORY_OF, savedCondition.getStatus()); - - List conditionsList = conditionDAO.getConditionHistory(condition.getPatient()); - assertEquals(conditionsList.size(), 4); - } - - @Test - public void shouldVoidConditionSetVoidedAndVoidReason() { - Condition condition = conditionService.getConditionByUuid("2ss6880e-2c46-11e4-5844-a6c5e4d22fb7"); - Condition voidedCondition = conditionService.voidCondition(condition, "voiding"); - assertTrue(voidedCondition.getVoided()); - assertEquals(voidedCondition.getVoidReason(), "voiding"); - } - - @Test - public void shouldMandateVoidReasonToVoidCondition() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("voidReason cannot be empty or null"); - Condition condition = conditionService.getConditionByUuid("2ss6880e-2c46-11e4-5844-a6c5e4d22fb7"); - conditionService.voidCondition(condition, null); - } - - @Test - public void shouldEndConditionSetEndDateAsTodayIfNotSpecified() { - Condition condition = conditionService.getConditionByUuid("2ss6880e-2c46-11e4-5844-a6c5e4d22fb7"); - Date endDate = new Date(); - Concept endReason = conceptService.getConceptByUuid("cured84f-1yz9-4da3-bb88-8122ce8868ss"); - condition.setEndReason(endReason); - Condition savedCondition = conditionService.save(condition); - assertEquals(savedCondition.getEndDate().getDate(), endDate.getDate()); - } - - @Test - public void shouldGetConditionHistoryReturnListOfConditionHistoryGroupedByConceptForPatient() { - Patient patient = patientService.getPatient(3); - List conditionHistoryForPatient = conditionService.getConditionHistory(patient); - assertEquals(conditionHistoryForPatient.size(), 4); - - assertThat(conditionHistoryForPatient, contains(new ConditionHistoryMatcher("severe", 1), - new ConditionHistoryMatcher("pain", 1), new ConditionHistoryMatcher("Angina", 1), - new ConditionHistoryMatcher("Tuberculosis", 1))); - } - - @Test - public void shouldSetOnsetDateOfNewConditionAsEndDateForExistingIfStatusHasChanged() throws Exception { - Date newOnSetDate = new SimpleDateFormat("yyyy-MM-dd").parse("2017-01-01"); - Condition existingCondition = conditionService.getConditionByUuid("c84i8o0e-2n46-11e4-58f4-a6i5e4d22fb7"); - - assertEquals(existingCondition.getStatus(), ACTIVE); - - Condition condition = Condition.newInstance(existingCondition); - condition.setUuid(existingCondition.getUuid()); - condition.setOnsetDate(newOnSetDate); - condition.setStatus(INACTIVE); - - Condition newCondition = conditionService.save(condition); - - assertNotSame(existingCondition, newCondition); - assertNotSame(existingCondition.getUuid(), newCondition.getUuid()); - assertEquals(ACTIVE, existingCondition.getStatus()); - assertEquals(INACTIVE, newCondition.getStatus()); - assertTrue(isEquals(newOnSetDate, existingCondition.getEndDate())); - assertTrue(isEquals(newOnSetDate, newCondition.getOnsetDate())); - assertNull(newCondition.getEndDate()); - } - - @Test - public void shouldSetEndDateIfStatusHasChangedAndEndDateIsNull() { - Date today = new Date(); - Condition existingCondition = conditionService.getConditionByUuid("c84i8o0e-2n46-11e4-58f4-a6i5e4d22fb7"); - - assertEquals(existingCondition.getStatus(), ACTIVE); - - Condition condition = Condition.newInstance(existingCondition); - condition.setUuid(existingCondition.getUuid()); - condition.setStatus(INACTIVE); - - Condition newCondition = conditionService.save(condition); - - assertNotSame(condition, newCondition); - assertNotSame(existingCondition.getUuid(), newCondition.getUuid()); - assertEquals(ACTIVE, existingCondition.getStatus()); - assertEquals(INACTIVE, newCondition.getStatus()); - assertTrue(isEquals(today, existingCondition.getEndDate())); - assertTrue(isEquals(today, newCondition.getOnsetDate())); - assertNull(newCondition.getEndDate()); - } - - private boolean isEquals(Date date1, Date date2) { - return (date2.getTime() - date1.getTime()) < 1000; - } - - public static class ConditionHistoryMatcher extends TypeSafeMatcher { - - private final String name; - - private final int count; - - public ConditionHistoryMatcher(String name, int count) { - this.name = name; - this.count = count; - } - - @Override - public void describeTo(Description description) { - description.appendText("condition: ").appendValue(name).appendText("count: ").appendValue(count); - } - - @Override - protected boolean matchesSafely(ConditionHistory item) { - return (item.getCondition().getName().getName().equals(name) || item.getNonCodedCondition().equals(name)) - && count == item.getConditions().size(); - } - - } - - private Condition createCondition(Condition.Status status, String conceptName, int patientId, String uuid, - String conditionNonCoded) { - Condition condition = new Condition(); - condition.setStatus(status); - Concept concept = conceptService.getConceptByName(conceptName); - condition.setConcept(concept); - Patient patient = patientService.getPatient(patientId); - condition.setPatient(patient); - Date dateCreated = new Date(); - condition.setDateCreated(dateCreated); - condition.setUuid(uuid); - condition.setConditionNonCoded(conditionNonCoded); - return condition; - } -} diff --git a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/validator/ConditionValidatorTest.java b/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/validator/ConditionValidatorTest.java deleted file mode 100644 index 3747b488a..000000000 --- a/condition-list/src/test/java/org/openmrs/module/emrapi/conditionslist/validator/ConditionValidatorTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * 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.module.emrapi.conditionslist.validator; - -import java.util.Date; -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openmrs.Concept; -import org.openmrs.Patient; -import org.openmrs.User; -import org.openmrs.api.ConceptService; -import org.openmrs.api.PatientService; -import org.openmrs.api.UserService; -import org.openmrs.module.emrapi.conditionslist.Condition; -import org.openmrs.module.emrapi.conditionslist.ConditionService; -import org.openmrs.module.emrapi.conditionslist.EmrConditionValidator; -import org.openmrs.test.BaseModuleContextSensitiveTest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ObjectError; - -public class ConditionValidatorTest extends BaseModuleContextSensitiveTest { - - @Autowired - ConditionService conditionService; - - @Autowired - ConceptService conceptService; - - @Autowired - UserService userService; - - @Autowired - PatientService patientService; - - @Autowired - EmrConditionValidator conditionValidator; - - @Before - public void setUp() throws Exception { - executeDataSet("conditionListDataSet.xml"); - } - - @Test - public void validate_shouldFailValidationIfConditionIsNull() throws Exception { - Errors errors = new BindException(new Condition(), "condition"); - conditionValidator.validate(null, errors); - Assert.assertTrue(errors.hasErrors()); - Assert.assertEquals("error.general", ((List) errors.getAllErrors()).get(0).getCode()); - } - - @Test - public void shouldNotAllowNonCodedConceptConditionWithoutNonCodedConditionValue() { - Condition condition = conditionService.getConditionByUuid("2ss6880e-2c46-11e4-9038-a6c5e4d22fb7"); - Errors errors = new BindException(condition, "condition"); - conditionValidator.validate(condition, errors); - Assert.assertTrue(errors.hasErrors()); - Assert.assertEquals("Condition.error.conditionNonCodedValueNeededForNonCodedCondition", - ((List) errors.getAllErrors()).get(0).getCode()); - } - - @Test - public void shouldNotAllowNonCodedValueForCodedConceptCondition() { - Condition condition = conditionService.getConditionByUuid("2ss6880e-2c46-11e4-5844-a6c5e4d22fb7"); - Errors errors = new BindException(condition, "condition"); - conditionValidator.validate(condition, errors); - Assert.assertTrue(errors.hasErrors()); - Assert.assertEquals("Condition.error.conditionNonCodedValueNotSupportedForCodedCondition", - ((List) errors.getAllErrors()).get(0).getCode()); - } - - @Test - public void shouldNotAllowDuplicateConditionsWhiteSpacesAndCaseChangesInConditionNonCodedValue() { - Condition condition = createCondition(Condition.Status.ACTIVE, "OTHER, NON-CODED", 2, - "3584c584-c291-46c8-8584-96dc33d19584", "P a I n"); - Errors errors = new BindException(condition, "condition"); - conditionValidator.validate(condition, errors); - Assert.assertTrue(errors.hasErrors()); - Assert.assertEquals("Condition.error.duplicatesNotAllowed", - ((List) errors.getAllErrors()).get(0).getCode()); - } - - @Test - public void shouldNotAllowInValidEndReasonConcept() { - Condition condition = createCondition(Condition.Status.INACTIVE, "Tuberculosis", 1, - "2cc6880e-2c46-11e4-9038-a6c5e4d22fb7", null); - Concept endReasonConcept = conceptService.getConceptByName("invalid end reason"); - condition.setEndReason(endReasonConcept); - Errors errors = new BindException(condition, "condition"); - conditionValidator.validate(condition, errors); - Assert.assertTrue(errors.hasErrors()); - Assert.assertEquals("Condition.error.notAmongAllowedConcepts", - ((List) errors.getAllErrors()).get(0).getCode()); - } - - @Test - public void shouldAllowValidEndReasonConcept() { - Condition condition = createCondition(Condition.Status.INACTIVE, "Tuberculosis", 1, - "2cc6880e-2c46-11e4-9038-a6c5e4d22fb7", null); - Concept endReasonConcept = conceptService.getConceptByName("cured"); - condition.setEndReason(endReasonConcept); - Errors errors = new BindException(condition, "condition"); - conditionValidator.validate(condition, errors); - Assert.assertFalse(errors.hasErrors()); - } - - @Test - public void shouldMandateEndReasonToEndCondition() { - Condition condition = conditionService.getConditionByUuid("2cc6880e-2c46-11e4-9038-a6c5e4d22fb7"); - condition.setEndDate(new Date()); - Errors errors = new BindException(condition, "condition"); - conditionValidator.validate(condition, errors); - Assert.assertEquals("Condition.error.endReasonIsMandatory", - ((List) errors.getAllErrors()).get(0).getCode()); - } - - private Condition createCondition(Condition.Status status, String conceptName, int patientId, String uuid, - String conditionNonCoded) { - Condition condition = new Condition(); - Concept concept = conceptService.getConceptByName(conceptName); - condition.setConcept(concept); - - Patient patient = patientService.getPatient(patientId); - condition.setPatient(patient); - - User user = userService.getUserByUsername("superman"); - condition.setCreator(user); - condition.setStatus(status); - condition.setDateCreated(new Date()); - condition.setVoided(false); - condition.setConditionNonCoded(conditionNonCoded); - condition.setUuid(uuid); - - return condition; - } -} \ No newline at end of file diff --git a/condition-list/src/test/resources/TestingApplicationContext.xml b/condition-list/src/test/resources/TestingApplicationContext.xml deleted file mode 100644 index 8aa187e55..000000000 --- a/condition-list/src/test/resources/TestingApplicationContext.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - classpath:hibernate.cfg.xml - classpath:test-hibernate.cfg.xml - - - - - - - - org.openmrs - - - - - - diff --git a/condition-list/src/test/resources/conditionListDataSet.xml b/condition-list/src/test/resources/conditionListDataSet.xml deleted file mode 100644 index e7adbb0a9..000000000 --- a/condition-list/src/test/resources/conditionListDataSet.xml +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/condition-list/src/test/resources/test-hibernate.cfg.xml b/condition-list/src/test/resources/test-hibernate.cfg.xml deleted file mode 100644 index bed9eac08..000000000 --- a/condition-list/src/test/resources/test-hibernate.cfg.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - diff --git a/pom.xml b/pom.xml index 7e851b6b0..b84947e88 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,6 @@ api - condition-list omod