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;
 }
 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');
 }