Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.89 KB | None | 0 0
  1. /**
  2. * This Source Code Form is subject to the terms of the Mozilla Public License,
  3. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  4. * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
  5. * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
  6. *
  7. * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
  8. * graphic logo is a trademark of OpenMRS Inc.
  9. */
  10. package org.openmrs.web.controller.patient;
  11.  
  12. import java.util.ArrayList;
  13. import java.util.Collections;
  14. import java.util.List;
  15. import java.util.Vector;
  16.  
  17. import javax.servlet.ServletException;
  18.  
  19. import org.apache.commons.logging.Log;
  20. import org.apache.commons.logging.LogFactory;
  21. import org.openmrs.Concept;
  22. import org.openmrs.Patient;
  23. import org.openmrs.api.ConceptService;
  24. import org.openmrs.api.EncounterService;
  25. import org.openmrs.api.LocationService;
  26. import org.openmrs.api.OrderService;
  27. import org.openmrs.api.PatientService;
  28. import org.openmrs.api.PersonService;
  29. import org.openmrs.api.context.Context;
  30. import org.openmrs.api.db.SerializedObject;
  31. import org.openmrs.module.Module;
  32. import org.openmrs.module.ModuleFactory;
  33. import org.openmrs.module.chitscore.CHITSPatientSearchService;
  34. import org.openmrs.module.chitscore.CHITSService;
  35. import org.openmrs.module.chitscore.ConceptUtilFactory;
  36. import org.openmrs.module.chitscore.Constants.CivilStatusConcepts;
  37. import org.openmrs.module.chitscore.Constants.IdAttributes;
  38. import org.openmrs.module.chitscore.Constants.MiscAttributes;
  39. import org.openmrs.module.chitscore.Constants.PhilhealthConcepts;
  40. import org.openmrs.module.chitscore.Constants.PhoneAttributes;
  41. import org.openmrs.module.chitscore.Constants.ProgramIds;
  42. import org.openmrs.module.chitscore.FamilyFolder;
  43. import org.openmrs.module.chitscore.PatientQueue;
  44. import org.openmrs.module.chitscore.PhilhealthUtil;
  45. import org.openmrs.module.chitscore.RelationshipUtil;
  46. import org.openmrs.module.chitscore.impl.StaticBarangayCodesHolder;
  47. import org.openmrs.module.chitscore.phie.PHIEService;
  48. import org.openmrs.web.WebConstants;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.stereotype.Controller;
  51. import org.springframework.ui.ModelMap;
  52. import org.springframework.web.bind.annotation.ModelAttribute;
  53. import org.springframework.web.bind.annotation.RequestMapping;
  54. import org.springframework.web.bind.annotation.RequestMethod;
  55. import org.springframework.web.bind.annotation.RequestParam;
  56.  
  57. @Controller
  58. public class PatientDashboardController {
  59.  
  60.  
  61. /** Logger for this class and subclasses */
  62. protected final Log log = LogFactory.getLog(getClass());
  63.  
  64.  
  65. /** Auto-wire the CHITS service */
  66. protected CHITSService chitsService;
  67.  
  68. /** Auto-wire the Patient service */
  69. protected PatientService patientService;
  70.  
  71. /** Auto-wire the concept service */
  72. protected ConceptService conceptService;
  73.  
  74. /** Auto-wire the Order service */
  75. protected OrderService orderService;
  76.  
  77. /** Auto-wire the Encounter service */
  78. protected EncounterService encounterService;
  79.  
  80. /** Auto-wire the person service */
  81. protected PersonService personService;
  82.  
  83. /** Auto-wire the location service */
  84. protected LocationService locationService;
  85.  
  86. /** Auto-wire the concept util */
  87. protected ConceptUtilFactory conceptUtilFactory;
  88.  
  89. /** Indirectly auto-wired relationship util */
  90. protected RelationshipUtil relationshipUtil;
  91.  
  92. protected PHIEService phieService;
  93.  
  94. private StaticBarangayCodesHolder holder = new StaticBarangayCodesHolder();
  95.  
  96.  
  97. /**
  98. * This is called prior to displaying a form for the first time. It tells Spring the
  99. * form/command object to load into the request
  100. *
  101. * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest)
  102. */
  103. @ModelAttribute("patientModel")
  104. public ShortPatientModel getPatientModelAttribute(ModelMap model, //
  105. @RequestParam(required = false, value = "patientId") Integer patientId) throws ServletException {
  106. final Patient patient = patientId != null ? patientService.getPatient(patientId) : null;
  107.  
  108. final ShortPatientModel patientModel = new ShortPatientModel();
  109. patientModel.setPatient(patient);
  110. patientModel.setMother(relationshipUtil.getPatientMotherOrCreteNew(patientId));
  111. patientModel.setFather(relationshipUtil.getPatientFatherOrCreteNew(patientId));
  112. if (patient != null) {
  113. if (patient.getAttribute(PhilhealthConcepts.CHITS_PHILHEALTH) != null) {
  114. patientModel.setHasPhilhealth(true);
  115. }
  116.  
  117. // store patient queue record (if any)
  118. patientModel.setPatientQueue(chitsService.getQueuedPatient(patient));
  119. }
  120.  
  121. // return the patient
  122. return patientModel;
  123. }
  124.  
  125. /**
  126. * Returns the current version of the patient being edited.
  127. *
  128. * @param patient The {@link Patient} instance to extract the version of.
  129. * @return The version of the version object.
  130. */
  131. protected long getCurrentVersion(Patient versionObject) {
  132. if (versionObject != null) {
  133. // use the 'dateChanged' value as the version
  134. return versionObject.getDateChanged() != null ? versionObject.getDateChanged().getTime() : 0;
  135. }
  136.  
  137. // no available object, version is '0'
  138. return 0;
  139. }
  140.  
  141. /**
  142. * Initializes the model for rendering
  143. */
  144. protected void initFormAndModel(ShortPatientModel patientModel, ModelMap model) {
  145. // attach the associated folders of this patient
  146. final Patient patient = patientModel.getPatient();
  147. final List<FamilyFolder> familyFolders = new ArrayList<FamilyFolder>();
  148.  
  149. familyFolders.addAll(chitsService.getFamilyFoldersOf(patient.getPatientId()));
  150. model.addAttribute("familyFolders", familyFolders);
  151.  
  152. // indicate if the patient is the head of the family | Employee | Employee Dependent
  153. String employee = "false";
  154.  
  155. for (FamilyFolder folder : familyFolders) {
  156. if (folder.getHeadOfTheFamily() != null && folder.getHeadOfTheFamily().equals(patient)) {
  157. // patient is the head of the family
  158. patientModel.setHeadOftheFamily(true);
  159. employee = "Employee";
  160. }else if(folder.getHeadOfTheFamily() != null && !folder.getHeadOfTheFamily().equals(patient)){
  161. patientModel.setEmployee(false);
  162. employee = "Employee Dependent";
  163. }
  164. }
  165.  
  166. if(patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE)) != null){
  167. String employeeAttribute = patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE)).getValue();
  168. System.out.println("EMPLOYEE ATTRIBUTE: " + employeeAttribute);
  169. if(employeeAttribute.equalsIgnoreCase("true")){
  170. patientModel.setEmployee(true);
  171. employee = "Employee";
  172. }
  173. }
  174.  
  175. //get queue list
  176. List<PatientQueue> queueList = new Vector<PatientQueue>(); //All queues
  177. List<PatientQueue> patientQueue = new Vector<PatientQueue>(); //The current patient's queues
  178. List<PatientQueue> visitDetails = new Vector<PatientQueue>();
  179. List<PatientQueue> previousServices = new Vector<PatientQueue>();
  180. queueList = chitsService.getAllQueuedPatients();
  181. for(PatientQueue entry : queueList){
  182. if(entry.getPatient() == patient){
  183. patientQueue.add(entry);
  184. //entry.getEncounter().getActiveEncounterProviders().iterator().next(); //first element
  185. }
  186. }
  187.  
  188. if (!patientQueue.isEmpty()) {
  189. //populate visit details and previous services
  190. for (PatientQueue queue : patientQueue) {
  191. if (queue.getExitedQueue() != null) {
  192. visitDetails.add(queue);
  193. }
  194. if (queue.getConsultEnd() != null) {
  195. previousServices.add(queue);
  196. }
  197. }
  198. //get latest exited queue date
  199. visitDetails.sort((q1, q2) -> q1.getExitedQueue().compareTo(q2.getExitedQueue()));
  200. Collections.reverse(visitDetails);
  201.  
  202. if (!visitDetails.isEmpty()) {
  203. model.addAttribute("exitedQueue", visitDetails.get(0).getExitedQueue());
  204. }
  205. //get earliest entered queue date
  206. visitDetails.sort((q1, q2) -> q1.getEnteredQueue().compareTo(q2.getEnteredQueue()));
  207. if (!visitDetails.isEmpty()) {
  208. model.addAttribute("enteredQueue", visitDetails.get(0).getEnteredQueue());
  209. }
  210. //sort previous services according to consult start date
  211. previousServices.sort((q1, q2) -> q1.getConsultStart().compareTo(q2.getConsultStart()));
  212. if (!visitDetails.isEmpty() && !previousServices.isEmpty()) {
  213. model.addAttribute("visitDetails", visitDetails);
  214. model.addAttribute("previousServices", previousServices);
  215. }
  216. }
  217.  
  218.  
  219. // use minimal header
  220. model.addAttribute(WebConstants.OPENMRS_HEADER_USE_MINIMAL, "true");
  221.  
  222. // calculate the philhealth status and add it to the model
  223. model.addAttribute("philhealthStatus", PhilhealthUtil.getPhilhealthStatus(patientModel.getPatient(), familyFolders));
  224. model.addAttribute("religion", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.RELIGION)));
  225. model.addAttribute("birthOrder", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.BIRTHORDER)));
  226. model.addAttribute("occupation", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.OCCUPATION)));
  227. model.addAttribute("civilStatus", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(CivilStatusConcepts.CIVIL_STATUS
  228. .getConceptName())));
  229. model.addAttribute("fourPs", patientModel.isFourPs());
  230. model.addAttribute("nonPatient", patientModel.isNonPatient());
  231. model.addAttribute("cellphone", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(PhoneAttributes.MOBILE_NUMBER)));
  232. model.addAttribute("localId", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(IdAttributes.LOCAL_ID)));
  233. model.addAttribute("gender", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.GENDER)));
  234. model.addAttribute("patientType", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.PATIENT_TYPE)));
  235. model.addAttribute("municipalities", holder.municipalities);
  236. model.addAttribute("barangays", holder.barangays);
  237. model.addAttribute("employee", employee);
  238. model.addAttribute("employeeDepartment", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE_DEPARTMENT)));
  239. model.addAttribute("employeeId", patientModel.getPatient().getAttribute(personService.getPersonAttributeTypeByName(MiscAttributes.EMPLOYEE_ID)));
  240.  
  241. Object[][] programList = {
  242. {
  243. "GeneralConsult",
  244. ProgramIds.GENERAL_CONSULT
  245. }, {
  246. "MaternalCare",
  247. ProgramIds.MATERNAL_CARE
  248. }, {
  249. "Leprosy",
  250. ProgramIds.LEPROSY
  251. }, {
  252. "SocialHygiene",
  253. ProgramIds.SOCIAL_HYGIENE
  254. }, {
  255. "RabiesControl",
  256. ProgramIds.RABIES_CONTROL
  257. }, {
  258. "ECCD",
  259. ProgramIds.ECCD
  260. }, {
  261. "Dental",
  262. ProgramIds.DENTAL
  263. }, {
  264. "LyingIn",
  265. ProgramIds.LYING_IN
  266. }, {
  267. "FamilyPlanning",
  268. ProgramIds.FAMILY_PLANNING
  269. }
  270. };
  271. for(int i = 0; i < programList.length; i++) {
  272. // Check if patient is in queue
  273. model.addAttribute("inQueueIn_" + programList[i][0].toString(), chitsService.isPatientInQueue(patientModel.getPatient().getId(), Integer.parseInt(programList[i][1].toString())));
  274.  
  275. // Check if patient is on consultation
  276. model.addAttribute("onConsultationIn_" + programList[i][0].toString(), chitsService.isPatientOnConsultation(patientModel.getPatient().getId(), Integer.parseInt(programList[i][1].toString())));
  277.  
  278. // Check if module is installed
  279. Module module = ModuleFactory.getModuleById(programList[i][0].toString().toLowerCase());
  280. model.addAttribute("isInstalled_" + programList[i][0].toString(), (module != null && module.isStarted()) ? true : false);
  281. }
  282.  
  283. }
  284.  
  285. @Autowired
  286. public void setPersonPatientAndCHITSService(PersonService personService, PatientService patientService,
  287. CHITSService chitsService, CHITSPatientSearchService chitsPatientSearchService, PHIEService phieService) {
  288. this.personService = personService;
  289. this.patientService = patientService;
  290. this.chitsService = chitsService;
  291. this.relationshipUtil = new RelationshipUtil(personService, patientService, chitsPatientSearchService);
  292. this.phieService = phieService;
  293. }
  294.  
  295. @Autowired
  296. public void setConceptService(ConceptService conceptService) {
  297. this.conceptService = conceptService;
  298. }
  299.  
  300. @Autowired
  301. public void setLocationService(LocationService locationService) {
  302. this.locationService = locationService;
  303. }
  304.  
  305. @Autowired
  306. public void setEncounterService(EncounterService encounterService) {
  307. this.encounterService = encounterService;
  308. }
  309.  
  310. @Autowired
  311. public void setOrderService(OrderService orderService) {
  312. this.orderService = orderService;
  313. }
  314.  
  315.  
  316.  
  317. //@Autowired
  318. //public void setConceptUtilFactory(ConceptUtilFactory conceptUtilFactory) {
  319. // this.conceptUtilFactory = conceptUtilFactory;
  320. //}
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement