NCPDP SCRIPT is the messaging standard for e-prescribing in the United States, defined by the National Council for Prescription Drug Programs (NCPDP). It governs how new prescriptions (NewRx), renewal requests (RxRenewalRequest), and fill confirmations (RxFill) travel between prescribers, the Surescripts network, and retail or specialty pharmacies. This guide covers the complete Mirth Connect NCPDP SCRIPT 10.6 integration. See also our NCPDP to FHIR MedicationRequest gap analysis for the FHIR conversion layer.
NCPDP SCRIPT vs HL7 v2: What Changes in Mirth
NCPDP SCRIPT is XML-based, not the pipe-delimited HL7 v2 most Mirth engineers know. In Mirth, NCPDP channels use the XML data type, not HL7 v2. There is no built-in NCPDP parser — you navigate the message with E4X XPath using the NCPDP namespace http://www.ncpdp.org/schema/SCRIPT. The namespace declaration is mandatory, just like C-CDA — without it, every XPath returns empty string. For JavaScript transformer patterns used throughout this implementation, see our Mirth JavaScript transformer guide.
NewRx Message Parsing
// NCPDP namespace — required at top of every transformer
var ns = new Namespace('http://www.ncpdp.org/schema/SCRIPT');
default xml namespace = ns;
// Detect message type
var hasNewRx = msg['Body'][ns::('NewRx')].length() > 0;
var msgType = hasNewRx ? 'NewRx' : 'Other';
if (hasNewRx) {
var newRx = msg['Body'][ns::('NewRx')];
// Patient
var patFN = newRx[ns::('Patient')][ns::('Name')][ns::('FirstName')].toString();
var patLN = newRx[ns::('Patient')][ns::('Name')][ns::('LastName')].toString();
var patDOB= newRx[ns::('Patient')][ns::('DateOfBirth')].toString();
// Prescriber
var prescriberNPI = newRx[ns::('Prescriber')][ns::('Identification')][ns::('NPI')].toString();
var prescriberDEA = newRx[ns::('Prescriber')][ns::('Identification')][ns::('DEANumber')].toString();
// Medication
var drugName = newRx[ns::('MedicationPrescribed')][ns::('DrugDescription')].toString();
var ndc = newRx[ns::('MedicationPrescribed')][ns::('DrugCoded')][ns::('ProductCode')].toString();
var quantity = newRx[ns::('MedicationPrescribed')][ns::('Quantity')][ns::('Value')].toString();
var daysSupply = newRx[ns::('MedicationPrescribed')][ns::('DaysSupply')].toString();
var refills = newRx[ns::('MedicationPrescribed')][ns::('NumberOfRefills')].toString();
// Target pharmacy
var pharmacyNCPDP = newRx[ns::('Pharmacy')][ns::('Identification')][ns::('NCPDPID')].toString();
channelMap.put('pharmacy_id', pharmacyNCPDP);
}Surescripts Connectivity: Four Requirements
Surescripts requires four specific configurations in Mirth's HTTP Sender:
- Mutual TLS (mTLS) — Both client (Mirth) and server (Surescripts) present certificates. Configure Mirth keystore with your Surescripts-issued client certificate. Surescripts CA bundle goes in the Mirth truststore.
- SOAP 1.2 Envelope — NCPDP SCRIPT XML must be wrapped in a SOAP envelope. Set HTTP Sender Content-Type to
application/soap+xmland build the SOAP wrapper in the destination transformer. - 18-Second Timeout — Surescripts requires an HTTP 200 ACK within 20 seconds. Set Mirth HTTP Sender timeout to 18 seconds (2 seconds of buffer). Any downstream processing that takes longer must be offloaded to a downstream queued channel.
- Synchronous Mode — The Surescripts-facing channel must use synchronous HTTP response mode. Async patterns break the 20-second SLA requirement.
For the full Surescripts credentialing process and the certificate management setup in Mirth, see our Mirth Connect security guide.
RxRenewal Bidirectional Workflow
// RxRenewalRequest — pharmacy requests refill approval
if (msg['Body'][ns::('RxRenewalRequest')].length() > 0) {
var renewal = msg['Body'][ns::('RxRenewalRequest')];
var origRxId = renewal[ns::('RxReferenceNumber')].toString();
var prescriberNPI = renewal[ns::('Prescriber')][ns::('Identification')][ns::('NPI')].toString();
var pharmNCPDP = renewal[ns::('Pharmacy')][ns::('Identification')][ns::('NCPDPID')].toString();
channelMap.put('original_rx_id', origRxId);
channelMap.put('prescriber_npi', prescriberNPI);
// Route to prescriber EHR inbox for approval/denial
}The athenahealth integration guide covers the EHR routing for RxRenewal in ambulatory settings. For the eCR public health reporting connection — some e-prescribing systems also support controlled substance monitoring — see our eCR pipeline guide.
NCPDP Message Types Reference
- NewRx — New prescription from prescriber to pharmacy (most common)
- RxRenewalRequest — Pharmacy requests refill approval from prescriber
- RxRenewalResponse — Prescriber approves or denies renewal
- CancelRx — Prescriber cancels prescription before dispensing
- RxFill — Pharmacy confirms medication dispensed
- DrugUtilizationReview (DUR) — Drug interaction check response



