protected Message processPatientLeave(Message msg, ProviderSystemVo providerSystem)
      throws HL7Exception {
    try {

      PatientShort patVo = (PatientShort) getPrimaryIdFromPid(msg, providerSystem);

      if (patVo != null) {
        patVo = getDemog().getPatient(patVo);

        if (patVo == null)
          return HL7Utils.buildRejAck(
              msg.get("MSH"),
              "This patient has not been registered within the system",
              HL7Errors.APP_INT_ERROR,
              toConfigItemArray(providerSystem.getConfigItems()));

        String eventCode = HL7Utils.getEventCode(msg);
        if (eventCode.equals("A21")
            || eventCode.equals(
                "A53")) // A21 set's patient on leave, A53 cancels the cancelled Patient Leave i.e.
          // sets them on leave again
          adt.recordInpatientLeave(patVo);
        else if (eventCode.equals("A22") || eventCode.equals("A52")) // Cancel Patient's Leave
        {
          PV1 pv1 = (PV1) msg.get("PV1");
          LocShortVo loc = null;
          loc =
              orgLoc.getLocationByTaxonomyType(
                  pv1.getAssignedPatientLocation().getPointOfCare().getValue(), TaxonomyType.PAS);
          patVo.setWard(loc);
          adt.cancelInpatientLeave(patVo); // A22
        }
      }
    } catch (StaleObjectException ex) {
      return HL7Utils.buildRejAck(
          msg.get("MSH"),
          "StaleObjectException occured recording Inpatient Leave - " + ex.getMessage(),
          HL7Errors.APP_INT_ERROR,
          toConfigItemArray(providerSystem.getConfigItems()));
    }

    Message ack =
        HL7Utils.buildPosAck(msg.get("MSH"), toConfigItemArray(providerSystem.getConfigItems()));
    return ack;
  }