Hi, sorry for bothering you. I have found it now in the specification: http://www.openehealth.org/display/ipf2/Primitive+Type+Constraints
There is this note: --When primitive type rules are checked-- Note that primitive type rules can only be applied by configuring the parser. Validation then is executed whenever a primitive value is set: * during parsing * when individual fields are modified afterwards, e.g. by while using a transmogrifier. Thanks and sorry for interruption. :) Martin Swiech ----- Original Message ----- From: "Martin Swiech" <mswi...@redhat.com> To: hl7api-devel@lists.sourceforge.net Sent: Tuesday, March 31, 2015 1:44:19 PM Subject: [HAPI-devel] validation while encoding vs. primitive type validation rules (primitiveRules) 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 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Hl7api-devel mailing list Hl7api-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hl7api-devel ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Hl7api-devel mailing list Hl7api-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hl7api-devel