Skip to content

Commit

Permalink
First pass for: Add and Save Allergies - RA-344
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Sep 1, 2014
1 parent 64bee4e commit 4a465a0
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 7 deletions.
9 changes: 9 additions & 0 deletions api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ ${project.parent.artifactId}.comment=Comment
${project.parent.artifactId}.lastUpdated=Last Updated
${project.parent.artifactId}.addNewAllergy=Add New Allergy
${project.parent.artifactId}.noKnownAllergy=No Known Allergy
${project.parent.artifactId}.newAllergy=New Allergy
${project.parent.artifactId}.noKnownAllergy.message=Are you sure this patient has no known allergies?
${project.parent.artifactId}.message.success=Saved changes
${project.parent.artifactId}.message.fail=Failed to save changes
${project.parent.artifactId}.deactivate=Deactivate
${project.parent.artifactId}.categories=Categories
${project.parent.artifactId}.drug=Drug
${project.parent.artifactId}.food=Food
${project.parent.artifactId}.environment=Environment
${project.parent.artifactId}.reactionSelection=Reactions: (check all that apply)
${project.parent.artifactId}.mild=Mild
${project.parent.artifactId}.moderate=Moderate
${project.parent.artifactId}.severe=Severe
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.openmrs.module.allergyui.page.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.openmrs.Concept;
import org.openmrs.Patient;
import org.openmrs.activelist.AllergySeverity;
import org.openmrs.api.ConceptService;
import org.openmrs.module.allergyapi.Allergen;
import org.openmrs.module.allergyapi.AllergenType;
import org.openmrs.module.allergyapi.Allergies;
import org.openmrs.module.allergyapi.Allergy;
import org.openmrs.module.allergyapi.AllergyReaction;
import org.openmrs.module.allergyapi.api.PatientService;
import org.openmrs.ui.framework.UiUtils;
import org.openmrs.ui.framework.annotation.SpringBean;
import org.openmrs.ui.framework.fragment.action.SuccessResult;
import org.openmrs.ui.framework.page.PageModel;
import org.springframework.web.bind.annotation.RequestParam;

public class AllergyPageController {

public static final String DRUG_ALLERGENS_UUID = "162552AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public static final String FOOD_ALLERGENS_UUID = "162553AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public static final String ENVIRONMENT_ALLERGENS_UUID = "162554AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public static final String ALLERGY_REACTIONS_UUID = "162555AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public static final String MODERATE_UUID = "1499AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public static final String MILD_UUID = "1498AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public static final String SEVERE_UUID = "1500AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

public void controller(PageModel model, @RequestParam("patientId") Patient patient, UiUtils ui,
@SpringBean("allergyService") PatientService patientService,
@SpringBean("conceptService") ConceptService conceptService) {

model.addAttribute("patient", patient);

//drug allergens
List<Concept> concepts = new ArrayList<Concept>();
Concept concept = conceptService.getConceptByUuid(DRUG_ALLERGENS_UUID);
if (concept != null) {
concepts = concept.getSetMembers();
}
model.addAttribute("drugAllergens", concepts);

//food allergens
concepts = new ArrayList<Concept>();
concept = conceptService.getConceptByUuid(FOOD_ALLERGENS_UUID);
if (concept != null) {
concepts = concept.getSetMembers();
}
model.addAttribute("foodAllergens", concepts);

//environmental allergens
concepts = new ArrayList<Concept>();
concept = conceptService.getConceptByUuid(ENVIRONMENT_ALLERGENS_UUID);
if (concept != null) {
concepts = concept.getSetMembers();
}
model.addAttribute("environmentalAllergens", concepts);

//allergy reactions
concepts = new ArrayList<Concept>();
concept = conceptService.getConceptByUuid(ALLERGY_REACTIONS_UUID);
if (concept != null) {
concepts = concept.getSetMembers();
}
model.addAttribute("allergyReactions", concepts);
}

public String post(@RequestParam("patientId") Patient patient, @RequestParam("allergen") Concept allergen,
@RequestParam("severity") AllergySeverity severity, @RequestParam("comment") String comment,
@RequestParam("allergyType") AllergenType allergenType,
@RequestParam("reaction") List<Concept> reactionConcepts,
@SpringBean("conceptService") ConceptService conceptService,
@SpringBean("allergyService") PatientService patientService, HttpServletRequest request,
PageModel model, UiUtils ui) {

Allergen algn = new Allergen(allergenType, allergen, null);
Concept severityConcept = getSeverityConcept(severity, conceptService);
Allergy allergy = new Allergy(patient, algn, severityConcept, comment, null);
List<AllergyReaction> reactions = getAllergyReactions(reactionConcepts, allergy);
allergy.setReactions(reactions);

Allergies allergies = patientService.getAllergies(patient);
allergies.add(allergy);
patientService.setAllergies(patient, allergies);

return new SuccessResult(ui.message("allergyui.addNewAllergy.success")).toString();
}

private Concept getSeverityConcept(AllergySeverity severity, ConceptService conceptService) {
if (severity == AllergySeverity.MILD) {
return conceptService.getConceptByUuid(MILD_UUID);
} else if (severity == AllergySeverity.MODERATE) {
return conceptService.getConceptByUuid(MODERATE_UUID);
} else {
return conceptService.getConceptByUuid(SEVERE_UUID);
}
}

private List<AllergyReaction> getAllergyReactions(List<Concept> reactionConcepts, Allergy allergy) {
List<AllergyReaction> reactions = new ArrayList<AllergyReaction>();
for (Concept concept : reactionConcepts) {
reactions.add(new AllergyReaction(allergy, concept, null));
}
return reactions;
}
}
5 changes: 2 additions & 3 deletions omod/src/main/webapp/fragments/allergies.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
<% allergies.each { allergy -> %>
<li style="display: inline-block; font-size: 0.8em;">
${ allergy.allergen } =>
<% allergy.reactions.eachWithIndex { reaction, index -> %>
<% if (index > 0) { %>,<% } %> ${reaction} (${ allergy.severity.name })
<% } %>
<% allergy.reactions.eachWithIndex { reaction, index -> %><% if (index > 0) { %>,<% } %> ${reaction}<% } %>
(${ allergy.severity.name })
</li>
<% } %>
</ul>
Expand Down
6 changes: 2 additions & 4 deletions omod/src/main/webapp/pages/allergies.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ ${ ui.includeFragment("uicommons", "infoAndErrorMessage")}
<tr>
<td> ${ allergy.allergen } </td>
<td>
<% allergy.reactions.eachWithIndex { reaction, index -> %>
<% if (index > 0) { %>,<% } %> ${reaction}
<% } %>
<% allergy.reactions.eachWithIndex { reaction, index -> %><% if (index > 0) { %>,<% } %> ${reaction}<% } %>
</td>
<td> ${ allergy.severity.name } </td>
<td> ${ allergy.comment } </td>
Expand All @@ -72,7 +70,7 @@ ${ ui.includeFragment("uicommons", "infoAndErrorMessage")}

<br/>

<button class="confirm">
<button class="confirm" onclick="location.href='${ ui.pageLink("allergyui", "allergy", [patientId: patient.id]) }'">
${ ui.message("allergyui.addNewAllergy") }
</button>

Expand Down
101 changes: 101 additions & 0 deletions omod/src/main/webapp/pages/allergy.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<%
ui.decorateWith("appui", "standardEmrPage")
%>
<script type="text/javascript">
var breadcrumbs = [
{ icon: "icon-home", link: '/' + OPENMRS_CONTEXT_PATH + '/index.htm' },
{ label: "${ ui.format(patient.familyName) }, ${ ui.format(patient.givenName) }" , link: '${ui.pageLink("coreapps", "clinicianfacing/patient", [patientId: patient.id])}'},
{ label: "${ ui.message("allergyui.allergies") }", link: '${ui.pageLink("allergyui", "allergies", [patientId: patient.id])}'},
{ label: "${ ui.message("allergyui.newAllergy") }" }
];
var patient = { id: ${ patient.id } };
</script>

${ ui.includeFragment("coreapps", "patientHeader", [ patient: patient ]) }

<h2>
${ ui.message("allergyui.addNewAllergy") }
</h2>

<style>
table tr td {
border: none;
display: inline-block;
}
table:not(.unstyled) tr:nth-child(even) {
background: white;
}
</style>

<form method="POST">
<table id="allergy">
<tr>
<td>
${ ui.message("allergyui.categories") }
</td>
<td>
<input type="radio" name="allergyType" value="DRUG" checked="checked"> ${ ui.message("allergyui.drug") }
</td>
<td>
<input type="radio" name="allergyType" value="FOOD"> ${ ui.message("allergyui.food") }
</td>
<td>
<input type="radio" name="allergyType" value="ENVIRONMENT"> ${ ui.message("allergyui.environment") }
</td>
</tr>
<tr>
<td colspan="2">
<fieldset>
<legend>${ui.message("allergyui.allergen")}:</legend>
<% drugAllergens.each { allergen -> %>
<input type="radio" name="allergen" value="${allergen.id}">${allergen.name}<br/>
<% } %>
</fieldset>
</td>
<td colspan="2">
<fieldset>
<legend>${ui.message("allergyui.reactionSelection")}</legend>
<% allergyReactions.each { reaction -> %>
<input type="checkbox" name="reaction" value="${reaction.id}">${reaction.name}<br/>
<% } %>
</fieldset>
</td>
</tr>
<tr>
<td>
${ ui.message("allergyui.severity") }
</td>
<td>
<input type="radio" name="severity" value="MILD"> ${ ui.message("allergyui.mild") }
</td>
<td>
<input type="radio" name="severity" value="MODERATE"> ${ ui.message("allergyui.moderate") }
</td>
<td>
<input type="radio" name="severity" value="SEVERE"> ${ ui.message("allergyui.severe") }
</td>
</tr>
<tr>
<td>
${ ui.message("allergyui.comment") }
</td>
<td colspan="3" style="width:80%">
<input type="text" name="comment">
</td>
</tr>
<tr>
<td colspan="3">
<button class="cancel" onclick="location.href='${ ui.pageLink("allergyui", "allergies", [patientId: patient.id]) }'">
${ ui.message("coreapps.cancel") }
</button>
</td>
<td align="right" style="float:right">
<button class="confirm" type="submit">
${ ui.message("coreapps.save") }
</button>
</td>
</tr>
</table>
</form>

0 comments on commit 4a465a0

Please sign in to comment.