/**
  * 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);
 }
    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("&nbsp;&nbsp;");
                    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'));
                }
            }
        }
    }
    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("&nbsp;&nbsp;");
                    $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'));
                }
            }
        }
    }
Пример #4
0
 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;
 }