final String componentKey = componentEntry.getKey(); final Type component = componentEntry.getValue(); final String componentValue = HL7_ESCAPING.unescape(component.encode(), HL7_ENCODING); if (!StringUtils.isEmpty(componentValue)) { attributes.put(componentKey, componentValue); final String fieldValue = HL7_ESCAPING.unescape(field.encode(), HL7_ENCODING); if (!StringUtils.isEmpty(fieldValue)) { attributes.put(fieldKey, fieldValue);
public HapiField(final Type type) { this.value = PipeParser.encode(type, EncodingCharacters.defaultInstance()); final List<HL7Component> componentList = new ArrayList<>(); if (type instanceof Composite) { final Composite composite = (Composite) type; for (final Type component : composite.getComponents()) { componentList.add(new HapiField(component)); } } final ExtraComponents extra = type.getExtraComponents(); if (extra != null && extra.numComponents() > 0) { final String singleFieldValue; if (type instanceof Primitive) { singleFieldValue = ((Primitive) type).getValue(); } else { singleFieldValue = this.value; } componentList.add(new SingleValueField(singleFieldValue)); for (int i = 0; i < extra.numComponents(); i++) { componentList.add(new HapiField(extra.getComponent(i))); } } this.components = Collections.unmodifiableList(componentList); }
final HapiContext hapiContext = new DefaultHapiContext(); if (!inputVersion.equals("autodetect")) { hapiContext.setModelClassFactory(new CanonicalModelClassFactory(inputVersion)); final String hl7Text = new String(buffer, charset); try { final Message message = parser.parse(hl7Text); final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields); flowFile = session.putAllAttributes(flowFile, attributes);
meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); data.parser = new GenericParser(); data.parser.setValidationContext( new NoValidation() ); Message message = data.parser.parse( messageString ); List<HL7Value> values = HL7KettleParser.extractValues( message );
/** * @see org.openmrs.hl7.HL7Service#parseHL7String(String) */ @Override public Message parseHL7String(String hl7Message) throws HL7Exception { // Any pre-parsing for HL7 messages would go here // or a module can use AOP to pre-parse the message // First, try and parse the message Message message; try { message = parser.parse(hl7Message); } catch (EncodingNotSupportedException e) { throw new HL7Exception("HL7 encoding not supported", e); } catch (HL7Exception e) { throw new HL7Exception("Error parsing message", e); } return message; }
final HL7Message message; try { final Message hapiMessage = parser.parse(hl7Text); message = new HapiMessage(hapiMessage); } catch (final Exception e) {
Parser parser = new GenericParser(); ValidationContext validationContext = new NoValidation(); parser.setValidationContext( validationContext ); Message msg = parser.parse( message ); Structure structure = msg.get( "MSH" ); String messageType = null;
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailOnEmptyConceptAnswers() throws Exception { String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080630094800||ORU^R01|kgWdFt0SVwwClOfJm3pe|P|2.5|1||||||||15^AMRS.ELD.FORMID\r" + "PID|||3^^^^~d3811480^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20080208|||||||V\r" + "ORC|RE||||||||20080208000000|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|CWE|5497^CD4, BY FACS^99DCT||^^99DCT|||||||||20080208"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }
Parser parser = new GenericParser(); ValidationContext validationContext = new NoValidation(); parser.setValidationContext( validationContext ); Message msg = parser.parse( message ); Message ack = msg.generateACK();
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailOnEmptyConceptProposals() throws Exception { String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080630094800||ORU^R01|kgWdFt0SVwwClOfJm3pe|P|2.5|1||||||||15^AMRS.ELD.FORMID\r" + "PID|||3^^^^~d3811480^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20080208|||||||V\r" + "ORC|RE||||||||20080208000000|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBR|1|||1284^PROBLEM LIST^99DCT\r" + "OBX|1|CWE|6042^PROBLEM ADDED^99DCT||PROPOSED^^99DCT|||||||||20080208"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailIfTheProviderNameTypeCodeIsNotSpecifiedAndIsNotAPersonId() throws Exception { int patientId = 2; String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||" + patientId + "^^^^||Hornblower^Horatio^Test||\r" + "PV1||O|1^Unknown Location||||Test^Super User (1-8)^^^^^^^&" + HL7Constants.PROVIDER_ASSIGNING_AUTH_IDENTIFIER + "&^|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }
/** * @see ORUR01Handler#processNK1(Patient,NK1) */ @Test(expected = HL7Exception.class) public void processNK1_shouldFailIfTheCodingSystemIsNot99REL() throws Exception { // process a message with an invalid coding system Patient patient = new Patient(3); // the patient that is the focus of // this hl7 message String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^ACKFOO||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714"; ORUR01Handler oruHandler = new ORUR01Handler(); Message hl7message = parser.parse(hl7String); ORU_R01 oru = (ORU_R01) hl7message; List<NK1> nk1List = oruHandler.getNK1List(oru); for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1); }
/** * @see ORUR01Handler#processNK1(Patient,NK1) */ @Test(expected = HL7Exception.class) public void processNK1_shouldFailIfTheRelationshipIdentifierIsFormattedImproperly() throws Exception { // process a message with an invalid relationship identifier format Patient patient = new Patient(3); // the patient that is the focus of // this hl7 message String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3C^Parent^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714"; ORUR01Handler oruHandler = new ORUR01Handler(); Message hl7message = parser.parse(hl7String); ORU_R01 oru = (ORU_R01) hl7message; List<NK1> nk1List = oruHandler.getNK1List(oru); for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1); }
/** * @see ORUR01Handler#processNK1(Patient,NK1) */ @Test(expected = HL7Exception.class) public void processNK1_shouldFailIfTheRelationshipTypeIsNotFound() throws Exception { // process a message with a non-existent relationship type Patient patient = new Patient(3); // the patient that is the focus of // this hl7 message String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3952A^Fifth Cousin Twice Removed^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714"; ORUR01Handler oruHandler = new ORUR01Handler(); Message hl7message = parser.parse(hl7String); ORU_R01 oru = (ORU_R01) hl7message; List<NK1> nk1List = oruHandler.getNK1List(oru); for (NK1 nk1 : nk1List) oruHandler.processNK1(patient, nk1); }
/** * @see ORUR01Handler#getForm(MSH) */ @Test public void getForm_shouldPassIfReturnValueIsNullWhenUuidAndIdIsNull() throws Exception { String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714"; ORUR01Handler oruHandler = new ORUR01Handler(); Message hl7message = parser.parse(hl7String); ORU_R01 oru = (ORU_R01) hl7message; ca.uhn.hl7v2.model.v25.segment.MSH msh = oru.getMSH(); Form form = oruHandler.getForm(msh); Assert.assertNull(form); }
/** * @see ORUR01Handler#getForm(MSH) */ @Test public void getForm_shouldPassIfReturnValueIsNotNullWhenUuidOrIdIsNotNull() throws Exception { String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714"; ORUR01Handler oruHandler = new ORUR01Handler(); Message hl7message = parser.parse(hl7String); ORU_R01 oru = (ORU_R01) hl7message; ca.uhn.hl7v2.model.v25.segment.MSH msh = oru.getMSH(); Form form = oruHandler.getForm(msh); Assert.assertNotNull(form); } }
/** * Should create a concept proposal because of the key string in the message * * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldCreateConceptProposalAndWithObsAlongside() throws Exception { // remember initial occurrence of proposal's text in the model int initialOccurrences = Context.getConceptService().getConceptProposals("ASDFASDFASDF").size(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20081006115934||ORU^R01|a1NZBpKqu54QyrWBEUKf|P|2.5|1||||||||3^AMRS.ELD.FORMID\r" + "PID|||7^^^^~asdf^^^^||Joe^ ^Smith||\r" + "PV1||O|1^Bishop Muge||||1^asdf asdf (5-9)|||||||||||||||||||||||||||||||||||||20081003|||||||V\r" + "ORC|RE||||||||20081006115645|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20081004|||||||||20081003\r" + "OBR|3|||1284^PROBLEM LIST^99DCT\r" + "OBX|2|CWE|6042^PROBLEM ADDED^99DCT||PROPOSED^ASDFASDFASDF^99DCT|||||||||20081003"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); //make sure that the proposal was added Assert.assertEquals("Processing of the HL7 message did not result in the new proposal being added to the model", initialOccurrences + 1, Context.getConceptService().getConceptProposals("ASDFASDFASDF").size()); }
/** * Should create a concept proposal because of the key string in the message * * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldCreateBasicConceptProposal() throws Exception { // remember initial occurrence of proposal's text in the model int initialOccurrences = Context.getConceptService().getConceptProposals("PELVIC MASS").size(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080924022306||ORU^R01|Z185fTD0YozQ5kvQZD7i|P|2.5|1||||||||3^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Joe^S^Mith||\r" + "PV1||O|1^Unknown Module 2||||1^Joe (1-1)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080219085345|1^Joe\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|18|DT|5096^RETURN VISIT DATE^99DCT||20080506|||||||||20080212\r" + "OBR|19|||1284^PROBLEM LIST^99DCT\r" + "OBX|1|CWE|6042^PROBLEM ADDED^99DCT||PROPOSED^PELVIC MASS^99DCT|||||||||20080212"; Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); //make sure that the proposal was added Assert.assertEquals("Processing of the HL7 message did not result in the new proposal being added to the model", initialOccurrences + 1, Context.getConceptService().getConceptProposals("PELVIC MASS").size()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailIfQuestionDatatypeIsNeitherBooleanNorNumericNorCoded() throws Exception { String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|19^FAVORITE FOOD, NON-CODED^99DCT||1|||||||||20080206"; Assert.assertEquals("Text", Context.getConceptService().getConcept(19).getDatatype().getName()); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test(expected = ApplicationException.class) public void processMessage_shouldFailIfQuestionDatatypeIsCodedAndABooleanIsNotAValidAnswer() throws Exception { GlobalProperty trueConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_TRUE_CONCEPT, "7", "Concept id of the concept defining the TRUE boolean concept"); GlobalProperty falseConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FALSE_CONCEPT, "8", "Concept id of the concept defining the TRUE boolean concept"); Context.getAdministrationService().saveGlobalProperty(trueConceptGlobalProperty); Context.getAdministrationService().saveGlobalProperty(falseConceptGlobalProperty); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|4^CIVIL STATUS^99DCT||1|||||||||20080206"; Assert.assertEquals("Coded", Context.getConceptService().getConcept(4).getDatatype().getName()); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); }