+
+
+
diff --git a/interface/cmsportal/list_requests.php b/interface/cmsportal/list_requests.php
new file mode 100644
index 000000000..66b4dcd0a
--- /dev/null
+++ b/interface/cmsportal/list_requests.php
@@ -0,0 +1,314 @@
+
+*
+* LICENSE: This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by the Free
+* Software Foundation; either version 2 of the License, or (at your option) any
+* later version.
+* This program is distributed in the hope that it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+* You should have received a copy of the GNU General Public License along with
+* this program. If not, see .
+*
+* @package OpenEMR
+* @author Rod Roark
+*/
+
+$sanitize_all_escapes = true;
+$fake_register_globals = false;
+
+require_once("../globals.php");
+require_once("$srcdir/log.inc");
+require_once("$srcdir/acl.inc");
+require_once("$srcdir/formdata.inc.php");
+require_once("$srcdir/options.inc.php");
+require_once("$srcdir/formatting.inc.php");
+require_once("portal.inc.php");
+
+/**
+ * Get a list item title, translating if required.
+ *
+ * @param string $listid List identifier.
+ * @param string $value List item identifier.
+ * @return string The item's title.
+ */
+function getListItem($listid, $value) {
+ $lrow = sqlQuery("SELECT title FROM list_options " .
+ "WHERE list_id = ? AND option_id = ?",
+ array($listid, $value));
+ $tmp = xl_list_label($lrow['title']);
+ if (empty($tmp)) $tmp = "($report_status)";
+ return $tmp;
+}
+
+/**
+ * Adapt text to be suitable as the contents of a table cell.
+ *
+ * @param string $s Input text.
+ * @return string Output text.
+ */
+function myCellText($s) {
+ if ($s === '') return ' ';
+ return text($s);
+}
+
+// Get patient name from OpenEMR, or empty if not there.
+function patientNameFromLogin($login) {
+ $ptname = '';
+ if ($login) {
+ $tmp = sqlQuery("SELECT fname, lname, mname, pid " .
+ "FROM patient_data WHERE cmsportal_login = ? ORDER BY id LIMIT 1",
+ array($login));
+ if (!empty($tmp['pid'])) {
+ $ptname = $tmp['lname'];
+ if ($tmp['fname'] || $tmp['mname']) $ptname .= ',';
+ if ($tmp['fname']) $ptname .= ' ' . $tmp['fname'];
+ if ($tmp['mname']) $ptname .= ' ' . $tmp['mname'];
+ }
+ }
+ return $ptname;
+}
+
+// Check authorization.
+$thisauth = acl_check('patients', 'med');
+if (!$thisauth) die(xlt('Not authorized'));
+
+$errmsg = '';
+
+// If Delete clicked, delete selected posts/messages from the portal.
+if (!empty($_POST['bn_delete'])) {
+ if (is_array($_POST['form_req_cb'])) {
+ foreach ($_POST['form_req_cb'] as $postid) {
+ $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
+ if ($result['errmsg']) {
+ die(text($result['errmsg']));
+ }
+ }
+ }
+ if (is_array($_POST['form_msg_cb'])) {
+ foreach ($_POST['form_msg_cb'] as $messageid) {
+ $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
+ if ($result['errmsg']) {
+ die(text($result['errmsg']));
+ }
+ }
+ }
+}
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/interface/cmsportal/patient_form.php b/interface/cmsportal/patient_form.php
new file mode 100644
index 000000000..0d66c10fc
--- /dev/null
+++ b/interface/cmsportal/patient_form.php
@@ -0,0 +1,318 @@
+
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see ;.
+ *
+ * @package OpenEMR
+ * @author Rod Roark
+ */
+
+$sanitize_all_escapes = true;
+$fake_register_globals = false;
+
+require_once("../globals.php");
+require_once("$srcdir/patient.inc");
+require_once("$srcdir/formdata.inc.php");
+require_once("$srcdir/options.inc.php");
+require_once("portal.inc.php");
+
+$postid = intval($_REQUEST['postid']);
+$ptid = intval($_REQUEST['ptid' ]);
+
+if ($_POST['bn_save']) {
+ $newdata = array();
+ $newdata['patient_data' ] = array();
+ $newdata['employer_data'] = array();
+ $ptid = intval($_POST['ptid']);
+ // Note we are careful to maintain cmsportal_login even if the layout has it
+ // configured as unused.
+ $fres = sqlStatement("SELECT * FROM layout_options WHERE " .
+ "form_id = 'DEM' AND field_id != '' AND (uor > 0 OR field_id = 'cmsportal_login') " .
+ "ORDER BY group_name, seq");
+ while ($frow = sqlFetchArray($fres)) {
+ $data_type = $frow['data_type'];
+ $field_id = $frow['field_id'];
+ $table = 'patient_data';
+ if (isset($_POST["form_$field_id"])) {
+ $newdata[$table][$field_id] = get_layout_form_value($frow);
+ }
+ }
+ if (empty($ptid)) {
+ $tmp = sqlQuery("SELECT MAX(pid)+1 AS pid FROM patient_data");
+ $ptid = empty($tmp['pid']) ? 1 : intval($tmp['pid']);
+ updatePatientData ($ptid, $newdata['patient_data' ], true);
+ updateEmployerData($ptid, $newdata['employer_data'], true);
+ newHistoryData($ptid);
+ }
+ else {
+ $newdata['patient_data']['id'] = $_POST['db_id'];
+ updatePatientData($ptid, $newdata['patient_data']);
+ }
+ // Finally, delete the request from the portal.
+ $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
+ if ($result['errmsg']) {
+ die(text($result['errmsg']));
+ }
+ echo "\n";
+ exit();
+}
+
+$db_id = 0;
+if ($ptid) {
+ $ptrow = getPatientData($ptid, "*");
+ $db_id = $ptrow['id'];
+}
+
+if ($postid) {
+ $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
+ if ($result['errmsg']) {
+ die(text($result['errmsg']));
+ }
+}
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/interface/cmsportal/patient_form_ajax.php b/interface/cmsportal/patient_form_ajax.php
new file mode 100644
index 000000000..15b205f4d
--- /dev/null
+++ b/interface/cmsportal/patient_form_ajax.php
@@ -0,0 +1,39 @@
+
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see ;.
+ *
+ * @package OpenEMR
+ * @author Rod Roark
+ */
+
+$sanitize_all_escapes = true;
+$fake_register_globals = false;
+
+require_once("../globals.php");
+require_once("$srcdir/formdata.inc.php");
+require_once("portal.inc.php");
+
+$result = cms_portal_call(array(
+ 'action' => 'adduser',
+ 'newlogin' => $_REQUEST['login'],
+ 'newpass' => $_REQUEST['pass'],
+ 'newemail' => $_REQUEST['email'],
+));
+
+if ($result['errmsg']) {
+ echo xl('Failed to add patient to portal') . ": " . $result['errmsg'];
+}
+?>
diff --git a/interface/cmsportal/patient_select.php b/interface/cmsportal/patient_select.php
new file mode 100644
index 000000000..972c4c1d4
--- /dev/null
+++ b/interface/cmsportal/patient_select.php
@@ -0,0 +1,224 @@
+;.
+ *
+ * @package OpenEMR
+ * @author Rod Roark
+ */
+
+$sanitize_all_escapes = true;
+$fake_register_globals = false;
+
+require_once("../globals.php");
+require_once("$srcdir/patient.inc");
+require_once("$srcdir/formdata.inc.php");
+require_once("$srcdir/options.inc.php");
+require_once("portal.inc.php");
+
+$postid = intval($_REQUEST['postid']);
+
+if ($postid) {
+ $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
+ if ($result['errmsg']) {
+ die(text($result['errmsg']));
+ }
+}
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/interface/cmsportal/portal.inc.php b/interface/cmsportal/portal.inc.php
new file mode 100644
index 000000000..a2240dea6
--- /dev/null
+++ b/interface/cmsportal/portal.inc.php
@@ -0,0 +1,98 @@
+
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see ;.
+ *
+ * @package OpenEMR
+ * @author Rod Roark
+ */
+
+// Note: In Ubuntu this requires the php5-curl package.
+// http://www.php.net/manual/en/function.curl-setopt.php has many comments and examples.
+
+if (!$GLOBALS['gbl_portal_cms_enable']) die(xlt('CMS Portal not enabled!'));
+
+function cms_portal_call($args) {
+ $portal_url = $GLOBALS['gbl_portal_cms_address'] . "/wp-content/plugins/sunset-patient-portal/webserve.php";
+ $args['login' ] = $GLOBALS['gbl_portal_cms_username'];
+ $args['password'] = $GLOBALS['gbl_portal_cms_password'];
+
+ if (($phandle = curl_init($portal_url)) === FALSE) {
+ die(text(xl('Unable to access URL') . " '$portal_url'"));
+ }
+ curl_setopt($phandle, CURLOPT_POST , TRUE);
+ curl_setopt($phandle, CURLOPT_RETURNTRANSFER, TRUE);
+ curl_setopt($phandle, CURLOPT_POSTFIELDS , $args);
+ if (($presult = curl_exec($phandle)) === FALSE) {
+ die(text(xl('curl_exec failed') . ': ' . curl_error($phandle)));
+ }
+ curl_close($phandle);
+ // With JSON-over-HTTP we would use json_decode($presult,TRUE) here.
+ return unserialize($presult);
+}
+
+// Look up the OpenEMR patient matching this request. More or less than 1 is an error.
+function lookup_openemr_patient($wp_login) {
+ if (empty($wp_login)) die(xlt('The patient was not logged in when submitting this form'));
+ $ptres = sqlStatement("SELECT pid FROM patient_data WHERE cmsportal_login = ?", array($wp_login));
+ if (sqlNumRows($ptres) < 1) die(xlt('There is no patient with portal login') . " '$wp_login'");
+ if (sqlNumRows($ptres) > 1) die(xlt('There are multiple patients with portal login') . " '$wp_login'");
+ $ptrow = sqlFetchArray($ptres);
+ return $ptrow['pid'];
+}
+
+// This constructs a LBF field value string from form data provided by the portal.
+//
+function cms_field_to_lbf($data_type, $field_id, &$fldarr) {
+ $newvalue = '';
+ if ($data_type == '23') {
+ // Type Exam Results is special, pieced together from multiple CMS fields.
+ // For example layout field "exams" might find CMS fields "exams:brs" = 1
+ // and "exams:cec" = 2 and aggregate them into the value "brs:1|cec:2".
+ foreach ($fldarr as $key => $value) {
+ if (preg_match('/^' . $field_id . ':(\w+)/', $key, $matches)) {
+ if ($newvalue !== '') $newvalue .= '|';
+ $newvalue .= $matches[1] . ":$value:";
+ }
+ }
+ }
+ else {
+ if (isset($fldarr[$field_id])) $newvalue = $fldarr[$field_id];
+ if ($newvalue !== '') {
+ // Lifestyle Status.
+ if ($data_type == '28') {
+ $newvalue = "|$newvalue$field_id|";
+ }
+ // Smoking Status.
+ else if ($data_type == '32') {
+ // See the smoking_status list for these array values:
+ $ssarr = array('current' => 1, 'quit' => 3, 'never' => 4, 'not_applicable' => 9);
+ $ssindex = isset($ssarr[$newvalue]) ? $ssarr[$newvalue] : 0;
+ $newvalue = "|$newvalue$field_id||$ssindex";
+ }
+ // Checkbox list.
+ else if (is_array($newvalue)) {
+ $tmp = '';
+ foreach ($newvalue as $value) {
+ if ($tmp !== '') $tmp .= '|';
+ $tmp .= $value;
+ }
+ $newvalue = $tmp;
+ }
+ }
+ }
+ return $newvalue;
+}
+?>
diff --git a/interface/cmsportal/upload_form.php b/interface/cmsportal/upload_form.php
new file mode 100644
index 000000000..4d8fd4904
--- /dev/null
+++ b/interface/cmsportal/upload_form.php
@@ -0,0 +1,206 @@
+
+ *
+ * LICENSE: This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see ;.
+ *
+ * @package OpenEMR
+ * @author Rod Roark
+ */
+
+$sanitize_all_escapes = true;
+$fake_register_globals = false;
+
+require_once("../globals.php");
+require_once("$srcdir/formdata.inc.php");
+require_once("$srcdir/classes/Document.class.php");
+require_once("portal.inc.php");
+
+// This function builds an array of document categories recursively.
+// Borrowed from interface/fax/fax_dispatch.php.
+//
+function getKittens($catid, $catstring, &$categories) {
+ $cres = sqlStatement("SELECT id, name FROM categories " .
+ "WHERE parent = ? ORDER BY name", array($catid));
+ $childcount = 0;
+ while ($crow = sqlFetchArray($cres)) {
+ ++$childcount;
+ getKittens($crow['id'], ($catstring ? "$catstring / " : "") .
+ ($catid ? $crow['name'] : ''), $categories);
+ }
+ // If no kitties, then this is a leaf node and should be listed.
+ if (!$childcount) $categories[$catid] = $catstring;
+}
+
+$postid = empty($_REQUEST['postid' ]) ? 0 : intval($_REQUEST['postid' ]);
+$messageid = empty($_REQUEST['messageid']) ? 0 : intval($_REQUEST['messageid']);
+
+if ($_POST['bn_save']) {
+ $ptid = intval($_POST['ptid']);
+ echo "\n";
+ if (is_array($_POST['form_filename'])) {
+ foreach ($_POST['form_filename'] as $uploadid => $filename) {
+ $catid = $_POST['form_category'][$uploadid];
+ if (!$catid) continue;
+ echo text(sprintf(xl('Fetching %s from portal...'), $filename)) . " \n";
+ flush();
+ if ($messageid) {
+ $result = cms_portal_call(array('action' => 'getmsgup', 'uploadid' => $uploadid));
+ }
+ else {
+ $result = cms_portal_call(array('action' => 'getupload', 'uploadid' => $uploadid));
+ }
+ if ($result['errmsg']) die(text($result['errmsg']));
+ $d = new Document();
+ // With JSON-over-HTTP we would need to base64_decode the contents.
+ $rc = $d->createDocument($ptid, $catid, $filename, $result['mimetype'],
+ $result['contents']);
+ if ($rc) die(text(xl('Error saving document') . ": $rc"));
+ }
+ }
+ // Finally, delete the request or message from the portal.
+ if ($messageid) {
+ $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
+ }
+ else {
+ $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
+ }
+ if ($result['errmsg']) {
+ die(text($result['errmsg']));
+ }
+ echo "\n";
+ exit();
+}
+
+// Get the document categories list.
+$categories = array();
+getKittens(0, '', $categories);
+
+// Get the portal request data.
+if (!$postid && !$messageid) die(xlt('Request ID is missing!'));
+if ($messageid) {
+ $result = cms_portal_call(array('action' => 'getmessage', 'messageid' => $messageid));
+}
+else {
+ $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
+}
+if ($result['errmsg']) {
+ die(text($result['errmsg']));
+}
+
+// Look up the patient in OpenEMR.
+$userlogin = $messageid ? $result['message']['user'] : $result['post']['user'];
+$ptid = lookup_openemr_patient($userlogin);
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\n";
+ echo "\n";
+ echo "
";
+ echo xlt('This message text is not saved automatically. Copy and save it as appropriate for the content.');
+ echo "