@RequestMapping("/module/hirifxray/participant.form")
  public String viewParticipant(
      ModelMap model,
      @RequestParam(value = "id", required = true) Integer id,
      @RequestParam(value = "type", required = false) Concept type,
      @RequestParam(value = "xrayId", required = false) Encounter encounter) {

    User currentUser = Context.getAuthenticatedUser();
    if (currentUser == null) {
      return "redirect:/login.htm";
    }

    Xray xray = new Xray(encounter);

    model.addAttribute("type", type);
    model.addAttribute("xray", xray);

    Patient patient = Context.getPatientService().getPatient(id);
    model.addAttribute("patient", patient);

    model.addAttribute("xrayTypes", HirifMetadata.getXrayTypes());
    model.addAttribute("xraysByType", HirifUtil.getXraysByType(patient));

    model.addAttribute("xrayLocations", HirifMetadata.getXrayLocations());

    model.addAttribute("xrayStatuses", HirifMetadata.getXrayStatuses());
    model.addAttribute("notDoneStatus", HirifMetadata.getNotDoneStatus());
    model.addAttribute("completedStatus", HirifMetadata.getCompletedStatus());

    return null;
  }
  @RequestMapping("/module/hirifxray/uploadXray.form")
  public String uploadXray(
      ModelMap model,
      @RequestParam(value = "patientId", required = true) Patient patient,
      @RequestParam(value = "xrayId", required = false) Encounter encounter,
      @RequestParam(value = "xrayDate", required = false) Date encounterDate,
      @RequestParam(value = "type", required = true) Concept type,
      @RequestParam(value = "status", required = false) Concept status,
      @RequestParam(value = "location", required = false) Concept location,
      @RequestParam(value = "xrayFile", required = false) MultipartFile xrayFile)
      throws Exception {

    ComplexData xrayData = null;
    if (xrayFile != null && !xrayFile.isEmpty()) {
      String identifier = patient.getPatientIdentifier().getIdentifier();
      String[] fileParts = xrayFile.getOriginalFilename().split("\\.");
      String xrayKey = identifier + "_" + type + "." + fileParts[fileParts.length - 1];
      xrayData = new ComplexData(xrayKey, xrayFile.getInputStream());
    }

    if (encounter == null) {
      encounter = new Encounter();
      encounter.setPatient(patient);
      encounter.setEncounterType(HirifMetadata.getEncounterType());
    }
    encounter.setEncounterDatetime(
        encounterDate == null ? HirifUtil.dateMidnight() : encounterDate);

    HirifUtil.updateCodedObs(encounter, HirifMetadata.getXrayTypeConcept(), type);
    HirifUtil.updateCodedObs(encounter, HirifMetadata.getXrayStatusConcept(), status);
    HirifUtil.updateCodedObs(encounter, HirifMetadata.getXrayLocationConcept(), location);
    HirifUtil.updateComplexObs(encounter, HirifMetadata.getXrayImageConcept(), xrayData);

    encounter = Context.getEncounterService().saveEncounter(encounter);

    return "redirect:/module/hirifxray/participant.form?id="
        + patient.getPatientId()
        + "&type="
        + type
        + "&xrayId="
        + encounter.getEncounterId();
  }