How to change HAPI verification rules for phone numbers?

In this example, the following dependencies are used from the maven central repository:

<!-- provides HAPI library --> <dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-base</artifactId> <version>2.2</version> </dependency> <!-- provides HAPI library message version --> <dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-structures-v22</artifactId> <version>2.2</version> </dependency> <!-- provides ByteString --> <dependency> <groupId>com.typesafe.akka</groupId> <artifactId>akka-actor_2.10</artifactId> <version>2.3.3</version> </dependency> 

Here is an example of my parsing code written in scala:

  import akka.util.ByteString import ca.uhn.hl7v2.model.Message import ca.uhn.hl7v2.model.v22.datatype.{CM_PAT_ID, ST, TN, TSComponentOne} import ca.uhn.hl7v2.model.v22.segment.{EVN, MRG, PID} import ca.uhn.hl7v2.parser.CanonicalModelClassFactory import ca.uhn.hl7v2.{DefaultHapiContext, ErrorCode, HL7Exception} lazy val parser = { val context = new DefaultHapiContext() context.setModelClassFactory(new CanonicalModelClassFactory("2.2")) context.getGenericParser } def parseHL7Message(message: ByteString) = Try[Message] { val msg: String = message.utf8String.trim parser.parse(msg) } 

This code can successfully parse the following HL7 message.

 "MSH|^~\\&|XXXX|S|XXXXXX|S|201410280931||ADT^A31|123456|P|2.2\r" + "EVN|A31|201410280930\r" + "PID|||9999999^^^S^MR~88888888^^^^PI||xxxx^xxxxxxxxx||11111111||||||(123)456-7890\r" + "PV1\r" 

However, when the message contains an added phone number, the hapi parser does not parse the message. Here is an example of an input message that I'm trying to parse with an extension in a phone number:

 "MSH|^~\\&|XXXX|S|XXXXXX|S|201410280931||ADT^A31|123456|P|2.2\r" + "EVN|A31|201410280930\r" + "PID|||9999999^^^S^MR~88888888^^^^PI||xxxx^xxxxxxxxx||11111111||||||(123)456-7890 1\r" + "PV1\r" 

When you try to parse this message, you receive the following error message:

ca.uhn.hl7v2.validation.ValidationException: validation failure: The primitive value '(123)456-7890 1' must be empty or American telephone number on PID-13

I read everything I could find in http://hl7api.sourceforge.net/index.html to find documentation on how to change the validation rules, but did not find anything useful.

An example will be rated most highly, but even pointing to the correct documentation, or a simple working draft example will be enough.

How can I configure the validation rules used by the HAPI parser to include a phone number extension in a valid US phone number in the PID-13 field?

EDIT

With a few searches, through this hapi developer mailing list, I figured out how to completely disable validation. Here is an example:

  lazy val parser = { val context = new DefaultHapiContext() context.setModelClassFactory(new CanonicalModelClassFactory("2.2")) context.setValidationContext(new NoValidation) context.getGenericParser } 

But if possible, I would like to continue checking messages. If I need to disable verification, I think this will work, but I would prefer to indicate that verification remains enabled, but these phone numbers may contain extensions.

+5
source share
2 answers

I have to work with a third-party service, and this service sends me invalid phones. Unfortunately, I cannot figure out how to do this as a "best practice." But I found one hack:

 @PostConstruct public void postConstruct() { List<RuleBinding<PrimitiveTypeRule>> rules = ((ValidationContextImpl)applicationRouter.getParser().getHapiContext().getValidationContext()).getPrimitiveRuleBindings(); //initially was published with this line, but think it was mistake //for(int i = rules.size() - 1; i > 0; i--) { for(int i = rules.size() - 1; i >= 0; i--) { RuleBinding<PrimitiveTypeRule> item = rules.get(i); if("TN".equals(item.getScope())){ rules.remove(i); } } } 

If someone finds out a better way to solve it, write.

+3
source

Phone numbers may contain extensions. The problem is that you have the extension in the wrong format. See HL7 Messaging Standard Version 2.2 , section 2.8.10.9. Phone numbers should be in the following format.

 [NN] [(999)]999-9999[X99999][B99999][C any text] 

Place the extension after the "X".

+2
source

Source: https://habr.com/ru/post/1205987/


All Articles