From: Martin S. <ms...@re...> - 2015-03-31 11:44:28
|
Hi, I have a question about validating HL7 message with invalid value in primitive type. Example: I am creating HL7 message with invalid telephone number (TN): private Message createInvalidMessageObj() throws IOException, HL7Exception { final ADT_A01 adt = new ADT_A01(); adt.initQuickstart("ADT", "A01", "P"); final MSH mshSegment = adt.getMSH(); mshSegment.getSendingApplication().getNamespaceID().setValue("TestSendingSystem"); mshSegment.getSequenceNumber().setValue("11"); final PID pid = adt.getPID(); pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe"); pid.getPatientName(0).getGivenName().setValue("John"); pid.getPatientIdentifierList(0).getID().setValue("123456"); pid.getPhoneNumberHome(0).get9999999X99999CAnyText().setValue("00420999"); // phoneNumber should be US telephone number (TN) return adt; } And I will create Parser with DefaultValidation() (default ValidationContext): final HapiContext hapiContext = new DefaultHapiContext(); hapiContext.setValidationContext(new DefaultValidation()); final Parser parser = hapiContext.getPipeParser(); Parsing of that message will throw an exception and it's OK, because it's not valid message: final String invalidMsgStr = createInvalidMessageObj().toString(); try { parser.parse(invalidMsgStr); Assert.fail("DataTypeException expected"); } catch (DataTypeException e) { Assert.assertTrue(e.getCause() instanceof ValidationException); } But when I am trying to encode that invalid Message object to String (using the parser with default ValidationContext), no exception is thrown: try { parser.encode(createInvalidMessageObj()); Assert.fail("exception expected"); } catch (Exception e) { //expected } Why the primitive rules are not checked when HL7 message is encoded by parser from Message object to String? Isn't it bug? Thanks. Martin Swiech |