forked from openmrs/openmrs-module-allergyui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass for: Add and Save Allergies - RA-344
- Loading branch information
Showing
5 changed files
with
231 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
omod/src/main/java/org/openmrs/module/allergyui/page/controller/AllergyPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |