Ejemplo n.º 1
0
  // WDEV-20112
  //	public Message processEvent(Message msg, ProviderSystemVo providerSystem) throws HL7Exception
  public EventResponse processEvent(Message msg, ProviderSystemVo providerSystem)
      throws HL7Exception // WDEV-20112
      {
    // WDEV-20112
    EventResponse response = new EventResponse(); // WDEV-20112

    try {
      if (isClinicType(msg)) processClinic(msg, providerSystem);
      else processLocation(msg, providerSystem);

    } catch (Exception ex) {
      LOG.error(ex.getMessage(), ex);
      // WDEV-20112
      //			return HL7Utils.buildRejAck( msg.get("MSH"), "Exception. " + ex.getMessage(),
      // HL7Errors.APP_INT_ERROR, toConfigItemArray(providerSystem.getConfigItems()));
      response.setMessage(
          HL7Utils.buildRejAck(
              msg.get("MSH"),
              "Exception. " + ex.getMessage(),
              HL7Errors.APP_INT_ERROR,
              toConfigItemArray(providerSystem.getConfigItems())));
      return response; // WDEV-20112
    }

    // WDEV-20112
    //		Message ack = HL7Utils.buildPosAck( msg.get("MSH"),
    // toConfigItemArray(providerSystem.getConfigItems()));
    //		return ack;
    response.setMessage(
        HL7Utils.buildPosAck(msg.get("MSH"), toConfigItemArray(providerSystem.getConfigItems())));
    return response; // WDEV-20112
  }
  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;
  }
  private Message processCancelDischarge(Message msg, ProviderSystemVo providerSystem)
      throws HL7Exception {
    PV1 pv1 = (PV1) msg.get("PV1");
    String patClass = pv1.getPatientClass().getValue();

    if (patClass != null && patClass.equals(EMERGENCY_APP)) {
      A05VoMapper a05mapper = (A05VoMapper) HL7EngineApplication.getVoMapper(EvnCodes.A05);
      if (a05mapper == null) {
        throw new HL7Exception(
            "A13 mapper requires A05 mapper. A05 mapper not found in list of registerd mappers.");
      }

      Message ack = a05mapper.processEvent(msg, providerSystem);
      return ack;
    }

    Patient patVo;
    try {
      patVo = savePatient(msg, providerSystem, false);
    } catch (Exception ex) {
      return HL7Utils.buildRejAck(
          msg.get("MSH"),
          "Exception: " + ex.getMessage(),
          HL7Errors.APP_INT_ERROR,
          toConfigItemArray(providerSystem.getConfigItems()));
    }
    try {
      DischargedEpisodeVo dischargeVo =
          fillDischargeFromMsg(msg, getOrgLoc(), getHcpAdmin(), providerSystem);
      dischargeVo.getPasEvent().setPatient(patVo);
      String[] errs = dischargeVo.validate();
      if (errs != null) {
        throw new HL7Exception("Validation of Discharge failed. " + VoMapper.toDisplayString(errs));
      }
      // wdev-7261 - Patient needs to be validated also
      errs = patVo.validate();
      if (errs != null) {
        throw new HL7Exception("Validation of Patient failed. " + VoMapper.toDisplayString(errs));
      }

      // wdev-12588 Need to remove the end date on the care context
      CareContextInterfaceVo voCareContext = null;
      if (ConfigFlag.HL7.INPATIENT_EPISODE_MANAGEMENT_FROM_PAS.getValue()
          || ConfigFlag.HL7.INSTANTIATE_EPISODE_FROM_ADT.getValue()) {
        PASEventRefVo pasEvt = null;
        if (!dischargeVo.getPasEvent().getID_PASEventIsNotNull()) {
          pasEvt = getADT().getPasEventByUnqIdx(patVo, dischargeVo.getPasEvent().getPasEventId());
        } else {
          pasEvt = dischargeVo.getPasEvent();
        }

        if (pasEvt != null) {
          voCareContext = getADT().getCareContextByPasEvent(pasEvt);
          if (voCareContext != null) {
            voCareContext.setEndDateTime(null);
            voCareContext.setBedNumber(null);
          }
        }
      }

      getADT().cancelDischarge(patVo, dischargeVo, voCareContext);
    } catch (Exception ex) {
      return HL7Utils.buildRejAck(
          msg.get("MSH"),
          "Exception: " + ex.getMessage(),
          HL7Errors.APP_INT_ERROR,
          toConfigItemArray(providerSystem.getConfigItems()));
    }
    Message ack =
        HL7Utils.buildPosAck(msg.get("MSH"), toConfigItemArray(providerSystem.getConfigItems()));
    return ack;
  }