Allows display of appointments in descending order, take 2.
[openemr.git] / interface / cmsportal / portal.inc.php
bloba2240dea65104acd67f4828da80c1ef988857c8a
1 <?php
2 /**
3 * Remote access to a WordPress Patient Portal.
5 * Copyright (C) 2014 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
22 // Note: In Ubuntu this requires the php5-curl package.
23 // http://www.php.net/manual/en/function.curl-setopt.php has many comments and examples.
25 if (!$GLOBALS['gbl_portal_cms_enable']) die(xlt('CMS Portal not enabled!'));
27 function cms_portal_call($args) {
28 $portal_url = $GLOBALS['gbl_portal_cms_address'] . "/wp-content/plugins/sunset-patient-portal/webserve.php";
29 $args['login' ] = $GLOBALS['gbl_portal_cms_username'];
30 $args['password'] = $GLOBALS['gbl_portal_cms_password'];
32 if (($phandle = curl_init($portal_url)) === FALSE) {
33 die(text(xl('Unable to access URL') . " '$portal_url'"));
35 curl_setopt($phandle, CURLOPT_POST , TRUE);
36 curl_setopt($phandle, CURLOPT_RETURNTRANSFER, TRUE);
37 curl_setopt($phandle, CURLOPT_POSTFIELDS , $args);
38 if (($presult = curl_exec($phandle)) === FALSE) {
39 die(text(xl('curl_exec failed') . ': ' . curl_error($phandle)));
41 curl_close($phandle);
42 // With JSON-over-HTTP we would use json_decode($presult,TRUE) here.
43 return unserialize($presult);
46 // Look up the OpenEMR patient matching this request. More or less than 1 is an error.
47 function lookup_openemr_patient($wp_login) {
48 if (empty($wp_login)) die(xlt('The patient was not logged in when submitting this form'));
49 $ptres = sqlStatement("SELECT pid FROM patient_data WHERE cmsportal_login = ?", array($wp_login));
50 if (sqlNumRows($ptres) < 1) die(xlt('There is no patient with portal login') . " '$wp_login'");
51 if (sqlNumRows($ptres) > 1) die(xlt('There are multiple patients with portal login') . " '$wp_login'");
52 $ptrow = sqlFetchArray($ptres);
53 return $ptrow['pid'];
56 // This constructs a LBF field value string from form data provided by the portal.
58 function cms_field_to_lbf($data_type, $field_id, &$fldarr) {
59 $newvalue = '';
60 if ($data_type == '23') {
61 // Type Exam Results is special, pieced together from multiple CMS fields.
62 // For example layout field "exams" might find CMS fields "exams:brs" = 1
63 // and "exams:cec" = 2 and aggregate them into the value "brs:1|cec:2".
64 foreach ($fldarr as $key => $value) {
65 if (preg_match('/^' . $field_id . ':(\w+)/', $key, $matches)) {
66 if ($newvalue !== '') $newvalue .= '|';
67 $newvalue .= $matches[1] . ":$value:";
71 else {
72 if (isset($fldarr[$field_id])) $newvalue = $fldarr[$field_id];
73 if ($newvalue !== '') {
74 // Lifestyle Status.
75 if ($data_type == '28') {
76 $newvalue = "|$newvalue$field_id|";
78 // Smoking Status.
79 else if ($data_type == '32') {
80 // See the smoking_status list for these array values:
81 $ssarr = array('current' => 1, 'quit' => 3, 'never' => 4, 'not_applicable' => 9);
82 $ssindex = isset($ssarr[$newvalue]) ? $ssarr[$newvalue] : 0;
83 $newvalue = "|$newvalue$field_id||$ssindex";
85 // Checkbox list.
86 else if (is_array($newvalue)) {
87 $tmp = '';
88 foreach ($newvalue as $value) {
89 if ($tmp !== '') $tmp .= '|';
90 $tmp .= $value;
92 $newvalue = $tmp;
96 return $newvalue;