Exemplo n.º 1
0
 public static function createSignatureEntry(Document $object, $signingUserId = null)
 {
     $db = Zend_Registry::get('dbAdapter');
     $esig = new ESignature();
     if ($object->eSignatureId > 0) {
         //document is already signed, we cannot create a new signature entry for an already signed document unless the document is first unlinked
         return false;
     }
     $esigSelect = $db->select()->from('eSignatures')->where('eSignatures.objectId = ' . (int) $object->documentId)->order('eSignatureId DESC');
     if (($row = $db->query($esigSelect)->fetch()) !== false) {
         if ($row['signature'] == "") {
             //open signature record exists so do not create another
             return false;
         }
         $esig->editedSummary = $object->getSummary();
     } else {
         $esig->unsignedSummary = $object->getSummary();
     }
     $esig->objectId = $object->getDocumentId();
     $esig->objectClass = get_class($object);
     if ($signingUserId === null) {
         $signingUserId = Zend_Auth::getInstance()->getIdentity()->personId;
     }
     $esig->signingUserId = (int) $signingUserId;
     $esig->dateTime = date('Y-m-d H:i:s');
     $esig->persist();
 }
Exemplo n.º 2
0
 /**
  * Persist an ordo to the database
  *
  * @param ORDataObject	$ordo
  */
 function persist()
 {
     $db = Zend_Registry::get('dbAdapter');
     $this->_inPersist = true;
     $sql = $this->toSQL();
     $this->_inPersist = false;
     //echo $sql . "<br />";ob_flush();
     $stmt = $db->query($sql);
     $stmt->closeCursor();
     $this->postPersist();
     if ($this instanceof Document && $this->signatureNeeded()) {
         ESignature::createSignatureEntry($this);
     }
     if ($this->shouldAudit() && get_class($this) != "Audit" && get_class($this) != "AuditValue") {
         WebVista_Model_ORM::audit($this);
     }
     return $this;
 }
Exemplo n.º 3
0
 public static function handlereFaxAct(Audit $audit, array $sourceData)
 {
     if ($audit->objectClass != 'ESignature') {
         return false;
     }
     $eSignature = new ESignature();
     $eSignature->eSignatureId = $audit->objectId;
     $eSignature->populate();
     if ($eSignature->objectClass != 'Medication') {
         return false;
     }
     $medication = new Medication();
     $medication->medicationId = $eSignature->objectId;
     $medication->populate();
     $audit = $sourceData['_audit'];
     $messaging = new Messaging(Messaging::TYPE_OUTBOUND_FAX);
     $messaging->messagingId = (int) $sourceData['transmissionId'];
     $messaging->transmissionId = $messaging->messagingId;
     $messaging->populate();
     $messaging->objectId = $messaging->messagingId;
     $messaging->objectClass = $audit->objectClass;
     $messaging->status = 'Faxed';
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->auditId = $audit->auditId;
     // this must be required for retransmission in case of error
     $messaging->persist();
     $efax = new eFaxOutbound();
     $url = Zend_Registry::get('config')->healthcloud->eFax->outboundUrl;
     $url .= '?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey;
     $efax->setUrl($url);
     $efax->setTransmissionId($sourceData['transmissionId']);
     $efax->setNoDuplicate(eFaxOutbound::NO_DUPLICATE_ENABLE);
     $efax->setDispositionMethod('POST');
     // use the default disposition URL
     $dispositionUrl = Zend_Registry::get('config')->healthcloud->eFax->dispositionUrl;
     $efax->setDispositionUrl($dispositionUrl);
     //$efax->setDispositionMethod('EMAIL');
     //$efax->addDispositionEmail('Arthur Layese','*****@*****.**');
     foreach ($sourceData['recipients'] as $recipient) {
         if ($messaging->resend && strlen($messaging->faxNumber) > 9) {
             // supersedes fax number from messaging
             $recipient['fax'] = $messaging->faxNumber;
         }
         $efax->addRecipient($recipient['fax'], $recipient['name'], $recipient['company']);
     }
     foreach ($sourceData['files'] as $file) {
         $efax->addFile($file['contents'], $file['type']);
     }
     $ret = $efax->send();
     if (!$ret) {
         $messaging->status = 'Fax Error';
         $messaging->note = implode(PHP_EOL, $efax->getErrors());
     } else {
         $messaging->docid = $efax->getDocId();
         $messaging->status = 'Fax Sent';
         $messaging->note = '';
     }
     if ($messaging->resend) {
         $messaging->resend = 0;
     }
     $messaging->retries++;
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->persist();
     return true;
 }
 /**
  * Test lockout on multiple failed authentications
  */
 public function testLockout()
 {
     // if not enabled, do not run remaining tests
     if (!$this->esig_enabled) {
         return null;
     }
     // doesn't matter what we call here, just need 3 failed attempts
     // NOTE the number of failed attempts must be changed if there is
     //      a change in the electronic signature definition of the
     //      maximum number of attempts before lockout
     $result = $this->ktapi->create_folder(1, 'New test api folder');
     $this->assertEqual($result['status_code'], 1);
     $result = $this->ktapi->create_folder(1, 'New test api folder');
     $this->assertEqual($result['status_code'], 1);
     $result = $this->ktapi->create_folder(1, 'New test api folder');
     $this->assertEqual($result['status_code'], 1);
     // fourth attempt to check lockout message returned
     $result = $this->ktapi->create_folder(1, 'New test api folder');
     $this->assertEqual($result['status_code'], 1);
     $eSignature = new ESignature('api');
     $this->assertTrue($result['message'] == $eSignature->getLockMsg());
     // force reset of the lockout so that remaining tests can run :)
     unset($_SESSION['esignature_attempts']);
     unset($_SESSION['esignature_lock']);
 }
Exemplo n.º 5
0
 function editSignItemsAction()
 {
     $eSigIds = Zend_Json::decode($this->_getParam('electronicSignatureIds'));
     if (strlen($eSigIds) <= 0) {
         $msg = __('No selected signature.');
         throw new Exception($msg);
     }
     $eSigIds = explode(',', $eSigIds);
     $signature = $this->_getParam('signature');
     foreach ($eSigIds as $eSigId) {
         if (strlen($eSigId) <= 0) {
             continue;
         }
         $esig = new ESignature();
         $esig->eSignatureId = (int) $eSigId;
         $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;
         $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
         $json->suppressExit = true;
         try {
             $esig->sign($obj, $signature);
         } catch (Exception $e) {
             $this->getResponse()->setHttpResponseCode(500);
             $json->direct(array('error' => $e->getMessage()));
             return;
         }
         $esig->persist();
         $obj->populate();
         $obj->eSignatureId = $esig->eSignatureId;
         $obj->persist();
     }
 }
Exemplo n.º 6
0
 public function processForwardForSigningAction()
 {
     $providerId = (int) $this->_getParam('providerId');
     $ormClass = $this->_getParam('ormClass');
     $ormId = $this->_getParam('ormId');
     $data = false;
     $esign = new ESignature();
     $esign->objectClass = $ormClass;
     $esign->objectId = $ormId;
     $esign->populateByObject();
     if ($esign->signingUserId > 0) {
         $data = true;
         $esign->signingUserId = $providerId;
         $esign->persist();
     }
     /*if (class_exists($ormClass)) {
     			$orm = new $ormClass();
     			$primaryKeys = $orm->_primaryKeys;
     			$key = $primaryKeys[0];
     			$orm->$key = $ormId;
     			$orm->populate();
     			if ($orm instanceof Document && $orm->signatureNeeded()) {
     				ESignature::createSignatureEntry($orm,$providerId);
     			}
     			$data = true;
     		}*/
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 10
0
 /**
  * Attempts authentication of the signature
  *
  * @author KnowledgeTree Team
  * @access private
  * @param string $username The user's username
  * @param string $password The user's password
  * @param string $comment A comment on the action performed
  * @param string $action The action performed
  * @param string $details Details about the action performed
  * @return bool True if authenticated | False if rejected
  */
 private function _authenticateSignature($username, $password, $comment, $action, $details)
 {
     $eSignature = new ESignature('api');
     $result = $eSignature->sign($username, $password, $comment, $action, $details);
     if (!$result) {
         $this->esig_error = $eSignature->getError();
     }
     return $result;
 }
 function templateAction()
 {
     $clinicalNoteId = $this->_getParam('clinicalNoteId', 0);
     $revisionId = (int) $this->_getParam('revisionId');
     $cn = new ClinicalNote();
     $cn->clinicalNoteId = (int) $clinicalNoteId;
     $cn->populate();
     if ($revisionId > 0) {
         $cn->revisionId = $revisionId;
     }
     $this->_cn = $cn;
     $templateId = $cn->clinicalNoteTemplateId;
     assert('$templateId > 0');
     $cnTemplate = $cn->clinicalNoteDefinition->clinicalNoteTemplate;
     $this->_form = new WebVista_Form(array('name' => 'cn-template-form'));
     $this->_form->setWindow('dummyWindowId');
     $this->_form->setAction(Zend_Registry::get('baseUrl') . "clinical-notes-form.raw/process");
     $cnXML = simplexml_load_string($cnTemplate->template);
     $this->_buildForm($cnXML);
     $this->_form->addElement($this->_form->createElement('hidden', 'clinicalNoteId', array('value' => (int) $cn->clinicalNoteId)));
     $formData = array();
     $this->_form->removeElement('ok');
     $element = $this->_form->createElement('hidden', 'clinicalNoteOKId', array('value' => 'OK'));
     $this->_form->addElement($element);
     if ($revisionId > 0) {
         //$this->_form->removeElement('ok');
         $this->_form->removeElement('clinicalNoteOKId');
     }
     $this->_form->addElement($this->_form->createElement('hidden', 'revisionId', array('value' => (int) $revisionId)));
     $db = Zend_Registry::get('dbAdapter');
     $cndSelect = $db->select()->from('genericData')->where("objectClass = 'ClinicalNote'")->where('objectId = ?', (int) $cn->clinicalNoteId);
     if ($revisionId > 0) {
         $cndSelect->where('revisionId = ?', (int) $revisionId);
     }
     trigger_error($cndSelect->__toString(), E_USER_NOTICE);
     foreach ($db->query($cndSelect)->fetchAll() as $row) {
         $formData[ClinicalNote::encodeNamespace($row['name'])] = $row['value'];
     }
     if ((int) $cn->eSignatureId > 0) {
         // On signed notes generic data is shown
         //$this->_form->removeElement('ok');
         $this->_form->removeElement('clinicalNoteOKId');
         $esig = new ESignature();
         $esig->eSignatureId = $cn->eSignatureId;
         $esig->populate();
         $signPerson = new Person();
         $signPerson->personId = $esig->signingUserId;
         $signPerson->populate();
         $person = new Person();
         $person->personId = $esig->signingUserId;
         $person->populate();
         $this->view->signatureInfo = "Signed on: " . $esig->signedDateTime . " by: " . $person->firstName . ' ' . $person->lastName . ' ' . $person->suffix;
         $element = $this->_form->createElement('hidden', 'clinicalNoteSignatureId', array('value' => $this->view->signatureInfo));
         $this->_form->addElement($element);
     } else {
         // on unsigned notes NSDR is shown but a warning also needs to appear that says data has changed since last save if generic data != NSDR data
         if ((string) $cnXML->attributes()->useNSDR && (string) $cnXML->attributes()->useNSDR == 'true') {
             $nsdrData = ClinicalNote::getNSDRData($cnXML, $cn, $revisionId);
             if ($formData != $nsdrData) {
                 $msg = __('Data has been changed since last save');
                 $this->_form->addElement($this->_form->createElement('hidden', 'dataChangedId', array('value' => $msg)));
             }
             $formData = $nsdrData;
         }
     }
     $this->_form->populate($formData);
     $this->view->form = $this->_form;
 }