public static List<HL7Value> extractValues( Message message ) throws Exception { Terser terser = new Terser( message ); SegmentFinder finder = terser.getFinder(); List<HL7Value> values = new ArrayList<HL7Value>(); int childNr = 1; while ( finder.hasNextChild() ) { // next group in the message (MSH, PID, EVN and so on) // finder.nextChild(); Structure[] structures = finder.getCurrentChildReps(); for ( int i = 0; i < structures.length; i++ ) { Structure structure = structures[i]; parseStructure( values, message, terser, structure, Integer.toString( childNr ) ); } childNr++; } return values; }
public Object evaluate(Message msg) throws HL7Exception { return new Terser(msg).get(expression); }
public Object evaluate(Message msg) throws HL7Exception { return new Terser(msg).get(expression); }
private String[] getDeclaredProfileIDs(Message theMessage) throws HL7Exception { Terser t = new Terser(theMessage); boolean noMore = false; int c = 0; List<String> declaredProfiles = new ArrayList<String>(8); while (!noMore) { String path = "MSH-21(" + c++ + ")"; String idRep = t.get(path); //FIXME fails if empty rep precedes full rep ... should add getAll() to Terser and use that if (idRep == null || idRep.equals("")) { noMore = true; } else { declaredProfiles.add(idRep); } } return declaredProfiles.toArray(new String[declaredProfiles.size()]); }
private Map<String, Object> getMetadata(Message theMessage) throws HL7Exception { Map<String, Object> md = new HashMap<String, Object>(); Terser t = new Terser(theMessage); //snapshot so concurrent changes won't break our iteration String[] fields = getMetadataFields().toArray(new String[0]); for (int i = 0; i < fields.length; i++) { String field = fields[i].toString(); String val = t.get(field); md.put(field, val); } return md; }
/** * @param theMessage a message from which to extract fields * @param theTerserPaths a list of paths to desired fields, in the * form required by <code>Terser</code>. * @return a Map from Terser paths to field values */ public static Map<String, String> getFields(Message theMessage, List<String> theTerserPaths) throws HL7Exception { Map<String, String> fields = new HashMap<String, String>(); Terser terser = new Terser(theMessage); for (int i = 0; i < theTerserPaths.size(); i++) { String path = theTerserPaths.get(i); String fieldValue = terser.get(path); fields.put(path, fieldValue); } return fields; }
private String[] getDeclaredProfileIDs(Message theMessage) throws HL7Exception { Terser t = new Terser(theMessage); boolean noMore = false; int c = 0; List<String> declaredProfiles = new ArrayList<String>(8); while (!noMore) { String path = "MSH-21(" + c++ + ")"; String idRep = t.get(path); //FIXME fails if empty rep precedes full rep ... should add getAll() to Terser and use that if (idRep == null || idRep.equals("")) { noMore = true; } else { declaredProfiles.add(idRep); } } return declaredProfiles.toArray(new String[declaredProfiles.size()]); }
/** * @param theMessage a message from which to extract fields * @param theTerserPaths a list of paths to desired fields, in the * form required by <code>Terser</code>. * @return a Map from Terser paths to field values */ public static Map<String, String> getFields(Message theMessage, List<String> theTerserPaths) throws HL7Exception { Map<String, String> fields = new HashMap<String, String>(); Terser terser = new Terser(theMessage); for (int i = 0; i < theTerserPaths.size(); i++) { String path = theTerserPaths.get(i); String fieldValue = terser.get(path); fields.put(path, fieldValue); } return fields; }
private Map<String, Object> getMetadata(Message theMessage) throws HL7Exception { Map<String, Object> md = new HashMap<String, Object>(); Terser t = new Terser(theMessage); //snapshot so concurrent changes won't break our iteration String[] fields = getMetadataFields().toArray(new String[0]); for (int i = 0; i < fields.length; i++) { String field = fields[i].toString(); String val = t.get(field); md.put(field, val); } return md; }
public Location getLocation(Message msg) throws HL7Exception { Terser t = new Terser(msg); StringTokenizer tok = new StringTokenizer(expression, "-", false); Segment segment = t.getSegment(tok.nextToken()); Location location = new Location() .withSegmentName(segment.getName()) .withFieldIndizes(Terser.getIndices(expression)); return location; }
public Location getLocation(Message msg) throws HL7Exception { Terser t = new Terser(msg); StringTokenizer tok = new StringTokenizer(expression, "-", false); Segment segment = t.getSegment(tok.nextToken()); Location location = new Location() .withSegmentName(segment.getName()) .withFieldIndizes(Terser.getIndices(expression)); return location; }
/** * Performs transaction-specific acceptance test of the given response message. * * @param message {@link Message} object. */ public void checkResponseAcceptance(Message message) throws Hl7v2AcceptanceException { checkMessageAcceptance(message, false); try { if (!ArrayUtils.contains( new String[]{"AA", "AR", "AE", "CA", "CR", "CE"}, new Terser(message).get("MSA-1"))) { throw new Hl7v2AcceptanceException("Bad response: missing or invalid MSA segment", ErrorCode.REQUIRED_FIELD_MISSING); } } catch (HL7Exception e) { throw new Hl7v2AcceptanceException("Bad response: missing or invalid MSA segment", ErrorCode.APPLICATION_INTERNAL_ERROR); } }
/** * @see Validator#validate */ public HL7Exception[] validate(Message message, StaticDef profile) throws ProfileException, HL7Exception { List<HL7Exception> exList = new ArrayList<HL7Exception>(); Terser t = new Terser(message); checkMessageType(t.get("/MSH-9-1"), profile, exList); checkEventType(t.get("/MSH-9-2"), profile, exList); checkMessageStructure(t.get("/MSH-9-3"), profile, exList); exList.addAll(doTestGroup(message, profile, profile.getIdentifier(), validateChildren)); return exList.toArray(new HL7Exception[exList.size()]); }
/** * Finds out the exact profile inside the one specific IHETransaction * the given message belongs to. * * @param iheTransaction concrete IHETransaction * @param message hapi message * @return GazelleProfile that matches message type, event, structure & version * @throws HL7Exception */ public static ConformanceProfile guessGazelleProfile(HL7v2Transactions iheTransaction, Message message) throws HL7Exception { Terser terser = new Terser(message); for (ConformanceProfile conformanceProfile : iheTransaction.conformanceProfiles()) { if (matches(conformanceProfile.profileInfo(), terser)) { return conformanceProfile; } } return null; }
/** * @see Validator#validate */ public HL7Exception[] validate(Message message, StaticDef profile) throws ProfileException, HL7Exception { List<HL7Exception> exList = new ArrayList<HL7Exception>(); Terser t = new Terser(message); checkMessageType(t.get("/MSH-9-1"), profile, exList); checkEventType(t.get("/MSH-9-2"), profile, exList); checkMessageStructure(t.get("/MSH-9-3"), profile, exList); exList.addAll(doTestGroup(message, profile, profile.getIdentifier(), validateChildren)); return exList.toArray(new HL7Exception[exList.size()]); }
private void testMessageRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { Terser t = new Terser(message); String messageType = t.get("MSH-9-1"); String triggerEvent = t.get("MSH-9-2"); List<MessageRule> rules = new ArrayList<MessageRule>(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getMessageRules(message.getVersion(), messageType, triggerEvent)); } LOG.debug("Validating message against {} message rules", rules.size()); for (MessageRule rule : rules) { ValidationException[] ex = rule.apply(message); if (ex != null && ex.length > 0) { handler.onExceptions(ex); } } }
protected void applySuperStructureName(Message theMessage) throws HL7Exception { if (theMessage instanceof AbstractSuperMessage) { if (theMessage.getName() == null) { Terser t = new Terser(theMessage); String name = null; try { name = t.get("/MSH-9-3"); } catch (HL7Exception e) { // ignore } if (StringUtil.isBlank(name)) { name = t.get("/MSH-9-1") + "_" + t.get("/MSH-9-2"); } ((AbstractSuperMessage)theMessage).setName(name); } } }
/** * Returns the first Application that has been bound to messages of this type. */ private <T extends Message> ReceivingApplication<T> findApplication(T theMessage) throws HL7Exception { Terser t = new Terser(theMessage); AppRoutingData msgData = new AppRoutingDataImpl(t.get("/MSH-9-1"), t.get("/MSH-9-2"), t.get("/MSH-11-1"), t.get("/MSH-12")); ReceivingApplication<T> app = findDestination(theMessage, msgData); //have to send back an application reject if no apps available to process if (app == null) { app = (ReceivingApplication<T>)new DefaultApplication(); } return app; }
/** * Returns the first Application that has been bound to messages of this type. */ private <T extends Message> ReceivingApplication<T> findApplication(T theMessage) throws HL7Exception { Terser t = new Terser(theMessage); AppRoutingData msgData = new AppRoutingDataImpl(t.get("/MSH-9-1"), t.get("/MSH-9-2"), t.get("/MSH-11-1"), t.get("/MSH-12")); ReceivingApplication<T> app = findDestination(theMessage, msgData); //have to send back an application reject if no apps available to process if (app == null) { app = (ReceivingApplication<T>)new DefaultApplication(); } return app; }
protected void applySuperStructureName(Message theMessage) throws HL7Exception { if (theMessage instanceof AbstractSuperMessage) { if (theMessage.getName() == null) { Terser t = new Terser(theMessage); String name = null; try { name = t.get("/MSH-9-3"); } catch (HL7Exception e) { // ignore } if (StringUtil.isBlank(name)) { name = t.get("/MSH-9-1") + "_" + t.get("/MSH-9-2"); } ((AbstractSuperMessage)theMessage).setName(name); } } }