diff --git a/Allergy/pom.xml b/Allergy/pom.xml
new file mode 100644
index 000000000..1e6a67a61
--- /dev/null
+++ b/Allergy/pom.xml
@@ -0,0 +1,86 @@
+
+
+ 4.0.0
+
+ org.openmrs.module
+ emrapi
+ 1.28.0-SNAPSHOT
+
+ org.openmrs.module
+ emrapi-Allergy
+ 1.28.0-SNAPSHOT
+ EMR API Allergy
+
+ http://maven.apache.org
+
+
+ 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
+
+
+
+
+
diff --git a/Allergy/src/main/java/org/Allergy/App.java b/Allergy/src/main/java/org/Allergy/App.java
new file mode 100644
index 000000000..5b3280e12
--- /dev/null
+++ b/Allergy/src/main/java/org/Allergy/App.java
@@ -0,0 +1,13 @@
+package org.Allergy;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyHistory.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyHistory.java
new file mode 100644
index 000000000..150ad1ade
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyHistory.java
@@ -0,0 +1,49 @@
+package org.openmrs.module.emrapi.allergy;
+
+import java.util.List;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.openmrs.Concept;
+import org.openmrs.module.emrapi.allergy.Allergy_New;
+
+public class AllergyHistory {
+private String nonCodedAllergy;
+
+ private Concept allergy;
+
+ private List allergy_News;
+
+ public String getNonCodedAllergy() {
+ return nonCodedAllergy;
+ }
+
+ public void setNonCodedAllergy(String nonCodedAllergy) {
+ this.nonCodedAllergy = nonCodedAllergy;
+ }
+
+ public Concept getAllergy() {
+ return allergy;
+ }
+
+ public void setAllergy(Concept allergy) {
+ this.allergy = allergy;
+ }
+
+ public List getAllergies() {
+ return allergy_News;
+ }
+
+ public void setAllergies(List allergy_News) {
+ this.allergy_News = allergy_News;
+ }
+
+ @Override
+ public String toString() {
+ String name = nonCodedAllergy;
+ if (name != null && allergy != null && allergy.getName() != null) {
+ name = allergy.getName().getName();
+ }
+
+ return new ToStringBuilder(this).append("allergy", name).append("count", allergy_News.size()).build();
+ }
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyListConstant.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyListConstant.java
new file mode 100644
index 000000000..695c4e096
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyListConstant.java
@@ -0,0 +1,14 @@
+package org.openmrs.module.emrapi.allergy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class AllergyListConstant {
+
+ private static Log log = LogFactory.getLog(AllergyListConstant.class);
+
+ public static final String GP_END_REASON_CONCEPT_SET_UUID = "alergyList.endReasonConceptSetUuid";
+
+ public static final String GLOBAL_PROPERTY_NON_CODED_UUID = "alergyList.nonCodedUuid";
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyService.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyService.java
new file mode 100644
index 000000000..260ff55ad
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/AllergyService.java
@@ -0,0 +1,28 @@
+package org.openmrs.module.emrapi.allergy;
+
+import java.util.List;
+
+import org.openmrs.Concept;
+import org.openmrs.Patient;
+import org.openmrs.annotation.Authorized;
+import org.openmrs.api.OpenmrsService;
+
+
+@Deprecated
+public interface AllergyService extends OpenmrsService {
+
+ @Authorized({ PrivilegeAllergyConstant.EDIT_ALLERGIES })
+ Allergy_New save(Allergy_New allergy_New);
+
+ @Authorized({ PrivilegeAllergyConstant.EDIT_ALLERGIES })
+ Allergy_New voidAllergy(Allergy_New allergy_New, String voidReason);
+
+ Allergy_New getAllergyByUuid(String uuid);
+
+ List getAllergyHistory(Patient patient);
+
+ @Authorized({ PrivilegeAllergyConstant.GET_ALLERGIES })
+ List getActiveAllergy(Patient patient);
+
+ List getEndReasonConcepts();
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/Allergy_New.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/Allergy_New.java
new file mode 100644
index 000000000..c79ba126a
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/Allergy_New.java
@@ -0,0 +1,307 @@
+package org.openmrs.module.emrapi.allergy;
+
+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.Patient;
+
+
+public class Allergy_New extends BaseOpenmrsData implements java.io.Serializable{
+
+ public static final long serialVersionUID = 2L;
+
+ protected final Log log = LogFactory.getLog(getClass());
+
+ /**
+ * default empty constructor
+ */
+ public Allergy_New() {
+ }
+
+ /**
+ * @param allergyId Integer to create this allergy object from
+ */
+ public Allergy_New(Integer allergyId) {
+ this.allergyId = allergyId;
+ }
+
+ public enum Status {
+ ACTIVE, INACTIVE, HISTORY_OF
+ }
+
+ private Integer allergyId;
+
+ private Allergy_New previousAllergy;
+
+ private Patient patient;
+
+ private Status status = Status.ACTIVE;
+
+ private Concept concept;
+
+ private String allergyNonCoded;
+
+ private Date onsetDate;
+
+ private String additionalDetail;
+
+ private Date endDate;
+
+ private Concept endReason;
+
+ public static Allergy_New newInstance(Allergy_New allergy_New) {
+ return copy(allergy_New, new Allergy_New());
+ }
+
+ public static Allergy_New copy(Allergy_New fromAllergy, Allergy_New toAllergy) {
+ toAllergy.setPreviousAllergy(fromAllergy.getPreviousAllergy());
+ toAllergy.setPatient(fromAllergy.getPatient());
+ toAllergy.setStatus(fromAllergy.getStatus());
+ toAllergy.setConcept(fromAllergy.getConcept());
+ toAllergy.setAllergyNonCoded(fromAllergy.getAllergyNonCoded());
+ toAllergy.setOnsetDate(fromAllergy.getOnsetDate());
+ toAllergy.setAdditionalDetail(fromAllergy.getAdditionalDetail());
+ toAllergy.setEndDate(fromAllergy.getEndDate());
+ toAllergy.setEndReason(fromAllergy.getEndReason());
+ toAllergy.setVoided(fromAllergy.getVoided());
+ toAllergy.setVoidedBy(fromAllergy.getVoidedBy());
+ toAllergy.setVoidReason(fromAllergy.getVoidReason());
+ toAllergy.setDateVoided(fromAllergy.getDateVoided());
+ return toAllergy;
+ }
+
+ /**
+ * @return Returns the allergyId.
+ */
+ public Integer getAllergyId() {
+ return allergyId;
+ }
+
+ /**
+ * @param allergyId The allergyId to set.
+ */
+ public void setAllergyId(Integer allergyId) {
+ this.allergyId = allergyId;
+ }
+
+ /**
+ * @return Returns the previousallergy.
+ */
+ public Allergy_New getPreviousAllergy() {
+ return previousAllergy;
+ }
+
+ /**
+ * @param previousallergy The previousallergy to set.
+ * When a allergy is altered (e.g., a symptom explicitly converted into a diagnosis), this
+ * field
+ * is used to link the new allergy to the allergy(s) it has replaced.
+ */
+ public void setPreviousAllergy(Allergy_New previousAllergy) {
+ this.previousAllergy = previousAllergy;
+ }
+
+ /**
+ * @return Returns the patient.
+ */
+ public Patient getPatient() {
+ return patient;
+ }
+
+ /**
+ * @param patient The patient to set.
+ */
+ public void setPatient(Patient patient) {
+ if (getAllergyId() != 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 allergy. Default is ACTIVE.
+ *
+ * - ACTIVE when the allergy is suspected, but not yet confirmed
+ * (HL7 uses the term "working")
+ * - INACTIVE when the allergy has been confirmed (typically for
+ * diagnoses)
+ * - HISTORY_OF when the history of a allergy is relevant to the
+ * patient's ongoing medical care (e.g., history of stroke)
+ *
+ */
+ 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 (getAllergyId() != null && getConcept() != null && !getConcept().equals(concept)) {
+ throw new IllegalArgumentException("Concept cannot be changed");
+ }
+ this.concept = concept;
+ }
+
+ /**
+ * @return Returns the allergyNonCoded.
+ */
+ public String getAllergyNonCoded() {
+ return allergyNonCoded;
+ }
+
+ /**
+ * @param allergyNonCoded The allergyNonCoded to set.
+ * When a allergy is not codified, the concept for the allergy is set to a concept for
+ * NON-CODED and the free text representation of the allergy is stored here.
+ */
+ public void setAllergyNonCoded(String allergyNonCoded) {
+ if (getAllergyId() != null && getAllergyNonCoded() != null && !getAllergyNonCoded().equals(
+ allergyNonCoded)) {
+ throw new IllegalArgumentException("allergy non coded cannot be changed");
+ }
+ this.allergyNonCoded = allergyNonCoded;
+ }
+
+ /**
+ * @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 allergy. 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 allergy 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 getAllergyId();
+ }
+
+ /**
+ * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
+ */
+ @Override
+ public void setId(Integer allergyId) {
+ setAllergyId(allergyId);
+ }
+
+ @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;
+ }
+
+ Allergy_New allergy_New = (Allergy_New) o;
+
+ if (!patient.equals(allergy_New.patient)) {
+ return false;
+ }
+ if (status != allergy_New.status) {
+ return false;
+ }
+ if (!concept.equals(allergy_New.concept)) {
+ return false;
+ }
+ if (allergyNonCoded != null ?
+ !allergyNonCoded.equals(allergy_New.allergyNonCoded) :
+ allergy_New.allergyNonCoded != null) {
+ return false;
+ }
+ if (onsetDate != null ? !onsetDate.equals(allergy_New.onsetDate) : allergy_New.onsetDate != null) {
+ return false;
+ }
+ if (additionalDetail != null ?
+ !additionalDetail.equals(allergy_New.additionalDetail) :
+ allergy_New.additionalDetail != null) {
+ return false;
+ }
+ if (endDate != null ? !endDate.equals(allergy_New.endDate) : allergy_New.endDate != null) {
+ return false;
+ }
+ return endReason != null ? endReason.equals(allergy_New.endReason) : allergy_New.endReason == null;
+ }
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/EmrAllergyValidator.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/EmrAllergyValidator.java
new file mode 100644
index 000000000..67fdae072
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/EmrAllergyValidator.java
@@ -0,0 +1,101 @@
+package org.openmrs.module.emrapi.allergy;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openmrs.Concept;
+import org.openmrs.api.AdministrationService;
+import org.springframework.validation.Errors;
+import org.springframework.validation.ValidationUtils;
+import org.springframework.validation.Validator;
+public class EmrAllergyValidator implements Validator {
+
+ /**
+ * Log for this class and subclasses
+ */
+ protected final Log log = LogFactory.getLog(getClass());
+
+ private AdministrationService administrationService;
+
+ private AllergyService allergyService;
+
+ public EmrAllergyValidator(AllergyService allergyService, AdministrationService administrationService) {
+ this.allergyService = allergyService;
+ 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 Allergy_New.class.isAssignableFrom(c);
+ }
+
+ @Override
+ public void validate(Object obj, Errors errors) {
+
+ Allergy_New allergy_New = (Allergy_New) obj;
+ if (allergy_New == 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");
+
+ validateNonCodedAllergy(allergy_New, errors);
+ validateDuplicateAllergies(allergy_New, errors);
+ validateEndReasonConcept(allergy_New, errors);
+ }
+
+ }
+
+ private void validateEndReasonConcept(Allergy_New allergy_New, Errors errors) {
+ if (allergy_New.getEndReason() == null) {
+ if (allergy_New.getEndDate() != null) {
+ errors.rejectValue("endReason", "Condition.error.endReasonIsMandatory");
+ }
+ } else {
+ List endReasonConcepts = allergyService.getEndReasonConcepts();
+ if (!endReasonConcepts.contains(allergy_New.getEndReason())) {
+ errors.rejectValue("endReason", "Condition.error.notAmongAllowedConcepts");
+ }
+ }
+ }
+
+ private void validateDuplicateAllergies(Allergy_New allergy_New, Errors errors) {
+ List conditionsForPatient = allergyService.getActiveAllergy(allergy_New.getPatient());
+ if (allergy_New.getAllergyNonCoded() != null) {
+ for (Allergy_New eachCondition : conditionsForPatient) {
+ if (eachCondition.getConcept().equals(allergy_New.getConcept())
+ && eachCondition.getAllergyNonCoded().equalsIgnoreCase(
+ allergy_New.getAllergyNonCoded().replaceAll("\\s", "")) && !eachCondition.getUuid().equals(
+ allergy_New.getUuid())) {
+ errors.rejectValue("concept", "Condition.error.duplicatesNotAllowed");
+ }
+ }
+ }
+ }
+
+ private void validateNonCodedAllergy(Allergy_New allergy_New, Errors errors) {
+ String nonCodedAllergyUuid = administrationService.getGlobalProperty(
+ AllergyListConstant.GLOBAL_PROPERTY_NON_CODED_UUID);
+ if (allergy_New.getAllergyNonCoded() != null) {
+ if (!allergy_New.getConcept().getUuid().equals(nonCodedAllergyUuid)) {
+ errors.rejectValue("conditionNonCoded",
+ "Condition.error.conditionNonCodedValueNotSupportedForCodedCondition");
+ }
+ } else {
+ if (allergy_New.getConcept().getUuid().equals(nonCodedAllergyUuid)) {
+ errors.rejectValue("allergyNonCoded", "Condition.error.conditionNonCodedValueNeededForNonCodedCondition");
+ }
+ }
+ }
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/PrivilegeAllergyConstant.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/PrivilegeAllergyConstant.java
new file mode 100644
index 000000000..8c124ce2c
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/PrivilegeAllergyConstant.java
@@ -0,0 +1,7 @@
+package org.openmrs.module.emrapi.allergy;
+
+public class PrivilegeAllergyConstant {
+ public static final String EDIT_ALLERGIES = "Edit allergies";
+
+ public static final String GET_ALLERGIES = "Get allergies";
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyHistory.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyHistory.java
new file mode 100644
index 000000000..852070d6f
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyHistory.java
@@ -0,0 +1,37 @@
+package org.openmrs.module.emrapi.allergy.contract;
+
+import java.util.List;
+
+import org.openmrs.module.emrapi.allergy.contract.Allergy_New;
+
+public class AllergyHistory {
+private String allergyNonCoded;
+
+ private String conceptUuid;
+
+ private List allergy_News;
+
+ public String getAllergyNonCoded() {
+ return allergyNonCoded;
+ }
+
+ public void setAllergyNonCoded(String allergyNonCoded) {
+ this.allergyNonCoded = allergyNonCoded;
+ }
+
+ public String getConceptUuid() {
+ return conceptUuid;
+ }
+
+ public void setConceptUuid(String conceptUuid) {
+ this.conceptUuid = conceptUuid;
+ }
+
+ public List getAllergies() {
+ return allergy_News;
+ }
+
+ public void setAllergies(List allergy_News) {
+ this.allergy_News = allergy_News;
+ }
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyHistoryMapper.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyHistoryMapper.java
new file mode 100644
index 000000000..75f8aa342
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyHistoryMapper.java
@@ -0,0 +1,37 @@
+package org.openmrs.module.emrapi.allergy.contract;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+
+
+public class AllergyHistoryMapper {
+
+ private AllergyMapper allergyMapper;
+
+ public AllergyHistoryMapper(AllergyMapper allergyMapper) {
+ this.allergyMapper = allergyMapper;
+ }
+
+ public AllergyHistory map(org.openmrs.module.emrapi.allergy.AllergyHistory allergyHistory) {
+ AllergyHistory allergyHistoryContract = new AllergyHistory();
+ allergyHistoryContract.setConceptUuid(allergyHistory.getAllergy().getUuid());
+
+ ArrayList< Allergy_New> allergy_News = new ArrayList< Allergy_New>();
+ for (org.openmrs.module.emrapi.allergy. Allergy_New allergy_New : allergyHistory.getAllergies()) {
+ allergy_News.add(allergyMapper.map(allergy_New));
+ }
+ allergyHistoryContract.setAllergies(allergy_News);;
+ allergyHistoryContract.setAllergyNonCoded(allergyHistory.getNonCodedAllergy());
+ return allergyHistoryContract;
+ }
+
+ public List map(List allergyHistories100) {
+ List allergyHistories101 = new ArrayList();
+ for (org.openmrs.module.emrapi.allergy.AllergyHistory allergyHistory : allergyHistories100) {
+ allergyHistories101.add(map(allergyHistory));
+ }
+ return allergyHistories101;
+ }
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyMapper.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyMapper.java
new file mode 100644
index 000000000..c8965c771
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/AllergyMapper.java
@@ -0,0 +1,86 @@
+package org.openmrs.module.emrapi.allergy.contract;
+
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.openmrs.util.LocaleUtility.getDefaultLocale;
+
+import java.util.Locale;
+
+import org.openmrs.ConceptName;
+import org.openmrs.Patient;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.emrapi.allergy.AllergyListConstant;
+import org.openmrs.module.emrapi.allergy.contract.Concept;
+public class AllergyMapper {
+ public Allergy_New map(org.openmrs.module.emrapi.allergy.Allergy_New openmrsAllergy) {
+ Concept concept = mapConcept(openmrsAllergy.getConcept());
+ Allergy_New allergy_New = new Allergy_New();
+ allergy_New.setUuid(openmrsAllergy.getUuid());
+ allergy_New.setAdditionalDetail(openmrsAllergy.getAdditionalDetail());
+ allergy_New.setStatus(openmrsAllergy.getStatus());
+ allergy_New.setConcept(concept);
+ allergy_New.setPatientUuid(openmrsAllergy.getPatient().getUuid());
+ allergy_New.setAllergyNonCoded(openmrsAllergy.getAllergyNonCoded());
+ allergy_New.setOnSetDate(openmrsAllergy.getOnsetDate());
+ allergy_New.setVoided(openmrsAllergy.getVoided());
+ allergy_New.setVoidReason(openmrsAllergy.getVoidReason());
+ allergy_New.setEndDate(openmrsAllergy.getEndDate());
+ allergy_New.setCreator(openmrsAllergy.getCreator().getDisplayString());
+ allergy_New.setDateCreated(openmrsAllergy.getDateCreated());
+ if (openmrsAllergy.getPreviousAllergy() != null) {
+ allergy_New.setPreviousAllergyUuid(openmrsAllergy.getPreviousAllergy().getUuid());
+ }
+ if (openmrsAllergy.getEndReason() != null) {
+ allergy_New.setEndReason(mapConcept(openmrsAllergy.getEndReason()));
+ }
+ return allergy_New;
+ }
+
+ public org.openmrs.module.emrapi.allergy.Allergy_New map(Allergy_New allergy_New) {
+ org.openmrs.Concept concept = Context.getConceptService().getConceptByUuid(allergy_New.getConcept().getUuid());
+ Patient patient = Context.getPatientService().getPatientByUuid(allergy_New.getPatientUuid());
+ String nonCodedAllergyConcept = Context.getAdministrationService().getGlobalProperty(
+ AllergyListConstant.GLOBAL_PROPERTY_NON_CODED_UUID);
+
+ org.openmrs.module.emrapi.allergy.Allergy_New openmrsAllergy = new org.openmrs.module.emrapi.allergy.Allergy_New();
+
+ if (!isEmpty(allergy_New.getAllergyNonCoded())) {
+ concept = Context.getConceptService().getConceptByUuid(nonCodedAllergyConcept);
+ }
+ if (allergy_New.getEndReason() != null) {
+ org.openmrs.Concept endReason = Context.getConceptService().getConceptByUuid(
+ allergy_New.getEndReason().getUuid());
+ openmrsAllergy.setEndReason(endReason);
+ }
+ if (allergy_New.getUuid() != null) {
+ openmrsAllergy.setUuid(allergy_New.getUuid());
+ }
+ openmrsAllergy.setAdditionalDetail(allergy_New.getAdditionalDetail());
+ openmrsAllergy.setStatus(allergy_New.getStatus());
+ openmrsAllergy.setConcept(concept);
+ openmrsAllergy.setPatient(patient);
+ openmrsAllergy.setAllergyNonCoded(allergy_New.getAllergyNonCoded());
+ openmrsAllergy.setOnsetDate(allergy_New.getOnSetDate());
+ openmrsAllergy.setEndDate(allergy_New.getEndDate());
+ openmrsAllergy.setVoided(allergy_New.getVoided());
+ openmrsAllergy.setVoidReason(allergy_New.getVoidReason());
+
+ return openmrsAllergy;
+ }
+
+ 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/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/Allergy_New.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/Allergy_New.java
new file mode 100644
index 000000000..2fe3d154f
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/Allergy_New.java
@@ -0,0 +1,155 @@
+package org.openmrs.module.emrapi.allergy.contract;
+
+import java.util.Date;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.openmrs.module.emrapi.allergy.contract.Concept;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Allergy_New {
+
+ public String uuid;
+
+ private String patientUuid;
+
+ private Concept concept;
+
+ private String allergyNonCoded;
+
+ private org.openmrs.module.emrapi.allergy.Allergy_New.Status status;
+
+ private Date onSetDate;
+
+ private Date endDate;
+
+ private Concept endReason;
+
+ private String additionalDetail;
+
+ private Boolean voided;
+
+ private String voidReason;
+
+ private String creator;
+
+ private Date dateCreated;
+
+ private String previousAllergyUuid;
+
+
+
+ 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 getAllergyNonCoded() {
+ return allergyNonCoded;
+ }
+
+ public void setAllergyNonCoded(String allergyNonCoded) {
+ this.allergyNonCoded = allergyNonCoded;
+ }
+
+ public String getPreviousAllergyUuid() {
+ return previousAllergyUuid;
+ }
+
+ public void setPreviousAllergyUuid(String previousAllergyUuid) {
+ this.previousAllergyUuid = previousAllergyUuid;
+ }
+
+ public Date getOnSetDate() {
+ return onSetDate;
+ }
+
+ public void setOnSetDate(Date onSetDate) {
+ this.onSetDate = onSetDate;
+ }
+
+ public Date getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Date 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.allergy.Allergy_New.Status getStatus() {
+ return status;
+ }
+
+ public void setStatus(org.openmrs.module.emrapi.allergy.Allergy_New.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/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/Concept.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/Concept.java
new file mode 100644
index 000000000..a077d1fd1
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/contract/Concept.java
@@ -0,0 +1,42 @@
+package org.openmrs.module.emrapi.allergy.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/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/db/AllergyDAO.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/db/AllergyDAO.java
new file mode 100644
index 000000000..4adf241ee
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/db/AllergyDAO.java
@@ -0,0 +1,18 @@
+package org.openmrs.module.emrapi.allergy.db;
+
+import java.util.List;
+
+import org.openmrs.Patient;
+import org.openmrs.module.emrapi.allergy.Allergy_New;
+
+public interface AllergyDAO {
+
+ Allergy_New saveOrUpdate(Allergy_New allergy_New);
+
+ Allergy_New getAllergyByUuid(String uuid);
+
+ List getAllergyHistory(Patient patient);
+
+ List getActiveAllergies(Patient patient);
+
+}
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/db/hibernate/HibernateAllergyDAO.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/db/hibernate/HibernateAllergyDAO.java
new file mode 100644
index 000000000..20b1410eb
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/db/hibernate/HibernateAllergyDAO.java
@@ -0,0 +1,65 @@
+package org.openmrs.module.emrapi.allergy.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.allergy.Allergy_New;
+import org.openmrs.module.emrapi.allergy.db.AllergyDAO;
+
+import org.springframework.transaction.annotation.Transactional;
+
+public class HibernateAllergyDAO implements AllergyDAO {
+
+ protected static final Log log = LogFactory.getLog(HibernateAllergyDAO.class);
+
+ /**
+ * Hibernate session factory
+ */
+
+ private DbSessionFactory sessionFactory;
+
+ /**
+ * Set session factory
+ *
+ * @param sessionFactory
+ */
+ public void setSessionFactory(DbSessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ @Override
+ @Transactional
+ public Allergy_New saveOrUpdate(Allergy_New allergy_New) {
+ sessionFactory.getCurrentSession().saveOrUpdate(allergy_New);
+ return allergy_New;
+ }
+ @Override
+ @Transactional(readOnly = true)
+ public Allergy_New getAllergyByUuid(String uuid) {
+ return (Allergy_New) sessionFactory.getCurrentSession().createQuery("from org.openmrs.module.emrapi.allergy.Allergy_New a where a.uuid = :uuid")
+ .setString("uuid", uuid).uniqueResult();
+ }
+ @Override
+ @Transactional(readOnly = true)
+ public List getActiveAllergies(Patient patient) {
+ Query query = sessionFactory.getCurrentSession().createQuery(
+ "from org.openmrs.module.emrapi.allergy.Allergy_New a where a.patient.patientId = :patientId and a.voided = false and a.endDate is null order "
+ + "by a.dateCreated desc");
+ query.setInteger("patientId", patient.getId());
+ return query.list();
+ }
+ @Override
+ @Transactional(readOnly = true)
+ public List getAllergyHistory(Patient patient) {
+ Query query = sessionFactory.getCurrentSession().createQuery(
+ "select ala from org.openmrs.module.emrapi.allergy.Allergy_New as ala where ala.patient.patientId = :patientId and ala.voided = false " +
+ "order by ala.dateCreated desc");
+ query.setInteger("patientId", patient.getId());
+ return query.list();
+ }
+}
+
diff --git a/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/impl/AllergyServiceImpl.java b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/impl/AllergyServiceImpl.java
new file mode 100644
index 000000000..57d63521d
--- /dev/null
+++ b/Allergy/src/main/java/org/openmrs/module/emrapi/allergy/impl/AllergyServiceImpl.java
@@ -0,0 +1,133 @@
+package org.openmrs.module.emrapi.allergy.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.context.Context;
+
+import org.openmrs.api.impl.BaseOpenmrsService;
+import org.openmrs.module.emrapi.allergy.Allergy_New;
+import org.openmrs.module.emrapi.allergy.AllergyHistory;
+import org.openmrs.module.emrapi.allergy.AllergyListConstant;
+import org.openmrs.module.emrapi.allergy.AllergyService;
+import org.openmrs.module.emrapi.allergy.db.AllergyDAO;
+import org.springframework.transaction.annotation.Transactional;
+
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+
+public class AllergyServiceImpl extends BaseOpenmrsService implements AllergyService {
+
+ private AllergyDAO allergyDAO;
+
+ private ConceptService conceptService;
+
+ private AdministrationService administrationService;
+
+ public AllergyServiceImpl(AllergyDAO allergyDAO, ConceptService conceptService,
+ AdministrationService administrationService) {
+ this.allergyDAO = allergyDAO;
+ this.conceptService = conceptService;
+ this.administrationService = administrationService;
+ }
+
+ @Override
+ public Allergy_New save(Allergy_New allergy_New) {
+ Date endDate = allergy_New.getEndDate() != null ? allergy_New.getEndDate() : new Date();
+ if (allergy_New.getEndReason() != null) {
+ allergy_New.setEndDate(endDate);
+ }
+ Allergy_New existingAllergy = getAllergyByUuid(allergy_New.getUuid());
+ if (allergy_New.equals(existingAllergy)) {
+ return existingAllergy;
+ }
+ if (existingAllergy == null) {
+ return allergyDAO.saveOrUpdate(allergy_New);
+ }
+ allergy_New = Allergy_New.newInstance(allergy_New);
+ allergy_New.setPreviousAllergy(existingAllergy);
+ if (existingAllergy.getStatus().equals(allergy_New.getStatus())) {
+ existingAllergy.setVoided(true);
+ allergyDAO.saveOrUpdate(existingAllergy);
+ return allergyDAO.saveOrUpdate(allergy_New);
+ }
+ Date onSetDate = allergy_New.getOnsetDate() != null ? allergy_New.getOnsetDate() : new Date();
+ existingAllergy.setEndDate(onSetDate);
+ allergyDAO.saveOrUpdate(existingAllergy);
+ allergy_New.setOnsetDate(onSetDate);
+ return allergyDAO.saveOrUpdate(allergy_New);
+ }
+
+ @Override
+ public Allergy_New voidAllergy(Allergy_New allergy_New, String voidReason) {
+ if (!StringUtils.hasLength(voidReason)) {
+ throw new IllegalArgumentException("voidReason cannot be empty or null");
+ }
+ return allergyDAO.saveOrUpdate(allergy_New);
+ }
+
+ @Override
+ public Allergy_New getAllergyByUuid(String uuid) {
+ return allergyDAO.getAllergyByUuid(uuid);
+ }
+
+ public List getAllergyHistory(Patient patient) {
+ List allergyList = allergyDAO.getAllergyHistory(patient);
+ Map allAllergies = new LinkedHashMap();
+ for (Allergy_New allergy_New : allergyList) {
+ Concept concept = allergy_New.getConcept();
+
+ String nonCodedConceptUuid = administrationService.getGlobalProperty(
+ AllergyListConstant.GLOBAL_PROPERTY_NON_CODED_UUID);
+
+ String key = concept.getUuid().equals(nonCodedConceptUuid) ?
+ allergy_New.getAllergyNonCoded() :
+ concept.getUuid();
+ AllergyHistory allergyHistory = allAllergies.get(key);
+ if (allergyHistory != null) {
+ allergyHistory.getAllergies().add(allergy_New);
+ } else {
+ allergyHistory = new AllergyHistory();
+ List allergy_News = new ArrayList();
+ allergy_News.add(allergy_New);
+ allergyHistory.setAllergies(allergy_News);
+ allergyHistory.setAllergy(allergy_New.getConcept());
+ if (concept.getUuid().equals(nonCodedConceptUuid)) {
+ allergyHistory.setNonCodedAllergy(allergy_New.getAllergyNonCoded());
+ }
+ }
+ allAllergies.put(key, allergyHistory);
+ }
+ return new ArrayList(allAllergies.values());
+ }
+
+ @Override
+ public List getActiveAllergy(Patient patient) {
+ return allergyDAO.getActiveAllergies(patient);
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public List getEndReasonConcepts() {
+ return getSetMembersOfConceptSetFromGP(AllergyListConstant.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/Allergy/src/main/resources/Allergy_New.hbm.xml b/Allergy/src/main/resources/Allergy_New.hbm.xml
new file mode 100644
index 000000000..5841c9466
--- /dev/null
+++ b/Allergy/src/main/resources/Allergy_New.hbm.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+ allergies_allergy_id_seq
+
+
+
+
+
+
+
+
+ org.openmrs.module.emrapi.allergy.Allergy_New$Status
+ 12
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Allergy/src/main/resources/moduleApplicationContext.xml b/Allergy/src/main/resources/moduleApplicationContext.xml
new file mode 100644
index 000000000..c53efff4f
--- /dev/null
+++ b/Allergy/src/main/resources/moduleApplicationContext.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.openmrs.module.emrapi.allergy.AllergyService
+
+
+
+
+
diff --git a/Allergy/src/test/java/org/Allergy/AppTest.java b/Allergy/src/test/java/org/Allergy/AppTest.java
new file mode 100644
index 000000000..2848aa58e
--- /dev/null
+++ b/Allergy/src/test/java/org/Allergy/AppTest.java
@@ -0,0 +1,38 @@
+package org.Allergy;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/api-pre2.2/src/main/resources/liquibase.xml b/api-pre2.2/src/main/resources/liquibase.xml
index af757cae0..acb59cd81 100644
--- a/api-pre2.2/src/main/resources/liquibase.xml
+++ b/api-pre2.2/src/main/resources/liquibase.xml
@@ -44,6 +44,7 @@
+
getDiagnosisSets() {
}
}
+ public Collection getAllergySets() {
+ String diagnosisSetsUuid = getGlobalProperty(EmrApiConstants.GP_ALLERGY_SET_OF_SETS, true);
+ if (StringUtils.hasText(diagnosisSetsUuid)) {
+ Concept setOfSets = conceptService.getConceptByUuid(diagnosisSetsUuid);
+ if (setOfSets == null) {
+ throw new IllegalStateException("Configuration required: " + EmrApiConstants.GP_ALLERGY_SET_OF_SETS);
+ }
+ return setOfSets.getSetMembers();
+ } else {
+ return null;
+ }
+ }
+
public Collection getNonDiagnosisConceptSets() {
Collection concepts = getConceptsByGlobalProperty(EmrApiConstants.GP_NON_DIAGNOSIS_CONCEPT_SETS);
@@ -275,6 +288,19 @@ public Collection getSuppressedDiagnosisConcepts() {
return getConceptsByGlobalProperty(EmrApiConstants.GP_SUPPRESSED_DIAGNOSIS_CONCEPTS);
}
+ public Collection getAllergyisSets() {
+ String diagnosisSetsUuid = getGlobalProperty(EmrApiConstants.GP_ALLERGY_SET_OF_SETS, true);
+ if (StringUtils.hasText(diagnosisSetsUuid)) {
+ Concept setOfSets = conceptService.getConceptByUuid(diagnosisSetsUuid);
+ if (setOfSets == null) {
+ throw new IllegalStateException("Configuration required: " + EmrApiConstants.GP_ALLERGY_SET_OF_SETS);
+ }
+ return setOfSets.getSetMembers();
+ } else {
+ return null;
+ }
+ }
+
public ConceptMapType getSameAsConceptMapType() {
return conceptService.getConceptMapTypeByUuid(EmrApiConstants.SAME_AS_CONCEPT_MAP_TYPE_UUID);
}
diff --git a/omod/pom.xml b/omod/pom.xml
index 17932ec5c..6c2a6da3a 100644
--- a/omod/pom.xml
+++ b/omod/pom.xml
@@ -13,6 +13,13 @@
OMOD project for EMRAPI
+
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-api
+ ${project.parent.version}
+ compile
+
${project.parent.groupId}
${project.parent.artifactId}-api
@@ -31,6 +38,12 @@
${project.parent.version}
compile
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-Allergy
+ ${project.parent.version}
+ compile
+
${project.parent.groupId}
${project.parent.artifactId}-api-1.11
diff --git a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/EmrAllergyConceptSearchController.java b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/EmrAllergyConceptSearchController.java
new file mode 100644
index 000000000..f7c1318be
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/EmrAllergyConceptSearchController.java
@@ -0,0 +1,93 @@
+/**
+ * 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.web.controller;
+
+import org.openmrs.Concept;
+import org.openmrs.ConceptMap;
+import org.openmrs.ConceptReferenceTerm;
+import org.openmrs.ConceptSearchResult;
+import org.openmrs.ConceptSource;
+import org.openmrs.module.emrapi.EmrApiProperties;
+import org.openmrs.module.emrapi.concept.EmrConceptService;
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.util.LocaleUtility;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+
+@Controller
+@RequestMapping(method = RequestMethod.GET, value = "/rest/emrapi/allergyconcept")
+public class EmrAllergyConceptSearchController {
+ private Log log = LogFactory.getLog(this.getClass());
+ @Autowired
+ EmrApiProperties emrApiProperties;
+ @Autowired
+ EmrConceptService emrService;
+
+ @RequestMapping(method = RequestMethod.GET)
+ @ResponseBody
+ public Object search(@RequestParam("term") String query, @RequestParam Integer limit) throws Exception {
+ Collection diagnosisSets = emrApiProperties.getAllergyisSets();
+ //List conceptSources = emrApiProperties.getConceptSourcesForDiagnosisSearch();
+ List conceptSearchResults =
+ emrService.conceptSearch(query, LocaleUtility.getDefaultLocale(), null, diagnosisSets, null, limit);
+ // ConceptSource conceptSource = conceptSources.isEmpty() ? null: conceptSources.get(0);
+ return createListResponse(conceptSearchResults, null);
+ }
+
+ private List createListResponse(List resultList, ConceptSource conceptSource) {
+ List allDiagnoses = new ArrayList();
+
+ for (ConceptSearchResult diagnosis : resultList) {
+ SimpleObject diagnosisObject = new SimpleObject();
+ diagnosisObject.add("conceptName", diagnosis.getConcept().getName().getName());
+ diagnosisObject.add("conceptUuid", diagnosis.getConcept().getUuid());
+ if(diagnosis.getConceptName()!=null) {
+ diagnosisObject.add("matchedName", diagnosis.getConceptName().getName());
+ }
+ ConceptReferenceTerm term = getConceptReferenceTermByConceptSource(diagnosis.getConcept(), conceptSource);
+ if(term != null) {
+ diagnosisObject.add("code", term.getCode());
+ }
+ allDiagnoses.add(diagnosisObject);
+ }
+ return allDiagnoses;
+ }
+
+ private ConceptReferenceTerm getConceptReferenceTermByConceptSource(Concept concept, ConceptSource conceptSource) {
+ Collection conceptMappings = concept.getConceptMappings();
+ if(conceptMappings != null && conceptSource != null) {
+ for (ConceptMap cm : conceptMappings) {
+ ConceptReferenceTerm term = cm.getConceptReferenceTerm();
+ if (conceptSource.equals(term.getConceptSource())) {
+ return term;
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml
index 950a39fa9..2961cd5c6 100644
--- a/omod/src/main/resources/config.xml
+++ b/omod/src/main/resources/config.xml
@@ -72,6 +72,7 @@
Condition.hbm.xml
+ Allergy_New.hbm.xml
@@ -144,6 +145,23 @@
UUID of non coded concept
+
+
+ alergyList.endReasonConceptSetUuid
+
+
+ UUID of end reason concept set
+
+
+
+
+ alergyList.nonCodedUuid
+
+
+ UUID of non coded concept
+
+
+
emrapi.EmrApiVisitAssignmentHandler.encounterTypeToNewVisitTypeMap
@@ -184,6 +202,16 @@
Get conditions
Able to get conditions
+
+
+ Edit allergies
+ Able to edit allergies
+
+
+
+ Get allergies
+ Able to get allergies
+
diff --git a/omod/src/main/resources/liquibase.xml b/omod/src/main/resources/liquibase.xml
new file mode 100644
index 000000000..25ee93b2b
--- /dev/null
+++ b/omod/src/main/resources/liquibase.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Creating unique index on allergy.uuid column
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 18b70292d..8c2994f18 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,3 +1,4 @@
+
4.0.0
org.openmrs.module
@@ -39,7 +40,8 @@
omod
api-pre2.2
web-pre2.2
-
+ Allergy
+
UTF-8
@@ -407,4 +409,4 @@
-
+
\ No newline at end of file
diff --git a/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/AllergyController.java b/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/AllergyController.java
new file mode 100644
index 000000000..d80b13e3c
--- /dev/null
+++ b/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/AllergyController.java
@@ -0,0 +1,38 @@
+package org.openmrs.module.emrapi.web.controller;
+
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.openmrs.util.LocaleUtility.getDefaultLocale;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openmrs.CodedOrFreeText;
+import org.openmrs.Concept;
+import org.openmrs.ConceptName;
+import org.openmrs.ConditionClinicalStatus;
+import org.openmrs.Patient;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.ConditionService;
+import org.openmrs.api.PatientService;
+import org.openmrs.api.context.Context;
+
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * This class specifies data manipulation methods on a Condition.
+ */
+@Controller
+public class AllergyController extends BaseRestController{
+
+}
+
diff --git a/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java b/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java
index 16b9926dd..105de166e 100644
--- a/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java
+++ b/web-2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java
@@ -9,6 +9,8 @@
import java.util.List;
import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.openmrs.CodedOrFreeText;
import org.openmrs.Concept;
import org.openmrs.ConceptName;
@@ -38,7 +40,7 @@
@Controller
@RequestMapping(value = "/rest/emrapi")
public class ConditionController extends BaseRestController {
-
+ private Log log = LogFactory.getLog(this.getClass());
ConditionMapper conditionMapper = new ConditionMapper();
ConditionHistoryMapper conditionHistoryMapper = new ConditionHistoryMapper(conditionMapper);
@@ -370,6 +372,7 @@ private org.openmrs.module.emrapi.conditionslist.Condition convertCoreConditionT
@RequestMapping(method = RequestMethod.GET, value = "/conditionhistory")
@ResponseBody
public List getConditionHistory(@RequestParam("patientUuid") String patientUuid) {
+ log.error("conditionhistory2.2222 ##############################################################################");
List activeConditions = conditionService.getActiveConditions(patientService.getPatientByUuid(patientUuid));
return conditionHistoryMapper.map(convertHistory(activeConditions));
@@ -383,7 +386,7 @@ public List
@RequestMapping(method = RequestMethod.POST, value = "/condition")
@ResponseBody
public List save(@RequestBody org.openmrs.module.emrapi.conditionslist.contract.Condition[] conditions) {
-
+log.error("condition# 2.22#############################################################################");
List savedConditions = new ArrayList();
for (org.openmrs.module.emrapi.conditionslist.contract.Condition condition : conditions) {
diff --git a/web-pre2.2/pom.xml b/web-pre2.2/pom.xml
index ebfc166c5..8f491693a 100644
--- a/web-pre2.2/pom.xml
+++ b/web-pre2.2/pom.xml
@@ -35,6 +35,13 @@
${project.parent.version}
compile
+
+
+ ${project.parent.groupId}
+ ${project.parent.artifactId}-Allergy
+ ${project.parent.version}
+ compile
+
org.openmrs.web
@@ -58,6 +65,8 @@
${webservices.restVersion}
provided
+
+
diff --git a/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/AllergyController.java b/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/AllergyController.java
new file mode 100644
index 000000000..240edb983
--- /dev/null
+++ b/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/AllergyController.java
@@ -0,0 +1,69 @@
+package org.openmrs.module.emrapi.web.controller;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openmrs.api.ConceptService;
+import org.openmrs.api.PatientService;
+import org.openmrs.module.emrapi.allergy.AllergyService;
+import org.openmrs.module.emrapi.allergy.AllergyListConstant;
+import org.openmrs.module.emrapi.allergy.contract.Allergy_New;
+import org.openmrs.module.emrapi.allergy.contract.AllergyHistory;
+import org.openmrs.module.emrapi.allergy.contract.AllergyHistoryMapper;
+import org.openmrs.module.emrapi.allergy.contract.AllergyMapper;
+import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+
+@Controller
+@RequestMapping(value = "/rest/emrapi")
+public class AllergyController extends BaseRestController {
+ private Log log = LogFactory.getLog(this.getClass());
+ AllergyMapper allergyMapper = new AllergyMapper();
+
+ AllergyHistoryMapper allergyHistoryMapper = new AllergyHistoryMapper(allergyMapper);
+
+ AllergyService allergyService;
+
+ PatientService patientService;
+
+ ConceptService conceptService;
+
+ @Autowired
+ public AllergyController(AllergyService allergyService, PatientService patientService,
+ ConceptService conceptService) {
+ this.allergyService = allergyService;
+ this.patientService = patientService;
+ this.conceptService = conceptService;
+ }
+
+ @RequestMapping(method = RequestMethod.GET, value = "/allergyhistory")
+ @ResponseBody
+ public List getAllergyHistory(@RequestParam("patientUuid") String patientUuid) {
+
+ List allergyHistory = allergyService.getAllergyHistory(
+ patientService.getPatientByUuid(patientUuid));
+
+ return allergyHistoryMapper.map(allergyHistory);
+ }
+
+ @RequestMapping(method = RequestMethod.POST, value = "/allergy")
+ @ResponseBody
+ public List save(@RequestBody Allergy_New[] Allergies) {
+
+ List savedAllergies = new ArrayList();
+ for (Allergy_New allergy_New : Allergies) {
+ org.openmrs.module.emrapi.allergy.Allergy_New savedAllergy = allergyService.save(allergyMapper.map(allergy_New));
+ savedAllergies.add(allergyMapper.map(savedAllergy));
+ }
+ return savedAllergies;
+ }
+}
diff --git a/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java b/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java
index bf726687a..b4c956a44 100644
--- a/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java
+++ b/web-pre2.2/src/main/java/org/openmrs/module/emrapi/web/controller/ConditionController.java
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.openmrs.api.ConceptService;
import org.openmrs.api.PatientService;
import org.openmrs.module.emrapi.conditionslist.ConditionService;
@@ -22,7 +24,7 @@
@Controller
@RequestMapping(value = "/rest/emrapi")
public class ConditionController extends BaseRestController {
-
+ private Log log = LogFactory.getLog(this.getClass());
ConditionMapper conditionMapper = new ConditionMapper();
ConditionHistoryMapper conditionHistoryMapper = new ConditionHistoryMapper(conditionMapper);
@@ -44,6 +46,7 @@ public ConditionController(ConditionService conditionService, PatientService pat
@RequestMapping(method = RequestMethod.GET, value = "/conditionhistory")
@ResponseBody
public List getConditionHistory(@RequestParam("patientUuid") String patientUuid) {
+
List conditionHistory = conditionService.getConditionHistory(
patientService.getPatientByUuid(patientUuid));
@@ -53,6 +56,7 @@ public List getConditionHistory(@RequestParam("patientUuid") S
@RequestMapping(method = RequestMethod.POST, value = "/condition")
@ResponseBody
public List save(@RequestBody Condition[] conditions) {
+
List savedConditions = new ArrayList();
for (Condition condition : conditions) {
org.openmrs.module.emrapi.conditionslist.Condition savedCondition = conditionService.save(conditionMapper.map(condition));