Beispiel #1
0
  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()));
  }
Beispiel #2
0
  public Result editGet(int patientId) {

    CurrentUser currentUserSession = sessionService.getCurrentUserSession();

    // current Patient info for view model
    ServiceResponse<IPatient> patientServiceResponse = searchService.findPatientById(patientId);
    if (patientServiceResponse.hasErrors()) {
      // this error should have been caught by searchPost
      return internalServerError();
    }
    IPatient patient = patientServiceResponse.getResponseObject();

    // current Encounter info for view model
    ServiceResponse<IPatientEncounter> patientEncounterServiceResponse =
        searchService.findCurrentEncounterByPatientId(patientId);
    if (patientEncounterServiceResponse.hasErrors()) {
      return internalServerError();
    }
    IPatientEncounter patientEncounter = patientEncounterServiceResponse.getResponseObject();

    // current vitals for view model
    List<IPatientEncounterVital> patientEncounterVitals = new ArrayList<>();
    ServiceResponse<IPatientEncounterVital> patientEncounterVitalServiceResponse;
    int TOTAL_VITALS = 9;
    for (int vital = 1; vital <= TOTAL_VITALS; vital++) {
      patientEncounterVitalServiceResponse =
          searchService.findPatientEncounterVitalByVitalIdAndEncounterId(
              vital, patientEncounter.getId());
      if (patientEncounterVitalServiceResponse.hasErrors()) {
        patientEncounterVitals.add(null);
      } else {
        patientEncounterVitals.add(patientEncounterVitalServiceResponse.getResponseObject());
      }
    }

    // viewModelPost is populated with editable fields
    ServiceResponse<List<? extends IPatientPrescription>> patientPrescriptionsServiceResponse =
        searchService.findPrescriptionsByEncounterId(patientEncounter.getId());
    List<? extends IPatientPrescription> patientPrescriptions = new ArrayList<>();
    if (patientPrescriptionsServiceResponse.hasErrors()) {
      // do nothing, there might not always be available prescriptions
    } else {
      patientPrescriptions = patientPrescriptionsServiceResponse.getResponseObject();
    }

    ServiceResponse<Map<Integer, List<? extends IPatientEncounterTreatmentField>>>
        patientTreatmentFieldsServiceResponse =
            searchService.findTreatmentFieldsByEncounterId(patientEncounter.getId());
    Map<Integer, List<? extends IPatientEncounterTreatmentField>> patientEncounterTreatmentMap =
        new LinkedHashMap<>();
    if (patientTreatmentFieldsServiceResponse.hasErrors()) {
      // do nothing, there might not always be available treatments
    } else {
      patientEncounterTreatmentMap = patientTreatmentFieldsServiceResponse.getResponseObject();
    }

    ServiceResponse<Map<Integer, List<? extends IPatientEncounterHpiField>>>
        patientHpiFieldsServiceResponse =
            searchService.findHpiFieldsByEncounterId(patientEncounter.getId());
    Map<Integer, List<? extends IPatientEncounterHpiField>> patientEncounterHpiMap =
        new LinkedHashMap<>();
    if (patientHpiFieldsServiceResponse.hasErrors()) {
      // do nothing, there might not always be available hpi fields
    } else {
      patientEncounterHpiMap = patientHpiFieldsServiceResponse.getResponseObject();
    }
    CreateViewModelPost viewModelPost =
        medicalHelper.populateViewModelPost(
            patientPrescriptions, patientEncounterTreatmentMap, patientEncounterHpiMap);
    CreateViewModelGet viewModelGet =
        medicalHelper.populateViewModelGet(
            patient, patientEncounter, patientEncounterVitals, viewModelPost);
    return ok(edit.render(currentUserSession, viewModelGet));
  }