Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This Source Code Form is subject to the terms of the Mozilla Public License,
- * v. 2.0. If a copy of the MPL was not distributed with this file, You can
- * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
- * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
- *
- * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
- * graphic logo is a trademark of OpenMRS Inc.
- */
- package org.openmrs.web.controller.patient;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Vector;
- import javax.servlet.ServletException;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.openmrs.Concept;
- import org.openmrs.Patient;
- import org.openmrs.api.ConceptService;
- import org.openmrs.api.EncounterService;
- import org.openmrs.api.LocationService;
- import org.openmrs.api.OrderService;
- import org.openmrs.api.PatientService;
- import org.openmrs.api.PersonService;
- import org.openmrs.api.context.Context;
- import org.openmrs.api.db.SerializedObject;
- import org.openmrs.module.Module;
- import org.openmrs.module.ModuleFactory;
- import org.openmrs.module.chitscore.CHITSPatientSearchService;
- import org.openmrs.module.chitscore.CHITSService;
- import org.openmrs.module.chitscore.ConceptUtilFactory;
- import org.openmrs.module.chitscore.Constants.CivilStatusConcepts;
- import org.openmrs.module.chitscore.Constants.IdAttributes;
- import org.openmrs.module.chitscore.Constants.MiscAttributes;
- import org.openmrs.module.chitscore.Constants.PhilhealthConcepts;
- import org.openmrs.module.chitscore.Constants.PhoneAttributes;
- import org.openmrs.module.chitscore.Constants.ProgramIds;
- import org.openmrs.module.chitscore.FamilyFolder;
- import org.openmrs.module.chitscore.PatientQueue;
- import org.openmrs.module.chitscore.PhilhealthUtil;
- import org.openmrs.module.chitscore.RelationshipUtil;
- import org.openmrs.module.chitscore.impl.StaticBarangayCodesHolder;
- import org.openmrs.module.chitscore.phie.PHIEService;
- import org.openmrs.web.WebConstants;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- @Controller
- public class PatientDashboardController {
- /** Logger for this class and subclasses */
- protected final Log log = LogFactory.getLog(getClass());
- /** Auto-wire the CHITS service */
- protected CHITSService chitsService;
- /** Auto-wire the Patient service */
- protected PatientService patientService;
- /** Auto-wire the concept service */
- protected ConceptService conceptService;
- /** Auto-wire the Order service */
- protected OrderService orderService;
- /** Auto-wire the Encounter service */
- protected EncounterService encounterService;
- /** Auto-wire the person service */
- protected PersonService personService;
- /** Auto-wire the location service */
- protected LocationService locationService;
- /** Auto-wire the concept util */
- protected ConceptUtilFactory conceptUtilFactory;
- /** Indirectly auto-wired relationship util */
- protected RelationshipUtil relationshipUtil;
- protected PHIEService phieService;
- private StaticBarangayCodesHolder holder = new StaticBarangayCodesHolder();
- /**
- * This is called prior to displaying a form for the first time. It tells Spring the
- * form/command object to load into the request
- *
- * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest)
- */
- @ModelAttribute("patientModel")
- public ShortPatientModel getPatientModelAttribute(ModelMap model, //
- @RequestParam(required = false, value = "patientId") Integer patientId) throws ServletException {
- final Patient patient = patientId != null ? patientService.getPatient(patientId) : null;
- final ShortPatientModel patientModel = new ShortPatientModel();
- patientModel.setPatient(patient);
- patientModel.setMother(relationshipUtil.getPatientMotherOrCreteNew(patientId));
- patientModel.setFather(relationshipUtil.getPatientFatherOrCreteNew(patientId));
- if (patient != null) {
- if (patient.getAttribute(PhilhealthConcepts.CHITS_PHILHEALTH) != null) {
- patientModel.setHasPhilhealth(true);
- }
- // store patient queue record (if any)
- patientModel.setPatientQueue(chitsService.getQueuedPatient(patient));
- }
- // return the patient
- return patientModel;
- }
- /**
- * Returns the current version of the patient being edited.
- *
- * @param patient The {@link Patient} instance to extract the version of.
- * @return The version of the version object.
- */
- protected long getCurrentVersion(Patient versionObject) {
- if (versionObject != null) {
- // use the 'dateChanged' value as the version
- return versionObject.getDateChanged() != null ? versionObject.getDateChanged().getTime() : 0;
- }
- // no available object, version is '0'
- return 0;
- }
- /**
- * Initializes the model for rendering
- */
- protected void initFormAndModel(ShortPatientModel patientModel, ModelMap model) {
- // attach the associated folders of this patient
- final Patient patient = patientModel.getPatient();
- final List<FamilyFolder> familyFolders = new ArrayList<FamilyFolder>();
- familyFolders.addAll(chitsService.getFamilyFoldersOf(patient.getPatientId()));
- model.addAttribute("familyFolders", familyFolders);
- // indicate if the patient is the head of the family | Employee | Employee Dependent
- String employee = "false";
- for (FamilyFolder folder : familyFolders) {
- if (folder.getHeadOfTheFamily() != null && folder.getHeadOfTheFamily().equals(patient)) {
- // patient is the head of the family
- patientModel.setHeadOftheFamily(true);
- employee = "Employee";
- }else if(folder.getHeadOfTheFamily() != null && !folder.getHeadOfTheFamily().equals(patient)){
- patientModel.setEmployee(false);
- employee = "Employee Dependent";
- }
- }
- if(patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE)) != null){
- String employeeAttribute = patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE)).getValue();
- System.out.println("EMPLOYEE ATTRIBUTE: " + employeeAttribute);
- if(employeeAttribute.equalsIgnoreCase("true")){
- patientModel.setEmployee(true);
- employee = "Employee";
- }
- }
- //get queue list
- List<PatientQueue> queueList = new Vector<PatientQueue>(); //All queues
- List<PatientQueue> patientQueue = new Vector<PatientQueue>(); //The current patient's queues
- List<PatientQueue> visitDetails = new Vector<PatientQueue>();
- List<PatientQueue> previousServices = new Vector<PatientQueue>();
- queueList = chitsService.getAllQueuedPatients();
- for(PatientQueue entry : queueList){
- if(entry.getPatient() == patient){
- patientQueue.add(entry);
- //entry.getEncounter().getActiveEncounterProviders().iterator().next(); //first element
- }
- }
- if (!patientQueue.isEmpty()) {
- //populate visit details and previous services
- for (PatientQueue queue : patientQueue) {
- if (queue.getExitedQueue() != null) {
- visitDetails.add(queue);
- }
- if (queue.getConsultEnd() != null) {
- previousServices.add(queue);
- }
- }
- //get latest exited queue date
- visitDetails.sort((q1, q2) -> q1.getExitedQueue().compareTo(q2.getExitedQueue()));
- Collections.reverse(visitDetails);
- if (!visitDetails.isEmpty()) {
- model.addAttribute("exitedQueue", visitDetails.get(0).getExitedQueue());
- }
- //get earliest entered queue date
- visitDetails.sort((q1, q2) -> q1.getEnteredQueue().compareTo(q2.getEnteredQueue()));
- if (!visitDetails.isEmpty()) {
- model.addAttribute("enteredQueue", visitDetails.get(0).getEnteredQueue());
- }
- //sort previous services according to consult start date
- previousServices.sort((q1, q2) -> q1.getConsultStart().compareTo(q2.getConsultStart()));
- if (!visitDetails.isEmpty() && !previousServices.isEmpty()) {
- model.addAttribute("visitDetails", visitDetails);
- model.addAttribute("previousServices", previousServices);
- }
- }
- // use minimal header
- model.addAttribute(WebConstants.OPENMRS_HEADER_USE_MINIMAL, "true");
- // calculate the philhealth status and add it to the model
- model.addAttribute("philhealthStatus", PhilhealthUtil.getPhilhealthStatus(patientModel.getPatient(), familyFolders));
- model.addAttribute("religion", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.RELIGION)));
- model.addAttribute("birthOrder", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.BIRTHORDER)));
- model.addAttribute("occupation", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.OCCUPATION)));
- model.addAttribute("civilStatus", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(CivilStatusConcepts.CIVIL_STATUS
- .getConceptName())));
- model.addAttribute("fourPs", patientModel.isFourPs());
- model.addAttribute("nonPatient", patientModel.isNonPatient());
- model.addAttribute("cellphone", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(PhoneAttributes.MOBILE_NUMBER)));
- model.addAttribute("localId", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(IdAttributes.LOCAL_ID)));
- model.addAttribute("gender", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.GENDER)));
- model.addAttribute("patientType", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.PATIENT_TYPE)));
- model.addAttribute("municipalities", holder.municipalities);
- model.addAttribute("barangays", holder.barangays);
- model.addAttribute("employee", employee);
- model.addAttribute("employeeDepartment", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE_DEPARTMENT)));
- model.addAttribute("employeeId", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE_ID)));
- Object[][] programList = {
- {
- "GeneralConsult",
- ProgramIds.GENERAL_CONSULT
- }, {
- "MaternalCare",
- ProgramIds.MATERNAL_CARE
- }, {
- "Leprosy",
- ProgramIds.LEPROSY
- }, {
- "SocialHygiene",
- ProgramIds.SOCIAL_HYGIENE
- }, {
- "RabiesControl",
- ProgramIds.RABIES_CONTROL
- }, {
- "ECCD",
- ProgramIds.ECCD
- }, {
- "Dental",
- ProgramIds.DENTAL
- }, {
- "LyingIn",
- ProgramIds.LYING_IN
- }, {
- "FamilyPlanning",
- ProgramIds.FAMILY_PLANNING
- }
- };
- for(int i = 0; i < programList.length; i++) {
- // Check if patient is in queue
- model.addAttribute("inQueueIn_" + programList[i][0].toString(), chitsService.isPatientInQueue(patientModel.getPatient().getId(), Integer.parseInt(programList[i][1].toString())));
- // Check if patient is on consultation
- model.addAttribute("onConsultationIn_" + programList[i][0].toString(), chitsService.isPatientOnConsultation(patientModel.getPatient().getId(), Integer.parseInt(programList[i][1].toString())));
- // Check if module is installed
- Module module = ModuleFactory.getModuleById(programList[i][0].toString().toLowerCase());
- model.addAttribute("isInstalled_" + programList[i][0].toString(), (module != null && module.isStarted()) ? true : false);
- }
- }
- @Autowired
- public void setPersonPatientAndCHITSService(PersonService personService, PatientService patientService,
- CHITSService chitsService, CHITSPatientSearchService chitsPatientSearchService, PHIEService phieService) {
- this.personService = personService;
- this.patientService = patientService;
- this.chitsService = chitsService;
- this.relationshipUtil = new RelationshipUtil(personService, patientService, chitsPatientSearchService);
- this.phieService = phieService;
- }
- @Autowired
- public void setConceptService(ConceptService conceptService) {
- this.conceptService = conceptService;
- }
- @Autowired
- public void setLocationService(LocationService locationService) {
- this.locationService = locationService;
- }
- @Autowired
- public void setEncounterService(EncounterService encounterService) {
- this.encounterService = encounterService;
- }
- @Autowired
- public void setOrderService(OrderService orderService) {
- this.orderService = orderService;
- }
- //@Autowired
- //public void setConceptUtilFactory(ConceptUtilFactory conceptUtilFactory) {
- // this.conceptUtilFactory = conceptUtilFactory;
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement