示例#1
0
  @Test
  public void generate() {
    logger.info("     INIT generate()");

    try {
      ACK ack = new ACK();
      ack.initQuickstart("ACK", null, "P");

      // MSH
      MSH msh = ack.getMSH();
      msh.getSendingApplication().getNamespaceID().setValue("sistemaExterno"); // MSH.3.1
      msh.getSendingFacility().getNamespaceID().setValue("FARMATOOLS"); // MSH.4.1
      msh.getReceivingFacility().getNamespaceID().setValue("HOSPITAL"); // MSH.6.1
      msh.getDateTimeOfMessage()
          .getTime()
          .setValue(
              DateUtil.format(
                  DateUtil.parse("03/04/2015 12:09:51", DateUtil.FECHA_HORA_SEPARADOR_BARRA),
                  DateUtil.FECHA_HORA_SIN_SEPARADOR_INVERTIDA)); // MSH.7
      msh.getSecurity().setValue("calidad2:calidad2"); // MSH.8
      msh.getMessageControlID().setValue("14966c1c9a394b79ad65b341fdaff"); // MSH.10
      msh.getProcessingID().getProcessingID().setValue("E"); // MSH.12
      msh.getAcceptAcknowledgmentType().setValue("AL"); // MSH.15
      msh.getApplicationAcknowledgmentType().setValue("AL"); // MSH.16
      msh.getCountryCode().setValue("ESP"); // MSH.17
      msh.getCharacterSet(0).setValue("ASCII"); // MSH.18

      // MSA
      MSA msa = ack.getMSA();
      msa.getAcknowledgmentCode().setValue("AE"); // MSA.1
      msa.getMessageControlID().setValue("16d24ee0105d410ac724d616a5cc5"); // MSA.2

      // ERR
      ERR err = ack.getERR(0);
      err.getHL7ErrorCode().getIdentifier().setValue("207"); // ERR.3.1
      err.getHL7ErrorCode().getText().setValue("ERROR AL PROCESAR EL MENSAJE"); // ERR.3.2
      err.getSeverity().setValue("E"); // ERR.3.4
      err.getDiagnosticInformation().setValue("error pq no viene NHC"); // ERR.3.7

      logger.debug(ack.encode());
      Assert.assertTrue(true);
    } catch (DateUtilException due) {
      logger.error(due);
      Assert.fail(due.toString());
    } catch (IOException ioe) {
      logger.error(ioe);
      Assert.fail(ioe.toString());
    } catch (HL7Exception hl7e) {
      logger.error(hl7e);
      Assert.fail(hl7e.toString());
    }

    logger.info("     END generate()");
  }
 /**
  * Checks a group's children against a list of allowed structures for the group (ie those
  * mentioned in the profile with usage other than X). Returns a list of exceptions representing
  * structures that appear in the message but are not supposed to.
  */
 protected List<ValidationException> checkForExtraStructures(
     Group group, List<String> allowedStructures) {
   List<ValidationException> exList = new ArrayList<>();
   for (String childName : group.getNames()) {
     if (!allowedStructures.contains(childName)) {
       try {
         for (Structure rep : group.getAll(childName)) {
           profileViolatedWhen(!isEmpty(rep), exList, STRUCTURE_NOT_DEFINED_IN_PROFILE, childName);
         }
       } catch (HL7Exception he) {
         exList.add(new ValidationException("Problem checking profile:" + he.getMessage()));
       }
     }
   }
   return exList;
 }
示例#3
0
  @BeforeClass
  public static void before() {
    logger.info("INIT ACKTest");

    try {
      ACK = IOUtils.toString(ACKTest.class.getResource(ACK_ER7_V25));
      context = new DefaultHapiContext();
      logger.debug(context.getPipeParser().parse(ACK).printStructure());
      Assert.assertTrue(true);
    } catch (IOException ioe) {
      logger.error(ioe);
      Assert.fail(ioe.toString());
    } catch (HL7Exception hl7e) {
      logger.error(hl7e);
      Assert.fail(hl7e.toString());
    }
  }
示例#4
0
  @Test
  public void parse() {
    logger.info("     INIT parse()");

    try {
      ACK ack = (ACK) context.getPipeParser().parse(ACK);

      // ACK
      logger.debug("          [" + ack.getName() + "] (start)");

      // MSH
      logger.debug("               [" + ack.getMSH().getName() + "]: " + ack.getMSH().encode());

      // SFT
      List<SFT> listaSFT = ack.getSFTAll();
      if (listaSFT != null && !listaSFT.isEmpty()) {
        Iterator<SFT> iteratorSFT = listaSFT.iterator();
        while (iteratorSFT.hasNext()) {
          SFT sft = iteratorSFT.next();
          logger.debug("          [" + sft.getName() + "]: " + sft.encode());
        }
      }

      // MSA
      logger.debug("               [" + ack.getMSA().getName() + "]: " + ack.getMSA().encode());

      // ERR
      List<ERR> listaERR = ack.getERRAll();
      if (listaERR != null && !listaERR.isEmpty()) {
        Iterator<ERR> iteratorERR = listaERR.iterator();
        while (iteratorERR.hasNext()) {
          ERR err = iteratorERR.next();
          logger.debug("               [" + err.getName() + "]: " + err.encode());
        }
      }

      logger.debug("          [" + ack.getName() + "] (end)");

    } catch (HL7Exception hl7e) {
      logger.error(hl7e);
      Assert.fail(hl7e.toString());
    }

    logger.info("     END parse()");
  }
 /**
  * Checks a segment against a list of allowed fields (ie those mentioned in the profile with usage
  * other than X). Returns a list of exceptions representing field that appear but are not supposed
  * to.
  *
  * @param allowedFields an array of Integers containing field #s of allowed fields
  */
 protected List<ValidationException> checkForExtraFields(
     Segment segment, List<Integer> allowedFields) {
   ArrayList<ValidationException> exList = new ArrayList<>();
   for (int i = 1; i <= segment.numFields(); i++) {
     if (!allowedFields.contains(new Integer(i))) {
       try {
         Type[] reps = segment.getField(i);
         for (Type rep : reps) {
           profileViolatedWhen(
               !isEmpty(rep), exList, FIELD_NOT_DEFINED_IN_PROFILE, i, segment.getName());
         }
       } catch (HL7Exception he) {
         exList.add(
             new ValidationException("Problem testing against profile: " + he.getMessage()));
       }
     }
   }
   return exList;
 }