public function testAddNote()
 {
     $personId = 1000;
     $authoringPersonId = 65650;
     $dateTime = date('Y-m-d h:i:s');
     $note = new ClinicalNote();
     $note->personId = $personId;
     $note->dateTime = $dateTime;
     $note->authoringPersonId = $authoringPersonId;
     $note->persist();
     $noteId = $note->clinicalNoteId;
     $note = new ClinicalNote();
     $note->clinicalNoteId = $noteId;
     $note->populate();
     $this->assertEquals($personId, $note->personId);
     $this->assertEquals($authoringPersonId, $note->authoringPersonId);
     $this->assertEquals($dateTime, $note->dateTime);
 }
 public function indexAction()
 {
     $personId = (int) $this->_getParam('personId');
     $clinicalNoteId = (int) $this->_getParam('clinicalNoteId');
     trigger_error('ttpid: ' . $personId, E_USER_NOTICE);
     $cn = new ClinicalNote();
     $cn->clinicalNoteId = (int) $clinicalNoteId;
     $cn->populate();
     $templateId = $cn->clinicalNoteTemplateId;
     $cnTemplate = new ClinicalNoteTemplate();
     $cnTemplate->clinicalNoteTemplateId = (int) $templateId;
     $cnTemplate->populate();
     $xml = simplexml_load_string($cnTemplate->template);
     $objective = '';
     foreach ($xml as $question) {
         foreach ($question as $key => $item) {
             if ($key != "dataPoint") {
                 continue;
             }
             $namespace = (string) $item->attributes()->template;
             // extract the nsdr: format
             preg_match('/{nsdr:(.*)}/', $namespace, $matches);
             if (isset($matches[1])) {
                 $namespace = str_replace('[selectedPatientId]', $personId, $matches[1]);
                 $result = NSDR::populate($namespace);
                 $objective .= $result[$namespace];
             }
         }
     }
     $this->view->objective = $objective;
     $filter = array('personId' => $personId);
     $pl = new ProblemList();
     $pli = $pl->getIterator();
     $pli->setFilters($filter);
     $this->view->problemListIterator = $pli;
 }
Example #3
0
 public function testInValidKey()
 {
     $signature = 'invalid_password';
     $objects = array();
     $clinicalNote = new ClinicalNote();
     $clinicalNote->clinicalNoteDefinitionId = $this->_objects['noteDefinition']->clinicalNoteDefinitionId;
     $clinicalNote->personId = $this->_objects['person']->personId;
     $clinicalNote->persist();
     $objects['clinicalNote'] = $clinicalNote;
     $eSig = new ESignature();
     $eSig->signingUserId = $this->_objects['user']->personId;
     $eSig->objectClass = 'ClinicalNote';
     $eSig->objectId = $clinicalNote->clinicalNoteId;
     $eSig->summary = 'Test, One #10026 - Transcription Note **Signed**';
     $eSig->persist();
     $objects['eSig'] = $eSig;
     $esig = new ESignature();
     $esig->eSignatureId = (int) $eSig->eSignatureId;
     $esig->populate();
     $signedDate = date('Y-m-d H:i:s');
     $esig->signedDateTime = $signedDate;
     $obj = new $esig->objectClass();
     $obj->documentId = $esig->objectId;
     $obj->eSignatureId = $esig->eSignatureId;
     try {
         $esig->sign($obj, $signature);
         $esig->persist();
         $obj->populate();
         $obj->eSignatureId = $esig->eSignatureId;
         $obj->persist();
     } catch (Exception $e) {
         $this->assertTrue(true, $e->getMessage());
     }
     $this->assertEquals($esig->signature, '');
     $this->_cleanUpObjects($objects);
 }
 public function testUnsignedItem()
 {
     $this->_objects = GeneralAlertHandler::generateClinicalNoteHandler();
     $objects = array();
     $db = Zend_Registry::get('dbAdapter');
     $clinicalNote = new ClinicalNote();
     $clinicalNote->personId = $this->_objects['person']->person_id;
     $clinicalNote->visitId = 100;
     $clinicalNote->clinicalNoteDefinitionId = 19;
     $clinicalNote->dateTime = date('Y-m-d H:i:s');
     $clinicalNote->persist();
     $objects['clinicalNote'] = $clinicalNote;
     $eSign = new ESignature();
     // cleanup all generalAlerts
     $db->query('DELETE FROM ' . $eSign->_table);
     $eSign->dateTime = date('Y-m-d H:i:s');
     $eSign->signedDateTime = '0000-00-00 00:00:00';
     $eSign->signingUserId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $eSign->objectId = $clinicalNote->clinicalNoteId;
     $eSign->objectClass = get_class($clinicalNote);
     $eSign->summary = ' **Unsigned**';
     $eSign->persist();
     $objects['eSignature'] = $eSign;
     // cleanup all generalAlerts
     $generalAlert = new GeneralAlert();
     $db->query('DELETE FROM ' . $generalAlert->_table);
     $process = Processingd::getInstance();
     $process->clearProcesses();
     $process->addProcess(new ProcessAlert());
     $process->startProcessing(false);
     $generalAlertIterator = $generalAlert->getIterator();
     $ctr = 0;
     foreach ($generalAlertIterator as $alert) {
         $objects['generalAlert' . $ctr++] = $alert;
     }
     $this->assertEquals($ctr, 1, 'No alert created even with signed items');
     $this->_cleanUpObjects($objects);
 }
 function processAction()
 {
     $clinicalNoteId = (int) $this->_getParam('clinicalNoteId');
     $revisionId = (int) $this->_getParam('revisionId');
     $data = $this->_getParam('namespaceData');
     $saveDate = date('Y-m-d H:i:s');
     $cn = new ClinicalNote();
     $cn->clinicalNoteId = $clinicalNoteId;
     $cn->populate();
     if (!$revisionId > 0) {
         $revisionId = GenericData::getUnsignedRevisionId(get_class($cn), $cn->clinicalNoteId);
     }
     $eSignatureId = ESignature::retrieveSignatureId(get_class($cn), $revisionId);
     if ($eSignatureId > 0) {
         $msg = __('Failed to save. Note is already signed');
     } else {
         $cn->dateTime = date('Y-m-d H:i:s');
         $cn->persist();
         $msg = __('Data saved.');
         $template = $cn->clinicalNoteDefinition->clinicalNoteTemplate->template;
         $xml = simplexml_load_string($template);
         $objectClass = 'ClinicalNote';
         list($name, $value) = each($data);
         $gd = new GenericData();
         $gd->objectClass = $objectClass;
         $gd->objectId = $clinicalNoteId;
         $gd->name = $name;
         $rowExists = $gd->doesRowExist(true);
         $preQueries = null;
         if ($rowExists) {
             $revisionId = (int) $gd->revisionId;
             $preQueries = 'DELETE FROM `' . $gd->_table . '` WHERE `revisionId`=' . $revisionId;
         } else {
             $revisionId = WebVista_Model_ORM::nextSequenceId();
         }
         $otm = new WebVista_Model_ORMTransactionManager();
         foreach ($data as $name => $value) {
             $gd = new GenericData();
             $gd->objectClass = $objectClass;
             $gd->objectId = $clinicalNoteId;
             $gd->dateTime = $saveDate;
             $gd->name = $name;
             $gd->value = $value;
             $gd->revisionId = $revisionId;
             $otm->addORM($gd);
         }
         if (!$otm->persist($preQueries)) {
             $msg = __('Failed to save.');
         }
         if ((string) $xml->attributes()->useNSDR && (string) $xml->attributes()->useNSDR == 'true') {
             if (!ClinicalNote::processNSDRPersist($xml, $cn, $data)) {
                 $msg = __('Failed to save.');
             }
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($msg);
 }
 public function processEditNoteAction()
 {
     $ret = true;
     $clinicalNote = new ClinicalNote();
     $clinicalNote->clinicalNoteId = (int) $this->_getParam('clinicalNoteId');
     $clinicalNote->populate();
     if ($clinicalNote->eSignatureId > 0) {
         $clinicalNote->eSignatureId = 0;
         $revisionId = (int) $this->_getParam('revisionId');
         GenericData::createRevision(get_class($clinicalNote), $clinicalNote->clinicalNoteId, $revisionId);
         $clinicalNote->persist();
     } else {
         $ret = __('Selected note must be signed first.');
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }
 public function defaultPatientNoteAction()
 {
     // bf9f3f39-dbc2-493f-9ca7-dde335f54de3
     $referenceId = $this->_getParam('referenceId');
     $data = $this->_getAttachmentData($referenceId);
     $clinicalNoteId = (int) $this->_getParam('clinicalNoteId');
     $revisionId = (int) $this->_getParam('revisionId');
     $clinicalNote = new ClinicalNote();
     $clinicalNote->clinicalNoteId = $clinicalNoteId;
     $clinicalNote->populate();
     $xml = new SimpleXMLElement('<data/>');
     $xml->addChild('clinicalNoteContents', $clinicalNote->toASCII($revisionId));
     $patient = new Patient();
     $patient->personId = (int) $clinicalNote->personId;
     $patient->populate();
     $xml = $patient->populateXML($xml);
     try {
         $content = ReportBase::mergepdfset($xml, $data);
         $this->getResponse()->setHeader('Content-Type', 'application/pdf');
     } catch (Exception $e) {
         $content = '<script>alert("' . $e->getMessage() . '")</script>';
     }
     $this->view->content = $content;
     $this->render('binary-template');
 }
    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'));
                }
            }
        }
    }
 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;
 }