@Test
  public void testSerialization()
      throws EncodingNotSupportedException, HL7Exception, IOException, ClassNotFoundException {

    String message =
        "MSH|^~\\&|IRIS|SANTER|AMB_R|SANTER|200803051508||ADT^A03|263206|P|2.5\r"
            + "EVN||200803051509||||200803031508\r"
            + "PID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\r"
            + "PV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\r"
            + "PR1|1||1111^Mastoplastica|Protesi|20090224|02\r";

    Parser p = new NewPipeParser();
    Message parsed = p.parse(message);

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    new ObjectOutputStream(os).writeObject(parsed);

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(os.toByteArray()));
    Message deser = (Message) ois.readObject();

    String actual = p.encode(deser);

    System.out.println(message);
    System.out.println();
    System.out.println(actual);

    assertEquals(message, actual);
  }
  public static void main(String[] args) {

    int port = 8888;
    boolean useTls = false;
    HapiContext context = new DefaultHapiContext();
    String msg =
        "MSH|^~\\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01|12345|P|2.2\r"
            + "PID|0001|00009874|00001122|A00977|SMITH^JOHN^M|MOM|19581119|F|NOTREAL^LINDA^M|C|564 SPRING ST^^NEEDHAM^MA^02494^US|0002|(818)565-1551|(425)828-3344|E|S|C|0000444444|252-00-4414||||SA|||SA||||NONE|V1|0001|I|D.ER^50A^M110^01|ER|P00055|11B^M011^02|070615^BATMAN^GEORGE^L|555888^NOTREAL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^NOTREAL^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|199904101200||||5555112333|||666097^NOTREAL^MANNY^P\r"
            + "NK1|0222555|NOTREAL^JAMES^R|FA|STREET^OTHER STREET^CITY^ST^55566|(222)111-3333|(888)999-0000|||||||ORGANIZATION\r"
            + "PV1|0001|I|D.ER^1F^M950^01|ER|P000998|11B^M011^02|070615^BATMAN^GEORGE^L|555888^OKNEL^BOB^K^DR^MD|777889^NOTREAL^SAM^T^DR^MD^PHD|ER|D.WT^1A^M010^01|||ER|AMB|02|070615^VOICE^BILL^L|ER|000001916994|D||||||||||||||||GDD|WA|NORM|02|O|02|E.IN^02D^M090^01|E.IN^01D^M080^01|199904072124|199904101200|||||5555112333|||666097^DNOTREAL^MANNY^P\r"
            + "PV2|||0112^TESTING|55555^PATIENT IS NORMAL|NONE|||19990225|19990226|1|1|TESTING|555888^NOTREAL^BOB^K^DR^MD||||||||||PROD^003^099|02|ER||NONE|19990225|19990223|19990316|NONE\r"
            + "AL1||SEV|001^POLLEN\r"
            + "GT1||0222PL|NOTREAL^BOB^B||STREET^OTHER STREET^CITY^ST^77787|(444)999-3333|(222)777-5555||||MO|111-33-5555||||NOTREAL GILL N|STREET^OTHER STREET^CITY^ST^99999|(111)222-3333\r"
            + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
    try {
      Parser p = context.getPipeParser();
      Message adt = p.parse(msg);
      Connection connection = context.newClient("localhost", port, useTls);
      Initiator initiator = connection.getInitiator();
      Message response = initiator.sendAndReceive(adt);
      if (response != null) {
        String responseString = p.encode(response);
        System.out.println("Received response:\n" + responseString);
      } else System.out.println("Received response:\n No Response Received");

      connection.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  @Ignore
  @Test
  @DirtiesContext
  public void validHL7IsConvertedAndAckIsSent() throws Exception {
    standardHL7XMLEndpoint.expectedMessageCount(1);
    t5XMLEndpoint.expectedMessageCount(1);

    String hl7Input =
        "MSH|^~\\&|SendingApplication|SendingFacility|ReceivingApplication|ReceivingFacility|20120530112345||ORU^R01^ORU_R01|9879790003|P|2.6|||NE|AL|USA|ASCII|EN^English^ISO639||IHE_PCD_ORU_R01^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r"
            + "PID|||HO2009001^^^NIST^PI||Hon^Albert^^^^^L|Adams^^^^^^L|19610101|M|||15 N Saguaro^^Tucson^AZ^85701\r"
            + "PV1||I|ICU^2^23\r"
            + "OBR|1|||44616-1^Pulse oximetry panel ^LN|||20120512031234||||||||||||||||||F|||||||||||||||||||252465000^Pulse oximetry^SCT|7087005^Intermittent^SCT\r"
            + "NTE|1||This comment refers to all the results in the battery\r"
            + "OBX|1|NM|8889-8^Heart Rate by Oximetry^LN^149530^ MDC_PULS_OXIM_PULS_RATE^MDC|1.11.2.3|55|{beats}/min^beats per minute^UCUM|35-125||99||R|||20120530112340|||AMEAS^auto-measurement^MDC|0123456789ABCDEF^Pulse_Oximeter_Vendor_X^0123456789ABCDEF^EUI-64||49521004^left ear structure^SCT\n"
            + "NTE|1||This is a comment about pulse";

    Parser parser = new PipeParser();
    ORU_R01 originalMessage = (ORU_R01) parser.parse(hl7Input);
    String encodedHL7 = parser.encode(originalMessage);

    String response = minaTemplate.requestBody((Object) encodedHL7, String.class);

    ACK responseMessage = (ACK) parser.parse(response);

    assertEquals(
        AcknowledgmentCode.AA.name(), responseMessage.getMSA().getAcknowledgmentCode().getValue());

    standardHL7XMLEndpoint.assertIsSatisfied();
    t5XMLEndpoint.assertIsSatisfied();

    ORU_R01 outputStandardXMLMessage =
        (ORU_R01) parseXMLExchange(standardHL7XMLEndpoint.getReceivedExchanges().get(0));

    assertEquals(
        originalMessage.getMSH().getMessageType().getName(),
        outputStandardXMLMessage.getMSH().getMessageType().getName());
    assertEquals(
        originalMessage.getMSH().getMessageControlID().getValue(),
        outputStandardXMLMessage.getMSH().getMessageControlID().getValue());
  }
  /** Accumulates fragments and passes the "big" message to the processing route. */
  @Override
  public void process(Exchange exchange) throws Exception {
    String requestString = exchange.getIn().getBody(String.class);
    Parser parser = getEndpoint().getHl7v2TransactionConfiguration().getParser();
    Message requestMessage = parser.parse(requestString);
    Terser requestTerser = new Terser(requestMessage);
    String msh14 = requestTerser.get("MSH-14");
    String dsc1 = null;
    try {
      if (!"I".equals(requestTerser.get("DSC-2"))) {
        dsc1 = requestTerser.get("DSC-1");
      }
    } catch (HL7Exception e) {
      // segment DSC does not exist in cancel requests
    }

    // pass when the message is not fragmented
    if (isEmpty(msh14) && isEmpty(dsc1)) {
      getWrappedProcessor().process(exchange);
      return;
    }

    // get pieces of the accumulator's key
    String msh31 = requestTerser.get("MSH-3-1");
    String msh32 = requestTerser.get("MSH-3-2");
    String msh33 = requestTerser.get("MSH-3-3");

    // create an accumulator (on the arrival of the first fragment)
    // or get an existing one (on the arrival of fragments 2..n)
    StringBuilder accumulator;
    if (isEmpty(msh14)) {
      accumulator = new StringBuilder();
    } else {
      accumulator = storage.getAndRemove(keyString(msh14, msh31, msh32, msh33));
      if (accumulator == null) {
        LOG.warn("Pass unknown fragment with MSH-14=={} to the route", msh14);
        getWrappedProcessor().process(exchange);
        return;
      }
    }

    // append current fragment to the accumulator
    int beginIndex = isEmpty(msh14) ? 0 : requestString.indexOf('\r');
    int endIndex = isEmpty(dsc1) ? requestString.length() : (requestString.indexOf("\rDSC") + 1);
    accumulator.append(requestString, beginIndex, endIndex);

    // DSC-1 is empty -- finish accumulation, pass message to the marshaller
    if (isEmpty(dsc1)) {
      LOG.debug("Finished fragment chain {}", msh14);
      exchange.getIn().setBody(accumulator.toString());
      getWrappedProcessor().process(exchange);
      return;
    }

    // DSC-1 is not empty -- update accumulators map, request the next fragment
    LOG.debug("Processed fragment {} requesting {}", msh14, dsc1);

    storage.put(keyString(dsc1, msh31, msh32, msh33), accumulator);
    Message ack = MessageUtils.response(requestMessage, "ACK", requestTerser.get("MSH-9-2"));
    Terser ackTerser = new Terser(ack);
    ackTerser.set("MSA-1", "CA");
    ackTerser.set("MSA-2", requestTerser.get("MSH-10"));
    Exchanges.resultMessage(exchange).setBody(parser.encode(ack));
  }