private TriageForRIETriageAssessmentVo getTriage(CareContextRefVo careContext) {
    String query =
        "SELECT trg FROM Triage AS trg LEFT JOIN trg.attendance AS attd WHERE attd.id = :CONTEXT_ID and (trg.isRIE is null OR trg.isRIE = 0)";

    return TriageForRIETriageAssessmentVoAssembler.create(
        (Triage)
            getDomainFactory().findFirst(query, "CONTEXT_ID", careContext.getID_CareContext()));
  }
  public void markTriageAsRIE(
      TriageProtocolAssessmentShortVo triageAssessment,
      FormName formName,
      PatientRefVo patient,
      CareContextRefVo careContext,
      String messageRIE)
      throws StaleObjectException, DomainInterfaceException {
    if (triageAssessment == null || triageAssessment.getID_TriageProtocolAssessment() == null)
      throw new CodingRuntimeException("Cannot RIE the records not saved.");

    // Get the Triage to check if it is the current Triage Assessment
    TriageForRIETriageAssessmentVo triage = getTriage(careContext);

    if (triage != null) {
      if (triage.getInitialTriageAssessment() == null
          || triageAssessment.equals(triage.getInitialTriageAssessment()))
        throw new DomainInterfaceException("Cannot record in error initial triage.");

      if (triageAssessment.equals(triage.getCurrentTriageAssessment())) {
        // Get the previous triage Assessment
        TriageProtocolAssessmentShortVo previousAssessment =
            getPreviousProtocolAssessment(
                careContext,
                triageAssessment.getAssessmentDateTime(),
                triage.getCurrentTriageAssessment());

        if (previousAssessment == null) return; // TODO - cannot RIE past the initial triage

        // Update current triage Assessment
        triage.setCurrentTriageAssessment(previousAssessment);
        if (triage.getInitialTriageAssessment().equals(previousAssessment))
          triage.setTriagePriorityChange(null);
        else
          triage.setTriagePriorityChange(
              getPriorityChange(
                  triage.getInitialTriageAssessment().getTriagePriority(),
                  previousAssessment.getTriagePriority()));
        triage.setCurrentTriagePriority(previousAssessment.getTriagePriority());

        getDomainFactory()
            .save(
                TriageForRIETriageAssessmentVoAssembler.extractTriage(getDomainFactory(), triage));
      }
    }

    markAsRie(
        triageAssessment,
        formName,
        patient.getID_Patient(),
        null,
        careContext.getID_CareContext(),
        messageRIE);
  }