diff --git a/README.md b/README.md index 5f885bf..5b7cbf9 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,13 @@ Send Rx requires user authentication method to work, so if your REDCap does not ## Customizing PDF and email messages The presented example can be fully adapted to your needs. You may freely create your own PDF template, change the email contents configuration, and override all forms/instruments (as soon as the fields containing `send_rx_` prefix remain untouched). All form fields you update/create will available to be used as wildcards on PDF and email (e.g. `[patient][first_name]`, `[site][send_rx_name]`, `[prescriber][first_name]`, etc). + +## Optional HL7 functionality + +This module also supports sending HL7 messages. This feature is only functional +when there is an external end-point that can convert JSON into hl7 and forward +that hl7 to a healthcare system and the [REDCapMirthConnectClient module](https://github.com/ctsit/redcap_mirth_client) is enabled on the patients project. To enable this feature go to the send_rx module +configuration menu on a patients project. Inside the end-point ID field enter "mirth_connect". Then configure the endpoint with the appropriate URL and authentication information. Finally, go +to a Site record in your Sites project and enable sending HL7 messages. After this +point whenever a prescriber hits the Send button for a patient in that site the JSON +provided earlier will be sent to that end-point. diff --git a/config.json b/config.json index c3e9ccb..a9ac22b 100644 --- a/config.json +++ b/config.json @@ -109,6 +109,16 @@ "type": "rich-text" } ] + }, + { + "key": "send-rx-hl7-settings", + "name": "HL7 settings", + "type": "descriptive" + }, + { + "key": "send-rx-hl7-json", + "name": "HL7 json message", + "type": "textarea" } ], "enable-every-page-hooks-on-system-pages": true, diff --git a/css/config.css b/css/config.css index bcebbe0..edff109 100644 --- a/css/config.css +++ b/css/config.css @@ -1,10 +1,5 @@ -.send-rx [field="send-rx-pdf-template"], -.send-rx [field="send-rx-pdf-template-variable"], -.send-rx [field="send-rx-pdf-template-variable-key"], -.send-rx [field="send-rx-pdf-template-variable-value"], -.send-rx [field="send-rx-message"], -.send-rx [field="send-rx-message-subject"], -.send-rx [field="send-rx-message-body"], -.send-rx [field="send-rx-hl7-schema"] { +.send-rx [field^="send-rx-pdf-template"], +.send-rx [field^="send-rx-message"], +.send-rx [field^="send-rx-hl7"] { display: none; } diff --git a/includes/RxSender.php b/includes/RxSender.php index 66ced68..8aff4fc 100644 --- a/includes/RxSender.php +++ b/includes/RxSender.php @@ -387,7 +387,19 @@ function send($generate_pdf = true, $log = true) { break; case 'hl7': - // TODO: handle HL7 messages. + //send json of hl7 message to mirth-connect + $payload = getHL7JsonPayload($this->siteProjectId); + $client = send_rx_generate_mirth_client('mirth_connect'); + + if(is_null($client)) { + $this->log($type, false, 'mirth_connect', 'POST', $payload); + } else { + $response = $client->request('POST', '', $payload); + + //log hl7 message that was sent + $success = !is_null($response) && $response->getStatusCode() == 200; + $this->log($type, $success, 'mirth_connect', 'POST', $payload); + } break; } } diff --git a/includes/send_rx_functions.php b/includes/send_rx_functions.php index 97b5e55..d3fc261 100644 --- a/includes/send_rx_functions.php +++ b/includes/send_rx_functions.php @@ -79,6 +79,27 @@ function send_rx_get_project_config($project_id, $project_type) { return $config; } +/** + * Get json payload for hl7 message + * + * @param int $project_id. + * The project id. + * + * @return string + * JSON formatted string that contains all of the data that must be sent + */ + function getHL7JsonPayload($project_id) { + $q = ExternalModules::getSettings('send_rx', $project_id, ['send-rx-hl7-json']); + if (!db_num_rows($q)) { + return false; + } + + $result = db_fetch_assoc($q); + + return $result['value']; + } + + /** * Gets site ID from DAG. * @@ -151,6 +172,21 @@ function send_rx_piping($subject, $data) { return $subject; } + +/** + * Generates a mirth client bound to the given endpoint. + * + * @param string $endpoint. + * Base url of the REST API being connected to. + * + * @return REDCapMithClient obj + * TRUE if success, FALSE otherwise. + */ +function send_rx_generate_mirth_client($endpoint_id) { + $client_module = ExternalModules::getModuleInstance('redcap_mirth_client', 'v1.0'); + return $client_module->getClient($endpoint_id); +} + /** * Generates a PDF file. * diff --git a/samples/SendRxSites.xml b/samples/SendRxSites.xml index fbc0ca8..f79a3a7 100644 --- a/samples/SendRxSites.xml +++ b/samples/SendRxSites.xml @@ -43,13 +43,13 @@ - + - + - + @@ -87,9 +87,9 @@ Delivery Methods - + Delivery Methods - + Delivery Methods @@ -99,9 +99,9 @@ Delivery Methods - + Delivery Methods - + Delivery Methods @@ -111,9 +111,9 @@ Delivery Methods - + Delivery Methods - + Delivery Methods @@ -149,39 +149,39 @@ Unverified Complete - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked