public Result searchPost() { // searchPost validates the search before redirecting to either indexGet // or editGet SearchViewModel searchViewModel = searchViewModelForm.bindFromRequest().get(); int id = searchViewModel.getId(); ServiceResponse<IPatient> patientServiceResponse = searchService.findPatientById(id); if (patientServiceResponse.hasErrors()) { return redirect(routes.MedicalController.indexGet(0, "That patient can not be found.")); } ServiceResponse<IPatientEncounter> patientEncounterServiceResponse = searchService.findCurrentEncounterByPatientId(id); IPatientEncounter patientEncounter = patientEncounterServiceResponse.getResponseObject(); boolean hasPatientBeenCheckedIn = medicalService.hasPatientBeenCheckedIn(patientEncounter.getId()); if (hasPatientBeenCheckedIn == true) { String message; ServiceResponse<DateTime> dateResponse = medicalService.getDateOfCheckIn(patientEncounter.getId()); if (dateResponse.hasErrors()) { return redirect( routes.MedicalController.indexGet( 0, "A fatal error has been encountered. Please try again.")); } DateTime dateNow = dateUtils.getCurrentDateTime(); DateTime dateTaken = dateResponse.getResponseObject(); if (dateNow.dayOfYear().equals(dateTaken.dayOfYear())) { message = "That patient has already been seen today. Would you like to edit their encounter?"; } else { message = "That patient's encounter has been closed."; id = 0; } return redirect(routes.MedicalController.indexGet(id, message)); } return redirect(routes.MedicalController.editGet(searchViewModel.getId())); }
public Result editPost(int patientId) { CurrentUser currentUserSession = sessionService.getCurrentUserSession(); CreateViewModelPost viewModelPost = createViewModelPostForm.bindFromRequest().get(); ServiceResponse<IPatientEncounter> patientEncounterServiceResponse = searchService.findCurrentEncounterByPatientId(patientId); if (patientEncounterServiceResponse.hasErrors()) { return internalServerError(); } IPatientEncounter patientEncounter = patientEncounterServiceResponse.getResponseObject(); // HPI Data List<IPatientEncounterHpiField> patientEncounterHpiFields = medicalHelper.populateHpiFields(viewModelPost, patientEncounter, currentUserSession); ServiceResponse<IPatientEncounterHpiField> patientEncounterHpiFieldServiceResponse; for (int j = 0; j < patientEncounterHpiFields.size(); j++) { if (StringUtils.isNullOrWhiteSpace(patientEncounterHpiFields.get(j).getHpiFieldValue())) { continue; } else { patientEncounterHpiFieldServiceResponse = medicalService.createPatientEncounterHpiField(patientEncounterHpiFields.get(j)); if (patientEncounterHpiFieldServiceResponse.hasErrors()) { return internalServerError(); } } } // Treatment Data List<IPatientEncounterTreatmentField> patientEncounterTreatmentFields = medicalHelper.populateTreatmentFields(viewModelPost, patientEncounter, currentUserSession); ServiceResponse<IPatientEncounterTreatmentField> patientEncounterTreatmentFieldServiceResponse; for (int i = 0; i < patientEncounterTreatmentFields.size(); i++) { if (StringUtils.isNullOrWhiteSpace( patientEncounterTreatmentFields.get(i).getTreatmentFieldValue())) { continue; } else { patientEncounterTreatmentFieldServiceResponse = medicalService.createPatientEncounterTreatmentField( patientEncounterTreatmentFields.get(i)); if (patientEncounterTreatmentFieldServiceResponse.hasErrors()) { return internalServerError(); } } } // prescriptions List<IPatientPrescription> patientPrescriptions = medicalHelper.populatePatientPrescriptions( viewModelPost, patientEncounter, currentUserSession); ServiceResponse<IPatientPrescription> patientPrescriptionServiceResponse; for (int k = 0; k < patientPrescriptions.size(); k++) { if (StringUtils.isNullOrWhiteSpace(patientPrescriptions.get(k).getMedicationName())) { continue; } else { patientPrescriptionServiceResponse = medicalService.createPatientPrescription(patientPrescriptions.get(k)); if (patientPrescriptionServiceResponse.hasErrors()) { return internalServerError(); } } } return redirect(routes.MedicalController.indexGet(0, null)); }