public function templatedTextAction() { $personId = $this->_getParam('personId', 0); $templateId = $this->_getParam('templateId', 0); $templateName = $this->_getParam('templateName'); $templatedText = new TemplatedText(); if ($templateId > 0) { $templatedText->templateId = $templateId; $templatedText->populate(); } else { $templatedText->populateByName($templateName); } $template = $templatedText->template; preg_match_all('/{nsdr:(.*)}/', $template, $matches); if (count($matches[1]) > 0) { foreach ($matches[1] as $val) { $namespace = str_replace('[selectedPatientId]', $personId, $val); if (Zend_Registry::get('memcacheStatus') === 0) { $resultValue = __("Memcache server not started"); } else { $resultValue = NSDR2::populate($namespace); } $template = preg_replace('/{nsdr:(.*)}/', $resultValue, $template, 1); } } $this->view->template = $template; $this->render(); }
public function NSDRUnload() { return NSDR2::systemUnload(); }
protected function systemStatus() { $ret = NSDR2::systemStatus(); if ($ret === false) { $ret = __("Stop"); } return $ret; }
/** * Process the modified clinical notes template */ public function processEditTemplateAction() { $params = $this->_getParam('cnTemplate'); $autoAdd = (int) $this->_getParam('autoAdd'); $cnTemplate = new ClinicalNoteTemplate(); $cnTemplate->populateWithArray($params); $data = array(); try { $xml = new SimpleXMLElement($cnTemplate->template); $data['msg'] = __('Record saved successfully.'); $cnTemplate->persist(); } catch (Exception $e) { $data['error'] = __('Error: ' . $e->getMessage()); } if (!isset($data['error']) && (string) $xml->attributes()->useNSDR && (string) $xml->attributes()->useNSDR == 'true') { $namespaceAdd = false; $namespaces = array(); $nsdrDefinition = new NSDRDefinition(); foreach ($xml as $questions) { foreach ($questions as $key => $item) { $namespace = (string) $item->attributes()->namespace; if ($key != 'dataPoint' || $namespace && !strlen($namespace) > 0) { continue; } // extract namespace only $namespace = NSDR2::extractNamespace($namespace); // check if namespace exists then auto-add if does not if (!$nsdrDefinition->isNamespaceExists($namespace) && $autoAdd) { $nsdrDefinition->addNamespace($namespace, 'GenericData'); $namespaceAdd = true; } } } if ($namespaceAdd) { $data['msg'] .= "\n\n" . __('Please reload NSDR'); } } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
public function imagingAction() { $personId = (int) $this->_getParam('personId'); $orderId = (int) $this->_getParam('orderId'); $copy = (int) $this->_getParam('copy'); $orderImaging = new OrderImaging(); $orderImaging->orderId = $orderId; if (!$orderId > 0 || !$orderImaging->populate()) { $orderImaging->order->patientId = $personId; } if ($copy) { $orderImaging->orderId = 0; } $form = new WebVista_Form(array('name' => 'imagingId')); $form->setAction(Zend_Registry::get('baseUrl') . 'orders.raw/process-imaging'); $form->loadORM($orderImaging, 'imaging'); $form->setWindow('windowImagingId'); $this->view->form = $form; $namespace = $personId . '::com.clearhealth.person.examsOver7days'; $this->view->examsOver7days = NSDR2::populate($namespace); $imagingList = array(); $categories = array(); $urgencies = array(); $transports = array(); $pregnants = array(); $enumeration = new Enumeration(); $enumeration->populateByUniqueName(OrderImaging::IMAGING_ENUM_NAME); $enumerationClosure = new EnumerationClosure(); $imagingEnums = $enumerationClosure->getAllDescendants($enumeration->enumerationId, 1, true); foreach ($imagingEnums as $imagingEnum) { $rowset = $enumerationClosure->getAllDescendants($imagingEnum->enumerationId, 1, true); if ($imagingEnum->key == OrderImaging::IMAGING_TYPES_ENUM_KEY) { foreach ($rowset as $enum) { $enumKey = $enum->enumerationId; $imagingList[$enumKey] = array(); $imagingList[$enumKey]['name'] = $enum->name; $imagingList[$enumKey]['procedures'] = array(); $imagingList[$enumKey]['modifiers'] = array(); $rows = $enumerationClosure->getAllDescendants($enum->enumerationId, 1, true); foreach ($rows as $row) { if ($row->name == 'Procedures') { $rowsProcedures = $enumerationClosure->getAllDescendants($row->enumerationId, 1, true); foreach ($rowsProcedures as $rowProcedure) { $rowProcedureKey = $rowProcedure->enumerationId; $imagingList[$enumKey]['procedures'][$rowProcedureKey]['procedure'] = $rowProcedure->name; $rowsUnitComment = $enumerationClosure->getAllDescendants($rowProcedure->enumerationId, 1, true); $comment = ''; foreach ($rowsUnitComment as $unitComment) { $comment = $unitComment->name; break; // only one comment is expected } $imagingList[$enumKey]['procedures'][$rowProcedureKey]['comment'] = $comment; } } else { if ($row->name == 'Modifiers') { $rowsModifiers = $enumerationClosure->getAllDescendants($row->enumerationId, 1, true); foreach ($rowsModifiers as $rowModifier) { $rowModifierKey = $rowModifier->enumerationId; $imagingList[$enumKey]['modifiers'][$rowModifierKey] = $rowModifier->name; } } } } } } else { if ($imagingEnum->key == OrderImaging::IMAGING_CATEGORIES_ENUM_KEY) { foreach ($rowset as $enum) { $categories[$enum->key] = $enum->name; } } else { if ($imagingEnum->key == OrderImaging::IMAGING_URGENCIES_ENUM_KEY) { foreach ($rowset as $enum) { $urgencies[$enum->key] = $enum->name; } } else { if ($imagingEnum->key == OrderImaging::IMAGING_TRANSPORTS_ENUM_KEY) { foreach ($rowset as $enum) { $transports[$enum->key] = $enum->name; } } else { if ($imagingEnum->key == OrderImaging::IMAGING_PREGNANTS_ENUM_KEY) { foreach ($rowset as $enum) { $pregnants[$enum->key] = $enum->name; } } } } } } } $this->view->imagingList = $imagingList; $this->view->categories = $categories; $this->view->urgencies = $urgencies; $this->view->transports = $transports; $this->view->pregnants = $pregnants; $this->view->imagingSubmitTo = array('CLEARHEALTH HOSPITAL'); // temporarily hard-coded $this->render(); }
public static function getServices() { $ok = true; $services = array(); $service = array(); $id = 'nsdr'; $service['id'] = $id; $service['name'] = 'NSDR'; $nsdrStatus = NSDR2::systemStatus(); if ($nsdrStatus === false) { $ok = false; $nsdrStatus = 'stopped'; } if ($nsdrStatus != 'started' && $nsdrStatus != 'reloaded') { $ok = false; } $service['status'] = ucwords($nsdrStatus); $services[$id] = $service; $service = array(); $id = 'hl7d'; $service['id'] = $id; $service['name'] = 'Processing Daemon'; $hl7Status = false; // temporarily set to false if ($hl7Status === false) { $hl7Status = 'stopped'; } $hl7Status = 'Stopped'; if (file_exists('/tmp/CHProcessingDaemon.lock')) { $hl7Status = 'Started'; } $service['status'] = ucwords($hl7Status); $services[$id] = $service; $service = array(); $id = 'menu'; $service['id'] = $id; $service['name'] = 'Menu'; $configItem = new ConfigItem(); $configItem->configId = 'enableCache'; $configItem->populate(); $menuStatus = __('Disable'); if ($configItem->value) { $menuStatus = __('Enable'); } else { $ok = false; } $service['status'] = $menuStatus; $services[$id] = $service; $service = array(); $id = 'permissions'; $service['id'] = $id; $service['name'] = 'Permissions'; $status = PermissionTemplate::serviceStatus(); if ($status === false) { $ok = false; $status = 'stopped'; } if ($status != 'started' && $status != 'reloaded') { $ok = false; } $service['status'] = ucwords($status); $services[$id] = $service; $memcache = Zend_Registry::get('memcache'); $serviceNominal = $memcache->get(self::SERVICE_NOMINAL); if ($ok) { $memcache = Zend_Registry::get('memcache'); $memcache->set(self::SERVICE_NOMINAL, true); } else { if ($serviceNominal !== false) { $memcache->delete(self::SERVICE_NOMINAL, 0); } } return $services; }
protected function _buildForm($xml) { static $_namespaceElements = array(); foreach ($xml as $question) { $formName = preg_replace('/[^a-zA-Z0-9]/', '', $question->attributes()->label); //var_dump($question->dataPoint); $elements = array(); foreach ($question as $key => $item) { if ($key == "dataPoint") { $dataPoint = $item; } elseif ($key == "heading") { $headingName = preg_replace('/[^a-zA-Z0-9\\ ]/', '', (string) $item); $element = $this->_form->createElement('hidden', $headingName, array('label' => (string) $item, 'disabled' => "disabled")); $element->addDecorator('Label', array('tag' => 'h3')); $this->_form->addElement($element); $elements[] = $headingName; continue; } else { continue; } $type = (string) $dataPoint->attributes()->type; if ($this->_cn->eSignatureId > 0 && $type == 'div') { $type = 'pre'; } else { if ($this->_cn->eSignatureId > 0 && $type == 'richEdit') { $type = 'readOnly'; } } if ($type == "img" && (string) $dataPoint->attributes()->draw == "true") { $type = 'drawing'; } $elementName = preg_replace('/[-\\.]/', '_', NSDR2::extractNamespace((string) $dataPoint->attributes()->namespace)); $element = $this->_form->createElement($type, $elementName, array('label' => (string) $dataPoint->attributes()->label)); if ($this->_form->getElement($elementName) instanceof Zend_Form_Element) { $element = $this->_form->getElement($elementName); } if ((string) $dataPoint->attributes()->src) { $element->setAttrib("src", (string) $dataPoint->attributes()->src); } if ((string) $dataPoint->attributes()->class) { $element->setAttribute("class", (string) $dataPoint->attributes()->class); } if ((string) $dataPoint->attributes()->type == "radio" || $type == "select") { $element->setLabel(""); $element->setSeparator(" "); $element->addMultiOption((string) $dataPoint->attributes()->value, (string) $dataPoint->attributes()->label); if ((string) $dataPoint->attributes()->default == true) { $element->setValue((string) $dataPoint->attributes()->value); } if ((string) $dataPoint->attributes()->type == 'radio') { if ((string) $dataPoint->attributes()->radioGroup) { $radioGroup = preg_replace('/\\./', '_', (string) $dataPoint->attributes()->radioGroup); $innerHTML = ''; $elName = 'namespaceData[' . $element->getName() . ']'; if (!isset($_namespaceElements[$radioGroup])) { $_namespaceElements[$radioGroup] = true; $innerHTML = ' var ' . $radioGroup . 'Members = []; function ' . $radioGroup . '(name) { var elName = null; var el = null; for (var i = 0; i < ' . $radioGroup . 'Members.length; i++) { elName = ' . $radioGroup . 'Members[i]; el = document.getElementsByName(elName)[0]; if (!el) { continue; } if (el.checked && elName != name) { el.checked = false; break; // there is only on checked element in a group } } } '; } $innerHTML .= $radioGroup . 'Members.push("' . $elName . '");'; $element->addDecorator('ScriptTag', array('placement' => 'APPEND', 'tag' => 'script', 'innerHTML' => $innerHTML, 'noAttribs' => true)); $element->setAttrib('onchange', $radioGroup . '("' . $elName . '")'); } if ((string) $dataPoint->attributes()->radioGroupDefault && (string) $dataPoint->attributes()->radioGroupDefault == '1') { $element->setAttrib('checked', 'checked'); } } } if ((string) $dataPoint->attributes()->type == "checkbox") { $element->AddDecorator('Label', array('placement' => 'APPEND')); $element->AddDecorator('HtmlTag', array('placement' => 'PREPEND', 'tag' => '<br />')); } if (strlen((string) $dataPoint->attributes()->templateText) > 0) { $templateName = (string) $dataPoint->attributes()->templateText; //$element->setValue($this->view->action('index','template-text',null,array('personId' => $this->_cn->personId))); $element->setValue($this->view->action('templated-text', 'template-text', null, array('personId' => $this->_cn->personId, 'templateName' => $templateName))); } if ((string) $dataPoint->script) { $element->addDecorator("ScriptTag", array('placement' => 'APPEND', 'tag' => 'script', 'innerHTML' => (string) $dataPoint->script, 'noAttribs' => true)); } $element->setBelongsTo('namespaceData'); //var_dump($element); $this->_form->addElement($element); $elements[] = $elementName; } //var_dump($elements); if (count($elements) > 0) { $this->_form->addDisplayGroup($elements, (string) $question->attributes()->label, array("legend" => (string) $question->attributes()->label)); if (strlen(trim((string) $question->attributes()->containerStyle)) > 0) { $displayGroup = $this->_form->getDisplayGroup((string) $question->attributes()->label); $style = preg_replace('/\\xEF\\xBB\\xBF/', '', trim((string) $question->attributes()->containerStyle)); $displayGroup->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'dl', 'style' => $style)), 'Fieldset')); } } } }
/** * Process the modified NSDR definition together its NSDR definition methods */ public function processEditAction() { $this->editAction(); // NSDR Definition parameters $params = $this->_getParam('nsdrDefinition'); $this->_nsdrDefinition->populateWithArray($params); $id = $params['uuid']; if (!strlen($id) > 0) { $this->_nsdrDefinition->uuid = NSDR::create_guid(); } else { // remove to NSDR memcache $nsdr = new NSDRDefinition(); $nsdr->uuid = $id; $nsdr->populate(); NSDR2::removeNamespace($nsdr->namespace); } $message = __('Record Saved for NSDR Definition: ' . $this->_nsdrDefinition->namespace); $code = 200; // cannot add method if alias exists (alias must be canonical) if (strlen($this->_nsdrDefinition->aliasFor) > 0) { $nsdr = new NSDRDefinition(); //$nsdr->uuid = $this->_nsdrDefinition->aliasFor; $nsdr->populateByNamespace($this->_nsdrDefinition->aliasFor); if (strlen($nsdr->namespace) > 0) { if (strlen($nsdr->aliasFor) > 0) { $this->_nsdrDefinition->aliasFor = ''; $message = __('Alias must be canonical.'); $code = 400; } } else { $this->_nsdrDefinition->aliasFor = ''; $message = __('Alias does not exists.'); $code = 401; } } if (strlen($this->_nsdrDefinition->ORMClass) > 0) { if (!NSDRDefinition::isORMClassImplementsMethod($this->_nsdrDefinition->ORMClass)) { $this->_nsdrDefinition->ORMClass = ''; $message = __('Invalid ORM Class'); $code = 402; } } $this->_nsdrDefinition->persist(); $this->view->message = $message; $this->view->code = $code; $this->render('edit'); }
protected function _buildForm($xml) { static $_namespaceElements = array(); $headingCounter = 1; $counter = 1; foreach ($xml as $question) { $elements = array(); foreach ($question as $key => $item) { if ($key == "dataPoint") { $dataPoint = $item; } elseif ($key == "heading") { $headingName = 'heading' . $headingCounter++; //preg_replace('/[^a-zA-Z0-9\ ]/','',(string)$item); $element = $this->_form->createElement('hidden', $headingName, array('label' => (string) $item, 'disabled' => "disabled")); $element->addDecorator('Label', array('tag' => 'h3')); $this->_form->addElement($element); $elements[] = $headingName; continue; } elseif ($key == 'break') { $breakName = 'break' . $counter++; $element = $this->_form->createElement('hidden', $breakName, array('disabled' => 'disabled')); $element->addDecorator('HtmlTag', array('placement' => 'APPEND', 'tag' => '<br />')); $this->_form->addElement($element); $elements[] = $breakName; continue; } else { continue; } $scripts = array(); $type = (string) $dataPoint->attributes()->type; if ($this->_cn->eSignatureId > 0 && $type == 'div') { $type = 'pre'; } else { if ($this->_cn->eSignatureId > 0 && $type == 'richEdit') { $type = 'readOnly'; } } if ($type == "img" && (string) $dataPoint->attributes()->draw == "true") { $type = 'drawing'; } $elementName = ClinicalNote::encodeNamespace(NSDR2::extractNamespace((string) $dataPoint->attributes()->namespace)); if ($this->_form->getElement($elementName) instanceof Zend_Form_Element) { $element = $this->_form->getElement($elementName); } else { $element = $this->_form->createElement($type, $elementName, array('label' => (string) $dataPoint->attributes()->label)); } $reservedAttributes = array('templateText' => 'templateText', 'label' => 'label', 'value' => 'value', 'containerStyle' => 'containerStyle', 'type' => 'type', 'draw' => 'draw', 'namespace' => 'namespace', 'default' => 'default', 'radioGroup' => 'radioGroup', 'radioGroupDefault' => 'radioGroupDefault'); if ((string) $dataPoint->attributes()->type == "radio" || $type == "select") { $attributes = array(); foreach ($dataPoint->attributes() as $k => $v) { if (isset($reservedAttributes[$k])) { continue; } $attributes[$k] = $v; } $element->setLabel(""); $element->setSeparator(" "); if ((string) $dataPoint->attributes()->type == 'radio') { $optionLabels = array('label' => (string) $dataPoint->attributes()->label, 'attributes' => $attributes); // composed of label and attributes $element->addMultiOption((string) $dataPoint->attributes()->value, $optionLabels); } else { $element->setAttribs($attributes); $element->addMultiOption((string) $dataPoint->attributes()->value, (string) $dataPoint->attributes()->label); } if ((string) $dataPoint->attributes()->default == true) { $element->setValue((string) $dataPoint->attributes()->value); } } else { foreach ($dataPoint->attributes() as $k => $v) { if (isset($reservedAttributes[$k])) { continue; } $element->setAttrib($k, $v); } } if ((string) $dataPoint->attributes()->type == "checkbox") { $element->addDecorator('Label', array('placement' => 'APPEND')); $element->addDecorator('HtmlTag', array('placement' => 'PREPEND', 'tag' => '<br />')); if ((string) $dataPoint->attributes()->radioGroup) { $radioGroup = '_' . preg_replace('/\\./', '_', (string) $dataPoint->attributes()->radioGroup); $innerHTML = ''; $elName = 'namespaceData[' . $element->getName() . ']'; if (!isset($_namespaceElements[$radioGroup])) { $_namespaceElements[$radioGroup] = true; $innerHTML = ' var ' . $radioGroup . 'Members = []; function ' . $radioGroup . '(name) { var elName = null; var el = null; var elem = null; for (var i = 0; i < ' . $radioGroup . 'Members.length; i++) { elName = ' . $radioGroup . 'Members[i]; el = document.getElementsByName(elName); if (!el) { continue; } elem = null; for (var j = 0; j < el.length; j++) { if (el[j].type == "checkbox") { elem = el[j]; break; } } if (elem == null) continue; if (elem.checked && elName != name) { elem.checked = false; //break; // there is only one checked element in a group } } } '; } $innerHTML .= $radioGroup . 'Members.push("' . $elName . '");'; $scripts[] = $innerHTML; $element->setAttrib('onchange', $radioGroup . '("' . $elName . '")'); } if ((string) $dataPoint->attributes()->radioGroupDefault && (string) $dataPoint->attributes()->radioGroupDefault == '1') { $element->setAttrib('checked', 'checked'); } } if (strlen((string) $dataPoint->attributes()->templateText) > 0) { $templateName = (string) $dataPoint->attributes()->templateText; //$element->setValue($this->view->action('index','template-text',null,array('personId' => $this->_cn->personId))); $element->setValue($this->view->action('templated-text', 'template-text', null, array('personId' => $this->_cn->personId, 'templateName' => $templateName))); } if ((string) $dataPoint->script) { $scripts[] = (string) $dataPoint->script; } if (isset($scripts[0])) { $element->addDecorator("ScriptTag", array('placement' => 'APPEND', 'tag' => 'script', 'innerHTML' => implode("\n", $scripts), 'noAttribs' => true)); } $element->setBelongsTo('namespaceData'); //var_dump($element); $this->_form->addElement($element); $elements[] = $elementName; } //var_dump($elements); if (count($elements) > 0) { $this->_form->addDisplayGroup($elements, (string) $question->attributes()->label, array("legend" => (string) $question->attributes()->label)); if (strlen(trim((string) $question->attributes()->containerStyle)) > 0) { $displayGroup = $this->_form->getDisplayGroup((string) $question->attributes()->label); $style = preg_replace('/\\xEF\\xBB\\xBF/', '', trim((string) $question->attributes()->containerStyle)); $displayGroup->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'dl', 'style' => $style)), 'Fieldset')); } } } }
public function executeQueries(array $filters, ReportView $view) { $config = Zend_Registry::get('config'); $dbName = $config->database->params->dbname; $db = Zend_Registry::get('dbAdapter'); $ret = array(); $filterQueries = array(); $reportFilters = array(); foreach ($this->reportFilters as $key => $filter) { if ($filter->type == 'QUERY') { $filterQueries[$filter->query] = $filter->query; } $reportFilters['{{' . $filter->name . '}}'] = $filter; } //trigger_error(print_r($reportFilters,true),E_USER_NOTICE); $reportQuery = new ReportQuery(); $reportQueryIterator = $reportQuery->getIteratorByBaseId($this->reportBaseId); $viewColumnDefinitions = array(); $unserializedColumnDefinitions = $view->unserializedColumnDefinitions; if ($unserializedColumnDefinitions === null) { $unserializedColumnDefinitions = array(); } foreach ($unserializedColumnDefinitions as $id => $value) { $viewColumnDefinitions[$value->queryId][$id] = $value; } //file_put_contents('/tmp/columns.txt',print_r($columnDefinitions,true)); foreach ($reportQueryIterator as $query) { if (isset($filterQueries[$query->reportQueryId])) { continue; } // report query associated with filter not included $row = array(); $row['reportQuery'] = $query->toArray(); $row['reportQuery']['customColNames'] = (bool) $view->customizeColumnNames; $queryValue = $query->query; $tokens = $this->_extractTokens($queryValue); if (isset($tokens[0])) { // tokens defined // check for undefined/orphaned filter $undefinedTokens = array(); foreach ($tokens as $token) { if (!isset($reportFilters[$token])) { $undefinedTokens[] = $token; } } if (isset($undefinedTokens[0])) { $error = 'Query "' . $query->displayName . '" contains undefined tokens: ' . implode(', ', $undefinedTokens); $row['error'] = $error; trigger_error($error, E_USER_NOTICE); $ret[] = $row; continue; } $queryValue = $this->_applyFilters($filters, $queryValue); } $columnDefinitions = array(); if (isset($viewColumnDefinitions[$query->reportQueryId])) { $columnDefinitions = $viewColumnDefinitions[$query->reportQueryId]; } else { foreach ($viewColumnDefinitions as $id => $value) { foreach ($value as $i => $v) { if ($v->queryId != 0 || $v->queryName != $query->reportQueryId) { continue; } $columnDefinitions[$i] = $v; } } } //file_put_contents('/tmp/columns.txt',$query->reportQueryId.' = '.print_r($columnDefinitions,true),FILE_APPEND); $columnDefinitionLen = count($columnDefinitions); switch ($query->type) { case ReportQuery::TYPE_SQL: //file_put_contents('/tmp/query.sql',$queryValue); trigger_error($queryValue, E_USER_NOTICE); // extract and execute defined SQL variables $tmp = explode(';', $queryValue); if (count($tmp) > 0) { foreach ($tmp as $key => $line) { $line = trim($line); if (substr($line, 0, 5) == 'SET @') { unset($tmp[$key]); trigger_error('EXECUTING SQL: ' . $line); $db->query($line); } } $queryValue = implode(';', $tmp); } try { $results = array(); $headers = array(); $stmt = $db->query($queryValue, array(), Zend_Db::FETCH_NUM); $columnInfo = array(); $rowCount = $stmt->rowCount(); for ($i = 0; $i < $rowCount; $i++) { $fetchRow = $stmt->fetch(Zend_Db::FETCH_NUM, null, $i); if ($i == 0) { for ($ctr = 0, $rowLen = count($fetchRow); $ctr < $rowLen; $ctr++) { $columnMeta = $stmt->getColumnMeta($ctr); if ($view->customizeColumnNames && $columnDefinitionLen > 0) { $resultSetName = $dbName . '.' . $columnMeta['table'] . '.' . $columnMeta['name']; foreach ($columnDefinitions as $id => $mapping) { // id, queryId, queryName, resultSetName, displayName, transform if ($mapping->resultSetName == $resultSetName) { $headers[$ctr] = $mapping->displayName; $columnInfo[$ctr] = $mapping; break; } } } else { $headers[$ctr] = $columnMeta['name']; } } } $tmpResult = array('id' => $i, 'data' => array()); if ($view->customizeColumnNames && $columnDefinitionLen > 0) { $tmp = array(); foreach ($columnInfo as $index => $mapping) { $tmp[$mapping->displayName] = $this->_applyTransforms($mapping->transforms, $fetchRow[$index]); } $tmpHeaders = $headers; $headers = array(); foreach ($columnDefinitions as $id => $mapping) { // id, queryId, queryName, resultSetName, displayName, transform $tmpResult['data'][] = $tmp[$mapping->displayName]; foreach ($tmpHeaders as $key => $header) { if ($header != $mapping->displayName) { continue; } $headers[] = $header; unset($tmpHeaders[$key]); break; } } } else { foreach ($headers as $index => $header) { $tmpResult['data'][] = $fetchRow[$index]; } } $results[] = $tmpResult; } $row['headers'] = $headers; $row['rows'] = $results; } catch (Exception $e) { $uniqErrCode = uniqid(); $row['error'] = 'There was a problem executing query: ' . $query->displayName . '. Contact your administrator with error code: ' . $uniqErrCode; trigger_error('Exception error (' . $uniqErrCode . '): ' . $e->getMessage(), E_USER_NOTICE); trigger_error('SQL Query (' . $uniqErrCode . '): ' . $queryValue, E_USER_NOTICE); } $ret[] = $row; break; case ReportQuery::TYPE_NSDR: $nsdr = explode("\n", $queryValue); $nsdrResults = array(); $allDefaults = true; foreach ($nsdr as $key => $value) { $value = $this->_applyFilters($filters, $value); $resultSetName = ReportView::extractNamespace($value); //$displayName = ReportView::metaDataPrettyName($resultSetName); $nsdrResult = NSDR2::populate($value); // NOTE: return of NSDR2::populate() can be either of the following: string, associative array (all keys are treated as column names and values as row/ cell values), and multidimensional array (contains multiple associative arrays) $data = array($resultSetName, $nsdrResult); if (is_array($nsdrResult)) { if (array_key_exists(0, $nsdrResult)) { if (!is_array($nsdrResult[0])) { $data[1] = implode("\n", $nsdrResult); } else { // multi dimensional array $allDefaults = false; foreach ($nsdrResult as $index => $results) { $data = array(); $row['headers'] = array(); foreach ($results as $k => $v) { $row['headers'][] = ReportView::metaDataPrettyName($k); $data[] = $v; } $nsdrResults[$resultSetName][] = array('id' => $key . $index, 'data' => $data); } continue; } } else { $allDefaults = false; $row['headers'] = array(); $data = array(); foreach ($nsdrResult as $k => $v) { $row['headers'][] = ReportView::metaDataPrettyName($k); $data[] = $v; } } } $nsdrResults[$resultSetName][] = array('id' => $key, 'data' => $data); } if ($allDefaults) { $row['headers'] = array('Name', 'Value'); } /*else { if (isset($row['headers'][0]) && $row['headers'][0] != 'Name') $row['headers'][0] .= ' / Name'; if (isset($row['headers'][1]) && $row['headers'][1] != 'Value') $row['headers'][1] .= ' / Value'; }*/ if ($view->customizeColumnNames && $columnDefinitionLen > 0) { foreach ($columnDefinitions as $id => $mapping) { // id, queryId, queryName, resultSetName, displayName, transform $displayName = $mapping->resultSetName; if (!isset($nsdrResults[$displayName]) || ($mapping->queryId != 0 && $mapping->queryId != $query->reportQueryId || $mapping->queryId == 0 && $mapping->queryName != $query->reportQueryId) && $mapping->queryName != $query->displayName) { continue; } //$displayName = ReportView::metaDataPrettyName($mapping->resultSetName); foreach ($nsdrResults[$displayName] as $key => $value) { $data = $nsdrResults[$displayName][$key]['data']; if (!array_key_exists(0, $data)) { continue; } foreach ($data as $k => $v) { if ($k == 0 && $v == $displayName) { $v = $mapping->displayName; } else { $v = $this->_applyTransforms($mapping->transforms, $v); } $nsdrResults[$displayName][$key]['data'][$k] = $v; } $data = $nsdrResults[$displayName][$key]['data'][1]; } } } $results = array(); foreach ($nsdrResults as $result) { foreach ($result as $key => $value) { $results[] = $value; } } $row['rows'] = $results; $ret[] = $row; break; } } return $ret; }
public function buildDefaultGenericData(SimpleXMLElement $xml = null) { if ($xml === null) { if (!strlen($this->clinicalNoteDefinition->clinicalNoteTemplate->template) > 0) { $this->clinicalNoteDefinition->populate(); } $xml = new SimpleXMLElement($this->clinicalNoteDefinition->clinicalNoteTemplate->template); } $revisionId = WebVista_Model_ORM::nextSequenceId(); $nsdrData = array(); if ((string) $xml->attributes()->useNSDR && (string) $xml->attributes()->useNSDR == 'true') { $nsdrData = ClinicalNote::getNSDRData($xml, $this, $revisionId); } $dateTime = date('Y-m-d H:i:s'); foreach ($xml as $question) { foreach ($question as $key => $item) { if ($key != 'dataPoint') { continue; } $namespace = NSDR2::extractNamespace((string) $item->attributes()->namespace); $name = preg_replace('/[-\\.]/', '_', $namespace); $value = ''; if (strlen((string) $item->attributes()->templateText) > 0) { $templateName = (string) $item->attributes()->templateText; $view = Zend_Layout::getMvcInstance()->getView(); $value = $view->action('templated-text', 'template-text', null, array('personId' => $this->personId, 'templateName' => $templateName)); } if ((string) $item->attributes()->default == true) { $value = (string) $item->attributes()->value; } if (isset($nsdrData[$name])) { $value = $nsdrData[$name]; } $gd = new GenericData(); $gd->objectClass = get_class($this); $gd->objectId = $this->clinicalNoteId; $gd->dateTime = $dateTime; $gd->name = $name; $gd->value = $value; $gd->revisionId = $revisionId; $gd->persist(); //trigger_error('PERSISTED:'.print_r($gd->toArray(),true),E_USER_NOTICE); } } return $revisionId; }
public function testPopulate() { $person = new Person(); $person->personId = 1234; $person->populate(); $firstName = $person->firstName; $person->firstName = 'John'; $lastName = $person->lastName; $person->lastName = 'Doe'; $middleName = $person->middleName; $person->middleName = 'C'; $person->persist(); // test case 1 $result = NSDR2::populate('1234::com.clearhealth.person'); $this->assertEquals($result['first_name'], $person->firstName, 'TEST CASE 1 failed.'); $this->assertEquals($result['last_name'], $person->lastName, 'TEST CASE 1 failed.'); $this->assertEquals($result['middle_name'], $person->middleName, 'TEST CASE 1 failed.'); // test case 2 $result = NSDR2::populate('1234::com.clearhealth.person.middleName'); $this->assertEquals($result, 'C', 'TEST CASE 2 failed.'); // test case 5 $result = NSDR2::populate('1234::com.clearhealth.person[aggregateDisplay()]'); $this->assertContains('Doe John C', $result, 'TEST CASE 5 failed.'); // revert the person $person->firstName = $firstName; $person->lastName = $lastName; $person->middleName = $middleName; $person->persist(); }