Esempio n. 1
0
 function ProcessData($data)
 {
     $cache = freemed::module_cache();
     // Handle "module:" prefix
     if (substr($data['table'], 0, 7) == 'object:') {
         $objectname = substr($data['table'], -(strlen($data['table']) - 7));
         $params = explode(':', $data['field']);
         if ($params[0] == 'patient') {
             $obj = CreateObject('org.freemedsoftware.core.' . $objectname, $this->patient->local_record[$params[1]]);
             $method = $params[2] ? $params[2] : 'to_text';
             $raw = $obj->{${method}}();
         } else {
             syslog(LOG_INFO, get_class($this) . "| could not process {$data['table']}, {$data['field']}");
             return '';
         }
     } elseif (substr($data['table'], 0, 7) == 'module:') {
         $modulename = substr($data['table'], -(strlen($data['table']) - 7));
         // Deal with method: prefix on data
         if (substr($data['field'], 0, 7) == 'method:') {
             $params = explode(':', $data['field']);
             $raw = module_function($modulename, $params[1], array($params[2] ? $params[2] : $this->patient->id));
         } else {
             // Load information from module
             include_once resolve_module($modulename);
             $m = new $modulename();
             // Run SQL query
             $query = "SELECT *" . (count($m->summary_query) > 0 ? "," . join(",", $m->summary_query) . " " : " ") . "FROM " . $m->table_name . " " . "WHERE " . $m->patient_field . "='" . addslashes($this->patient->id) . "' " . ($m->summary_conditional ? 'AND ' . $m->summary_conditional . ' ' : '') . "ORDER BY id DESC LIMIT 1";
             $result = $GLOBALS['sql']->query($query);
             if ($GLOBALS['sql']->num_rows($result) != 1) {
                 syslog(LOG_INFO, get_class($this) . "| could not retrieve rows for {$data['table']}, {$data['field']}");
                 return "";
             }
             $r = $GLOBALS['sql']->fetch_array($result);
             return $r[$data['field']];
         }
     } else {
         // Deal with straight abbreviations for data
         switch ($data['table']) {
             case 'patient':
                 if (strpos($data['field'], ':') === false) {
                     $raw = $this->patient->local_record[$data['field']];
                 } else {
                     list($desc, $field) = explode(':', $data['field']);
                     switch ($desc) {
                         case 'method':
                             $raw = $this->patient->{${field}}();
                             break;
                             // end method
                         // end method
                         default:
                             syslog(LOG_INFO, get_class($this) . "| could not figure out syntax for {$data['table']}, {$data['field']}");
                             $raw = "";
                             break;
                             // end default
                     }
                     // end switch desc
                 }
                 break;
             case 'control':
                 $raw = $this->FetchDataElement($data['field']);
                 break;
             case 'static':
                 $raw = $data['field'];
                 break;
             default:
                 break;
         }
         // end switch
     }
     // Deal with output formatting
     switch ($data['type']) {
         case 'link':
             if (!$data['value']) {
                 syslog(LOG_INFO, get_class($this) . "| could not process {$data['table']}, {$data['field']}, {$data['value']}");
                 return '';
             }
             if (strpos($data['value'], ':') !== false) {
                 $params = explode(':', $data['value']);
                 return module_function($params[0], 'get_field', array($raw, $params[1]));
             } else {
                 return module_function($data['value'], 'to_text', array($raw));
             }
             break;
         case 'ssn':
             return substr($raw, 0, 3) . '-' . substr($raw, 3, 2) . '-' . substr($raw, 5, 4);
             break;
         case 'conditional':
             // Handle "static" type
             if ($data['table'] == 'static') {
                 return 'X';
             }
             // Handle "multiple" type
             if ($data['table'] == 'control') {
                 if (!isset($this->controls)) {
                     $this->controls = $this->GetControls();
                 }
                 if ($this->controls[$data['field']]['type'] == 'multiple') {
                     foreach (explode(',', $raw) as $value) {
                         if ($data['value'] == $value) {
                             return 'X';
                         }
                     }
                     return '';
                 }
             }
             // Handle everything else
             if ($data['value'] == $raw) {
                 return 'X';
             } else {
                 return '';
             }
             break;
         case 'phone':
             return freemed::phone_display($raw);
             break;
         case 'date':
             if (!$raw) {
                 return '';
             }
             $_date = explode('-', $raw);
             switch (freemed::config_value('dtfmt')) {
                 case 'ymd':
                     return $raw;
                     break;
                 case 'mdy':
                 default:
                     return "{$_date[1]}/{$_date[2]}/{$_date[0]}";
                     break;
             }
             // Should never get here
             return $raw;
             break;
         case 'string':
         default:
             return $raw;
             break;
     }
     // end data type
 }
Esempio n. 2
0
function module_function($module_name, $function, $params = "")
{
    // Include proper file
    include_once resolve_module($module_name);
    // check for module existing
    if (!class_exists($module_name)) {
        trigger_error("module_function :: class \"{$module_name}\" doesn't exist");
    }
    // Load module through object
    $this_module = new $module_name();
    // execute the function
    if (is_array($params)) {
        return call_user_func_array(array($this_module, $function), $params);
    } elseif ($params == "") {
        return call_user_func(array($this_module, $function));
    } else {
        return call_user_func_array(array($this_module, $function), array($params));
    }
}
Esempio n. 3
0
function ResolveObjectPath($object, $methodResolution = false)
{
    $base_path = dirname(dirname(__FILE__));
    switch (true) {
        case substr($object, 0, 27) == 'org.freemedsoftware.module.':
            $cname = str_replace('org.freemedsoftware.module.', '', $object);
            $cname = preg_replace('/\\..+/i', '', $cname);
            $module_path = resolve_module($cname);
            if (!$module_path) {
                trigger_error("Could not resolve object path {$object}", E_USER_ERROR);
            }
            return "{$base_path}/{$module_path}";
            break;
        case substr($object, 0, 13) == 'net.php.pear.':
            $name = str_replace('net.php.pear.', '', $object);
            $name = preg_replace('/\\..+/i', '', $name);
            ini_set('include_path', ini_get('include_path') . ':' . dirname(__FILE__) . '/net/php/pear');
            $my_class = str_replace('_', '/', $name);
            $path = dirname(__FILE__) . '/net/php/pear/' . $my_class . '.php';
            return $path;
            break;
        default:
            $path = str_replace('.', '/', $object);
            $path_parts = explode('/', $path);
            // Pull out class name
            $cname = $path_parts[count($path_parts) - ($methodResolution ? 2 : 1)];
            // Remove class name
            $path_pos = count($path_parts) - ($methodResolution ? 2 : 1);
            unset($path_parts[$path_pos]);
            if ($methodResolution) {
                unset($path_parts[$path_pos + 1]);
            }
            $pname = join('/', $path_parts);
            if (file_exists("{$base_path}/lib/{$pname}/class.{$cname}.php")) {
                $cpath = "{$base_path}/lib/{$pname}/class.{$cname}.php";
            } else {
                if (file_exists("{$base_path}/lib/{$pname}/{$cname}.class.php")) {
                    $cpath = "{$base_path}/lib/{$pname}/{$cname}.class.php";
                } else {
                    $cpath = "{$base_path}/lib/{$pname}/{$cname}.php";
                }
            }
            if (!file_exists("{$base_path}/lib/{$pname}/.namespace")) {
                trigger_error("Object {$object} not valid.", E_USER_ERROR);
            }
            if (!file_exists($cpath)) {
                trigger_error("Could not resolve object path {$object}", E_USER_ERROR);
            }
            return $cpath;
            break;
    }
}
Esempio n. 4
0
<?php

// $Id$
//
// Authors:
//      Jeff Buchbinder <*****@*****.**>
//
// FreeMED Electronic Medical Record and Practice Management System
// Copyright (C) 1999-2012 FreeMED Software Foundation
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include_once dirname(__FILE__) . '/bootstrap.test.php';
t("resolve_module(systemreports)", resolve_module('systemreports'));
t("freemed::module_handler(useradd)", freemed::module_handler('UserAdd'));
#t("resolveobjectpath(org.freemedsoftware.module.systemreports)", ResolveObjectPath('org.freemedsoftware.module.systemreports'));
#t("resolveclassname(org.freemedsoftware.module.systemreports.view)", ResolveClassName('org.freemedsoftware.module.systemreports.view'));
#t("resolvemethodname(org.freemedsoftware.module.systemreports.view)", ResolveMethodName('org.freemedsoftware.module.systemreports.view'));
t('org.freemedsoftware.module.zipcodes.CalculateDistance', CallMethod('org.freemedsoftware.module.zipcodes.CalculateDistance', '06226', '03743'));