private static boolean isEmpty(final Visitable visitable) throws HL7Exception { return (visitable == null || visitable.isEmpty()); } }
@Override public String getName() { return segment.getName(); }
private static boolean isRepeating(final Segment segment) throws HL7Exception { if (isEmpty(segment)) { return false; } final Group parent = segment.getParent(); final Group grandparent = parent.getParent(); if (parent == grandparent) { return false; } return grandparent.isRepeating(parent.getName()); }
parser.setValidationContext( validationContext ); Message msg = parser.parse( message ); Message ack = msg.generateACK(); String ackMessage = ack.encode(); mod.getMSH().getSENDINGAPPLICATION().setValue( APPNAME ); mod.getMSH().getSENDINGFACILITY().setValue( APPNAME ); ackMessage = mod.encode(); } else if ( ack instanceof ca.uhn.hl7v2.model.v22.message.ACK ) { ca.uhn.hl7v2.model.v22.message.ACK mod = (ca.uhn.hl7v2.model.v22.message.ACK) ack; mod.getMSH().getSendingApplication().setValue( APPNAME ); mod.getMSH().getSendingFacility().setValue( APPNAME ); ackMessage = mod.encode(); } else if ( ack instanceof ca.uhn.hl7v2.model.v23.message.ACK ) { ca.uhn.hl7v2.model.v23.message.ACK mod = (ca.uhn.hl7v2.model.v23.message.ACK) ack; mod.getMSH().getSendingApplication().getNamespaceID().setValue( APPNAME ); mod.getMSH().getSendingFacility().getNamespaceID().setValue( APPNAME ); ackMessage = mod.encode(); } else if ( ack instanceof ca.uhn.hl7v2.model.v231.message.ACK ) { ca.uhn.hl7v2.model.v231.message.ACK mod = (ca.uhn.hl7v2.model.v231.message.ACK) ack; mod.getMSH().getSendingApplication().getNamespaceID().setValue( APPNAME ); mod.getMSH().getSendingFacility().getNamespaceID().setValue( APPNAME ); ackMessage = mod.encode(); } else if ( ack instanceof ca.uhn.hl7v2.model.v24.message.ACK ) { ca.uhn.hl7v2.model.v24.message.ACK mod = (ca.uhn.hl7v2.model.v24.message.ACK) ack; mod.getMSH().getSendingApplication().getNamespaceID().setValue( APPNAME ); mod.getMSH().getSendingFacility().getNamespaceID().setValue( APPNAME ); ackMessage = mod.encode();
String[] names = segment.getNames(); for ( int n = 1; n <= segment.numFields(); n++ ) { Type[] types = segment.getField( n ); for ( int t = 0; t < types.length; t++ ) { int nrComponents = Terser.numComponents( types[t] ); List<String> list = nameMap.get( types[t].getName() ); if ( list != null && c - 1 < list.size() ) { description = list.get( c - 1 ); Group group = structure.getParent(); Group rootGroup = structure.getMessage(); new HL7Value( message.getVersion(), rootGroup.getName(), group.getName(), structure.getName(), structureNumber, names[n - 1], coordinates, types[t].getName(), description, string ); values.add( value ); Group group = (Group) structure; String[] names = group.getNames(); Structure subStructure = group.get( name ); parseStructure( values, message, terser, subStructure, structureNumber + "." + n );
parser.setValidationContext( validationContext ); Message msg = parser.parse( message ); Structure structure = msg.get( "MSH" ); String messageType = null; String version = msg.getVersion(); messageType = ( (ca.uhn.hl7v2.model.v21.segment.MSH) structure ).getMESSAGETYPE().encode(); } else if ( structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v22.segment.MSH) structure ).getMessageType().encode(); } else if ( structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v23.segment.MSH) structure ).getMessageType().encode(); } else if ( structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v231.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v24.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v25.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v251.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else if ( structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH ) { messageType = ( (ca.uhn.hl7v2.model.v26.segment.MSH) structure ).getMessageType().getMessageStructure().getValue(); } else { logError( "This job entry does not support the HL7 dialect used. Found MSH class: "
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); }
private static void addSegments(final Group group, final Map<String, Segment> segments, final Map<String, Integer> segmentIndexes) throws HL7Exception { if (!isEmpty(group)) { for (final String name : group.getNames()) { for (final Structure structure : group.getAll(name)) { if (group.isGroup(name) && structure instanceof Group) { addSegments((Group) structure, segments, segmentIndexes); } else if (structure instanceof Segment) { addSegments((Segment) structure, segments, segmentIndexes); } } segmentIndexes.put(name, segmentIndexes.getOrDefault(name, 1) + 1); } } }
private static Map<String, Type> getAllFields(final String segmentKey, final Segment segment, final boolean useNames) throws HL7Exception { final Map<String, Type> fields = new TreeMap<>(); final String[] segmentNames = segment.getNames(); for (int i = 1; i <= segment.numFields(); i++) { final Type field = segment.getField(i, 0); if (!isEmpty(field)) { final String fieldName; if (useNames) { fieldName = WordUtils.capitalize(segmentNames[i-1]).replaceAll("\\W+", ""); } else { fieldName = String.valueOf(i); } final String fieldKey = new StringBuilder() .append(segmentKey) .append(".") .append(fieldName) .toString(); fields.put(fieldKey, field); } } return fields; }
public HapiSegment(final Segment segment) throws HL7Exception { this.segment = segment; final List<HL7Field> fieldList = new ArrayList<>(); for (int i = 1; i <= segment.numFields(); i++) { final Type[] types = segment.getField(i); if (types == null || types.length == 0) { fieldList.add(new EmptyField()); continue; } for (final Type type : types) { fieldList.add(new HapiField(type)); } } this.fields = Collections.unmodifiableList(fieldList); }
final Type[] types = ((Composite) field).getComponents(); for (int i = 0; i < types.length; i++) { final Type type = types[i]; if (!isEmpty(type)) { String fieldName = field.getName(); if (fieldName.equals("CM_MSG")) { fieldName = "CM";
@SuppressWarnings("unchecked") private static <T extends Structure> T unmodifiableStructure(T structure) { if (isUnmodifiable(structure)) return structure; if (structure instanceof Message) return (T) new UnmodifiableMessage((Message) structure); if (structure instanceof Group) return (T) new UnmodifiableGroup((Group) structure); return (T) new UnmodifiableSegment((Segment) structure); }
private static boolean isTimestamp(final Type field) throws HL7Exception { if (isEmpty(field)) { return false; } final String fieldName = field.getName(); return (fieldName.equals("TS") || fieldName.equals("DT") || fieldName.equals("TM")); }
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);
private void validate(Message message) throws HL7Exception { message.getVersion(); }
/** * Always returns true, assuming that the router calling this handler will only call this * handler with ADT_A28 messages. * * @return true */ @Override public boolean canProcess(Message message) { return message != null && "ADT_A28".equals(message.getName()); }
private void populateSegments(final Group group, final List<HL7Segment> segments) throws HL7Exception { for (final String structureName : group.getNames()) { final Structure[] structures = group.getAll(structureName); if (group.isGroup(structureName)) { for (final Structure structure : structures) { populateSegments((Group) structure, segments); } } else { for (final Structure structure : structures) { final Segment segment = (Segment) structure; final HapiSegment hapiSegment = new HapiSegment(segment); segments.add(hapiSegment); } } } }
private static void addSegments(final Segment segment, final Map<String, Segment> segments, final Map<String, Integer> segmentIndexes) throws HL7Exception { if (!isEmpty(segment)) { final String segmentName = segment.getName(); final StringBuilder sb = new StringBuilder().append(segmentName); if (isRepeating(segment)) { final int segmentIndex = segmentIndexes.getOrDefault(segmentName, 1); sb.append("_").append(segmentIndex); } final String segmentKey = sb.toString(); segments.put(segmentKey, segment); } }
/** * Always returns true, assuming that the router calling this handler will only call this * handler with ORU_R01 messages. * * @return true */ @Override public boolean canProcess(Message message) { return message != null && "ORU_R01".equals(message.getName()); }
/** * @see org.openmrs.hl7.HL7Service#processHL7Message(ca.uhn.hl7v2.model.Message) */ @Override public Message processHL7Message(Message message) throws HL7Exception { // Any post-parsing (pre-routing) processing would go here // or a module can use AOP to do the post-parsing Message response; try { if (!router.canProcess(message)) { throw new HL7Exception("No route for hl7 message: " + message.getName() + ". Make sure you have a module installed that registers a hl7handler for this type"); } response = router.processMessage(message); } catch (ApplicationException e) { throw new HL7Exception("Error while processing HL7 message: " + message.getName(), e); } return response; }