Permalink
Browse files

added past procedures and allergies

  • Loading branch information...
merovingienne committed Jul 30, 2017
1 parent ce702ba commit 1f32adb1eb47cb4cef37ebbc5487b93cd3f24958
@@ -0,0 +1,95 @@
package org.openmrs.module.operationtheater;
import org.openmrs.Obs;
import org.openmrs.Patient;
import org.openmrs.api.ConceptService;
import org.openmrs.api.ObsService;
import org.openmrs.api.context.Context;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
public class PastProcedure {
private String name;
private String date;
private String comment;
private SimpleDateFormat outputFormatter = new SimpleDateFormat("yyyy-MM-dd");
private PastProcedure(Obs pastProcedure){
Set<Obs> pastProcedureObs = pastProcedure.getGroupMembers();
for (Obs ob: pastProcedureObs){
switch (ob.getConcept().getConceptId()){
case (1651):
setName(ob.getValueAsString(Locale.ENGLISH));
break;
case (160715):
setDate(outputFormatter.format(ob.getValueDate()));
break;
case (160716):
setComment(ob.getValueText());
}
}
}
public static List<PastProcedure> getAllPastProcedures(Patient patient){
ObsService obsService = Context.getObsService();
ConceptService conceptService = Context.getConceptService();
List<Obs> pastProcedureGroupObs = obsService.getObservationsByPersonAndConcept(patient, conceptService.getConcept(160714));
List<PastProcedure> pastProcedures = new ArrayList<PastProcedure>();
for (Obs pastProcedure : pastProcedureGroupObs){
pastProcedures.add(new PastProcedure(pastProcedure));
}
return pastProcedures;
}
public static PastProcedure getPastProcedure(Obs obs){
return new PastProcedure(obs);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
@@ -0,0 +1,161 @@
package org.openmrs.module.operationtheater.fragment.controller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.*;
import org.openmrs.api.ConceptService;
import org.openmrs.api.ObsService;
import org.openmrs.api.context.Context;
import org.openmrs.module.operationtheater.PastProcedure;
import org.openmrs.module.operationtheater.Surgery;
import org.openmrs.module.operationtheater.Time;
import org.openmrs.module.operationtheater.Util.SurgeryObsUtil;
import org.openmrs.module.operationtheater.api.OperationTheaterService;
import org.openmrs.ui.framework.SimpleObject;
import org.openmrs.ui.framework.UiUtils;
import org.openmrs.ui.framework.annotation.SpringBean;
import org.openmrs.ui.framework.fragment.action.FailureResult;
import org.openmrs.ui.framework.fragment.action.FragmentActionResult;
import org.openmrs.ui.framework.fragment.action.SuccessResult;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import org.openmrs.module.operationtheater.Drug;
/**
* Controller class for handling data in
* pretheater data collection page.
*/
public class PretheaterDataFragmentController {
private final Time time = new Time();
private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
protected final Log log = LogFactory.getLog(getClass());
/**
* Method to fetch past procedures of a patient.
* @param UI
* @param patient required
* @return JSON objects with past procedure data.
* @see omod/src/main/webapp/resources/scripts/preTheaterForm_page/pastProcedures.js
*/
public List<SimpleObject> getPastProcedures(UiUtils UI,
@RequestParam("patient") Patient patient
){
if (patient == null){
throw new IllegalArgumentException("Patient doesn't exist");
}
List<PastProcedure> pastProceduresObsGroup = PastProcedure.getAllPastProcedures(patient);
return SimpleObject.fromCollection(pastProceduresObsGroup, UI,"name", "date", "comment" );
}
/**
* Add new past procedure record to the patient as obs.
* @param ui
* @param patient
* @param pastProcedureName
* @param pastProcedureDate
* @param pastProcedureComment
* @see org.openmrs.module.operationtheater.OperationTheaterModuleActivator#setupInitialConcepts(ConceptService)
*/
public FragmentActionResult addPastProcedureRecord(UiUtils ui,
@RequestParam("patient") Patient patient,
@RequestParam("pastProcedureName") String pastProcedureName,
@RequestParam("pastProcedureDate") String pastProcedureDate,
@RequestParam("pastProcedureComment") String pastProcedureComment
){
if (patient == null){
return new FailureResult(ui.message("operationtheater.patient.notFound"));
}
if (pastProcedureName == null){
return new FailureResult(ui.message("operationtheater.pastProcedure.invalidName"));
}
ConceptService conceptService = Context.getConceptService();
ObsService obsService = Context.getObsService();
/**
* Procedure history grouping obs.
*
*/
Obs parentObs = new Obs();
parentObs.setConcept(conceptService.getConcept(160714));
parentObs.setObsDatetime(new Date());
parentObs.setPerson(patient);
parentObs.setLocation(new Location(1));
parentObs.setCreator(Context.getAuthenticatedUser());
Obs procedurePerformed = new Obs();
procedurePerformed.setConcept(conceptService.getConcept(1651));
procedurePerformed.setValueText(pastProcedureName);
procedurePerformed.setObsDatetime(new Date());
procedurePerformed.setPerson(patient);
procedurePerformed.setLocation(new Location(1));
Obs procedureDate = new Obs();
procedureDate.setConcept(conceptService.getConcept(160715));
try {
procedureDate.setValueDate(formatter.parse(pastProcedureDate));
} catch (ParseException e) {
return new FailureResult(ui.message("operationtheater.pastProcedure.invalidDate"));
}
procedureDate.setObsDatetime(new Date());
procedureDate.setPerson(patient);
procedureDate.setLocation(new Location(1));
Obs procedureComment = new Obs();
procedureComment.setConcept(conceptService.getConcept(160716));
procedureComment.setValueText(pastProcedureComment);
procedureComment.setObsDatetime(new Date());
procedureComment.setPerson(patient);
procedureComment.setLocation(new Location(1));
parentObs.addGroupMember(procedurePerformed);
parentObs.addGroupMember(procedureDate);
parentObs.addGroupMember(procedureComment);
obsService.saveObs(parentObs, null);
Obs savedObs = obsService.getObs(parentObs.getObsId());
if (savedObs.getId() == null || savedObs.getConcept().getConceptId() != parentObs.getConcept().getConceptId()){
return new FailureResult(ui.message("operationtheater.pastProcedure.failedToAdd"));
}
return new SuccessResult(ui.message("operationtheater.pastProcedure.successfullyAdded"));
}
}
@@ -0,0 +1,86 @@
/**
* 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.operationtheater.page.controller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.*;
import org.openmrs.api.PatientService;
import org.openmrs.api.ProviderService;
import org.openmrs.api.context.Context;
import org.openmrs.module.appframework.context.AppContextModel;
import org.openmrs.module.appui.UiSessionContext;
import org.openmrs.module.emrapi.adt.AdtService;
import org.openmrs.module.emrapi.event.ApplicationEventService;
import org.openmrs.module.emrapi.patient.PatientDomainWrapper;
import org.openmrs.module.emrapi.visit.VisitDomainWrapper;
import org.openmrs.module.operationtheater.OTMetadata;
import org.openmrs.module.operationtheater.Procedure;
import org.openmrs.module.operationtheater.Surgery;
import org.openmrs.module.operationtheater.api.OperationTheaterService;
import org.openmrs.ui.framework.UiUtils;
import org.openmrs.ui.framework.annotation.InjectBeans;
import org.openmrs.ui.framework.annotation.SpringBean;
import org.openmrs.ui.framework.page.PageModel;
import org.openmrs.ui.framework.page.Redirect;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
public class PretheaterDataPageController {
protected final Log log = LogFactory.getLog(getClass());
public Object controller(PageModel model,
UiUtils ui,
@RequestParam(value = "patient") Patient patient,
@RequestParam(value = "surgeryId") Surgery surgery,
@RequestParam(value = "returnUrl", required = false) String returnUrl,
@SpringBean OperationTheaterService otService,
@SpringBean("providerService") ProviderService providerService,
@SpringBean("patientService") PatientService patientService,
@InjectBeans PatientDomainWrapper patientDomainWrapper,
@SpringBean("adtService") AdtService adtService,
@SpringBean("applicationEventService") ApplicationEventService applicationEventService,
UiSessionContext sessionContext) {
if (patient.getVoided() || patient.getPersonVoided()) {
return new Redirect("coreapps", "patientdashboard/deletedPatient", "patientId=" + patient.getId());
}
model.addAttribute("surgery", surgery);
model.addAttribute("returnUrl", returnUrl);
patientDomainWrapper.setPatient(patient);
model.addAttribute("patient", patientDomainWrapper);
List<Procedure> procedureList = otService.getAllProcedures(false);
model.addAttribute("procedureList", procedureList);
List<Concept> drugList = Context.getConceptService().getConceptsByClass(
Context.getConceptService().getConceptClass(3));
model.addAttribute("drugList", drugList);
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patientId", patient.getId());
Allergies allergies = patientService.getAllergies(patient);
model.addAttribute( "allergies", allergies);
return null;
}
}
Oops, something went wrong.

0 comments on commit 1f32adb

Please sign in to comment.