Recipes¶
Worked examples that combine QIE scripting bindings to solve specific integration problems. Each recipe is self-contained. Copy the snippet into a mapping node, adjust the node paths or table lookups to match your interface, and adapt as needed.
Recipes are not a replacement for the JavaScript Tutorial (which teaches the language) or the Code Wizard reference (which documents every binding). Use the tutorial to learn the syntax, use the Code Wizard for function-by-function lookup, and come here when you want to see how the pieces fit together for a real problem.
Sources¶
Receiver-side patterns: response handling, preprocessing, and pulling messages from atypical inbound protocols.
- Ingesting Empty Files. Replace the File source with a Custom Script Receiver so zero-byte files still enter the channel for "file arrived" workflows.
- Polling SFTP from a Custom Script Receiver. List, download, and create one inbound message per data row from an SFTP folder, including the
listSFTPEndpointleaf-name gotcha. - Unwrapping a Vendor Envelope from an HTTP Body. Peel off a partner-defined XML wrapper (e.g.
/Request/Part/Contentwith optional base64) in the HTTP Listener preprocess script so downstream scripts see only the real payload. - Validating an Inbound Bearer Token. Reject unauthorized HTTP Listener requests in a preprocessor script before they enter the channel.
- Building an ASTM ACK with a Mod-256 Checksum. Compute the ASTM mod-256 checksum in JavaScript and return a framed response via
qie.postMessageResponsefrom a Socket (ASTM) Receiver. - Acknowledging Receipt Before Processing. Return a fast ACK from the acknowledgement script so the client is released as soon as QIE has the bytes, then keep processing the message in the channel.
- Routing Multiple REST Endpoints on One HTTP Listener. Serve a whole REST API from one channel: parse the method and path once into a route key, then use a condition node per endpoint to dispatch.
Destinations¶
Sender-side patterns: shaping outbound requests and reading richer responses back.
- Posting multipart/form-data from a Script. Build a multipart REST request with file and text parts, including the DICOM-as-Part-10-file gotcha for
.dcmuploads. - Sending a CDA Document to an HIE. Submit a CDA via IHE ITI-41 (XDS.b / XDR), including the IHE Web Service Connection, XDS.b metadata, and the ack script that surfaces HIE
RegistryErrorresponses. - Reading REST Response Headers. Call
qie.callRESTWebServicewithreturnFullHttpResponse=trueto read HTTP status, headers, and body from the response envelope.
Message Types¶
Format-specific transforms and composition. Recipes are filed under the format the reader is transforming from. Someone who has HL7 data and wants JSON out looks under HL7.
HL7¶
- Handling HL7 Base64 Attachments. Offload Base64 OBX-5 payloads to disk, replace with a reference, and re-embed at the destination when needed.
- Converting Repeating HL7 Segments to a JSON Array, one JSON array element per ORC/OBR/OBX repetition using
qie.parseJSONStringandaddObjectToJSONArray. - Converting HL7 to JSON with a Template. Hold the JSON body as a System Variable (or inline), embed
{PID-3.1}-style node tags, and render withqie.evaluateTemplate.
JSON¶
- Converting a JSON Array to Repeating HL7 Segments. Iterate a JSON array in a mapping script and add one HL7 segment per element (SIU with one AIS per slot, ORM with one OBX per observation).
- Converting a JSON Array to a CSV Message. Build a flat CSV with
qie.createCSVMessage, taking column headers from the JSON object keys and one row per array element. - Converting JSON to HL7 with a Template. Hold an HL7 template as a System Variable with
{alt:/json/path}tags and render it against a JSON source withqie.evaluateTemplate. - Loading JSON into messageCache. Mirror a JSON source's top-level fields into
messageCacheso downstream nodes can read them by name without re-parsing.
CSV¶
- Reading a CSV Message: the
getRowCount/getHeaders/getRowsAPI, iterating rows by name or index, building a per-row JS object, and CSV System Variable lookups withqie.doTableLookup. - Converting a CSV Message to JSON with a Template: hold a JSON body as a System Variable with
{ColumnName}node tags and render it against the first CSV data row withqie.evaluateTemplate.
XML¶
- Composing XML Messages from Fragments. Graft parsed XML fragments together with
addChildMessageinstead of templating one large string.
General¶
Patterns that work across formats.
- Building a New Output Message. Rebuild a message in a different format or shape: ORU to MDM, repeating segments, and an XML document from a database query.
- Splitting One Message into Many. Emit one outbound message per ORC group with
qie.spawnNewMessage, or wrap the records in a single BHS/BTS batch. - Unpacking a Packed Delimited Field. Split a field that packs several values, e.g. CPT codes with descriptions, where the delimiter also appears inside the data.
Files & Large Data¶
Streaming to disk, binary output, and archive handling.
- Writing Binary Files from a Script. Drop a PDF, image, or ZIP to disk from a mapping script using
qie.writeFile, with the original message left intact. - Passing Through Large Files Without Loading Them Into Memory. Stream multi-GB files to disk on FTP, File, or Network Share sources, then move them with
qie.moveFileor upload withqie.writeFTPFile*without touching the JVM heap. - Handling Large DICOM Images. Keep multi-gigabyte instances out of the JVM heap with source-node pixel separation, and stream the complete file from a script with
message.writeDICOMToFilewhen a REST upload needs it. - Extracting a tar.gz / tgz Archive. Untar gzipped tarballs from a script using QIE's bundled Apache Commons Compress library.
Database¶
Parameterized queries and bulk-load patterns.
- Parameterized Database Queries. Bind message values safely with named parameters for select, existence, and insert/update queries.
- Batching SQL INSERTs for Performance. Group source rows and emit one multi-row INSERT to cut per-row database round-trips.
- Purging Old Rows from an External Table on a Schedule. Delete aged rows in batches from a Scheduled Script, with a dry-run count and the foreign-key filter that keeps the loop moving.
Channel Operations¶
Scheduled-script patterns that manage the channel itself rather than any one message.
- Automating Error Queue Remediation with Scheduled Scripts. Walk the channel's error queue from a Scheduled Script, retrying, fixing-and-replaying, or discarding messages programmatically via the
errorManagerbinding. - Rate-Limiting Channel Throughput from Scheduled Scripts. Pause a channel from a scheduled script when it has reached a per-period message cap and resume it at the start of the next period.