protected function _doProcess(GeneralAlertHandler $handler, Audit $audit) { $handlerName = Handler::normalizeHandlerName($handler->name); $classHandlerObject = $handlerName . 'GeneralAlertHandlerObject'; if (!parent::isParentOf($classHandlerObject, 'GeneralAlertHandlerObjectAbstract')) { trigger_error($classHandlerObject . ' is not an instance of GeneralAlertHandlerObjectAbstract', E_USER_NOTICE); return false; } $ret = false; if (call_user_func_array(array($classHandlerObject, 'matchAudit'), array($audit))) { do { $classDatasource = $handlerName . 'GeneralAlertDatasource'; if (!parent::isParentOf($classDatasource, 'GeneralAlertDatasourceAbstract')) { trigger_error($classDatasource . ' is not an instance of GeneralAlertDatasourceAbstract', E_USER_NOTICE); break; } try { $data = call_user_func_array(array($classDatasource, 'sourceData'), array($audit)); } catch (Exception $e) { trigger_error('Exception error (' . $e->getCode() . '): ' . $e->getMessage(), E_USER_NOTICE); break; } $ret = true; if (!strlen($handler->template) > 0) { $handler->template = $handler->generateDefaultTemplate(); } foreach ($data as $row) { $message = TemplateXSLT::render($row, $handler->template); $generalAlert = new GeneralAlert(); $generalAlert->message = $message; $generalAlert->urgency = 'Med'; $generalAlert->status = 'new'; $generalAlert->dateTime = date('Y-m-d H:i:s'); if (isset($row['teamId'])) { $generalAlert->teamId = $row['teamId']; } if (isset($row['signingUserId'])) { $generalAlert->userId = $row['signingUserId']; } if (isset($row['objectId'])) { $generalAlert->objectId = $row['objectId']; } if (isset($row['objectClass'])) { $generalAlert->objectClass = $row['objectClass']; } $generalAlert->persist(); } } while (false); } return $ret; }
protected function _doProcess(Handler $handler, Audit $audit) { $ret = false; $handlerName = Handler::normalizeHandlerName($handler->name); $classConditionHandler = $handlerName . 'ConditionHandler'; if (!parent::isParentOf($classConditionHandler, 'DataIntegrationConditionHandlerAbstract')) { return false; } if (call_user_func_array(array($classConditionHandler, 'matchAudit'), array($audit))) { do { $classDatasource = $handlerName . 'DataIntegrationDatasource'; if (!parent::isParentOf($classDatasource, 'DataIntegrationDatasourceAbstract')) { return false; } $data = call_user_func_array(array($classDatasource, 'sourceData'), array($audit)); switch ($handler->direction) { case 'INCOMING': $classAction = $handlerName . 'DataIntegrationAction'; if (!parent::isParentOf($classAction, 'DataIntegrationActionAbstract')) { return false; } $ret = call_user_func_array(array($classAction, 'act'), array($audit, $data)); break; case 'OUTGOING': $classDestination = $handlerName . 'DataIntegrationDestination'; if (!parent::isParentOf($classDestination, 'DataIntegrationDestinationAbstract')) { return false; } $template = new DataIntegrationTemplate(); $template->dataIntegrationTemplateId = $handler->dataIntegrationTemplateId; $template->populate(); $ret = call_user_func_array(array($classDestination, 'transmit'), array($audit, $template)); // temporarily set to true, transmit() skeleton does not provide boolean return $ret = true; break; } } while (false); } return $ret; }
public function getNormalizedName() { return Handler::normalizeHandlerName($this->name); }
protected function _isValidConditionObject() { $type = $this->_handler->handlerType; $handlerName = Handler::normalizeHandlerName($this->_handler->name); $conditionObject = $this->_handler->conditionObject; if (!strlen($conditionObject) > 0) { return __('Condition object is required'); } eval($conditionObject); $ret = true; do { $classConditionHandler = $handlerName . 'ConditionHandler'; if (!ProcessAlert::isParentOf($classConditionHandler, 'DataIntegrationConditionHandlerAbstract')) { $ret = __($classConditionHandler . ' does not exists or not an instance of DataIntegrationConditionHandlerAbstract'); break; } /*$classDatasource = $handlerName.'DataIntegrationDatasource'; if (!ProcessAlert::isParentOf($classDatasource,'DataIntegrationDatasourceAbstract')) { $ret = __($classDatasource.' does not exists or not an instance of DataIntegrationDatasourceAbstract'); break; } // code below is for HL7 only if ($type !== Handler::HANDLER_TYPE_HL7) { break; } $classAction = $handlerName.'DataIntegrationAction'; if (!ProcessAbstract::isParentOf($classAction,'DataIntegrationActionAbstract')) { $ret = __($classAction.' does not exists or not an instance of DataIntegrationActionAbstract'); break; } $classDestination = $handlerName.'DataIntegrationDestination'; if (!ProcessAbstract::isParentOf($classDestination,'DataIntegrationDestinationAbstract')) { $ret = __($classDestination.' does not exists or not an instance of DataIntegrationDestinationAbstract'); break; }*/ } while (false); return $ret; }
public static function generateTestTetanus() { $objects = array(); $person = new Person(); $person->last_name = 'ClearHealth'; $person->first_name = 'Test'; $person->middle_name = 'I'; $person->active = 1; $person->persist(); $objects['person'] = $person; $patient = new Patient(); $patient->person->_cascadePersist = false; // to avoid persist() calls on person $patient->person_id = $person->person_id; $patient->recordNumber = 1000; $patient->persist(); $objects['patient'] = $patient; $medication = new Medication(); $medication->_shouldAudit = false; // do not audit $medication->hipaaNDC = 'hipaaNDC'; $medication->personId = $patient->person_id; $medication->persist(); $objects['medication'] = $medication; $audit = new Audit(); $audit->_ormPersist = true; $audit->objectClass = get_class($medication); $audit->objectId = $medication->medicationId; $audit->dateTime = date('Y-m-d H:i:s'); $audit->type = WebVista_Model_ORM::REPLACE; $audit->userId = (int) Zend_Auth::getInstance()->getIdentity()->personId; $audit->persist(); $objects['audit'] = $audit; $handler = new HealthStatusHandler(); $handler->name = 'Tetanus Shots Handler ' . NSDR::create_guid(); $handler->active = 1; $handler->timeframe = '+1 month'; //$handler->condition = $audit->auditId; $handlerName = Handler::normalizeHandlerName($handler->name); $handler->handlerObject = <<<EOL class {$handlerName}HealthStatusHandlerObject extends HealthStatusHandlerObjectAbstract { \t//abstract requires at least this method \tpublic static function matchAudit(HealthStatusHandler \$handler,Audit \$auditOrm) { \t\t// check if the patientId of the item referenced by the audit is subscribed to the handler, if not return false (no match) \t\t\$objectClass = \$auditOrm->objectClass; \t\t\$obj = new \$objectClass(); \t\tforeach (\$obj->_primaryKeys as \$key) { \t\t\t\$obj->\$key = \$auditOrm->objectId; \t\t} \t\t\$obj->populate(); \t\t\$patientId = \$obj->personId; \t\tif (!HealthStatusHandlerPatient::isPatientSubscribed(\$handler->healthStatusHandlerId,\$patientId)) { \t\t\treturn false; \t\t} \t\tif (\$auditOrm->objectClass == '{$audit->objectClass}' && \$auditOrm->type == '{$audit->type}') { \t\t\treturn true; \t\t} \t\treturn false; \t} \tpublic static function fulfill(HealthStatusHandler \$handler,\$patientId) { \t\t// fulfill sees if current patient has any open alerts linked to this handler \t\t\$alert = new HealthStatusAlert(); \t\t\$alert->populateByHandlerPatientId(\$handler->healthStatusHandlerId,\$patientId); \t\t// if there are open alerts then calls patientMatch again \t\tif (strlen(\$alert->status) > 0) { \t\t\t// if patientMatch returns FALSE then marks alerts as fulfilled if patientMatch return non-false alerts stay as is \t\t\t// sees if any alerts exist for the patient that are for this handler and marks then as fulfilled if the same condition in patientMatch is reversed \t\t\tif (self::patientMatch(\$handler,\$patientId) === false) { \t\t\t\t\$alert->status = 'fulfilled'; \t\t\t\t\$alert->persist(); \t\t\t} \t\t} \t} \tpublic static function patientMatch(HealthStatusHandler \$handler,\$patientId) { \t\t// check if the patient does not have any record of a tetanus immunization (preferably by using NSDR) \t\t// if it has, add the timeframe to the date of that immunization and check if that date is greater than today, if so then return true \t\t// \$immunization = NSDR::populate(\$patientId.'::com.clearhealth.immunization'); \t\t// temporarily superseded NSDR \t\t\$alert = new HealthStatusAlert(); \t\t\$alert->populateByHandlerPatientId(\$handler->healthStatusHandlerId,\$patientId); \t\tif (!strlen(\$alert->status) > 0) { \t\t\t// no existing alert, return true \t\t\treturn true; \t\t} \t\t// would test to see if the date of a given patients last tetanus shot plus the timeframe is less than today \t\t// if (strtotime(\$handler->timeframe,strtotime(\$alert->dateTime)) < strtotime(date('m/d/Y h:i A',strtotime('+1 month')))) { \t\tif (\$alert->status == 'active') { \t\t\tif (strtotime(\$alert->dateDue) < strtotime(date('m/d/Y h:i A',strtotime('+5 weeks')))) { \t\t\t\t//self::fulfill(\$handler,\$patientId); \t\t\t\treturn false; \t\t\t} \t\t\t// patientMatch checks if patient 1234 has NOT had a tetanus when date of last tetanus + timeframe < today and generates an alert \t\t\treturn true; \t\t} \t\t/* \$alert->lastOccurence \t\tif (\$alert->status == 'active' || \$alert->status == 'fulfilled' || \$alert->status == 'ignored') { \t\t\t// would not match if patient already has an active, fulfilled or ignored alert \t\t\treturn false; \t\t} \t\t*/ \t\treturn true; \t} } EOL; $handler->datasource = $handler->generateDefaultDatasource(); $handler->template = $handler->generateDefaultTemplate(); $handler->persist(); $objects['healthStatusHandler'] = $handler; // subscribe patient to handler $handlerPatient = new HealthStatusHandlerPatient(); $handlerPatient->healthStatusHandlerId = $handler->healthStatusHandlerId; $handlerPatient->personId = $patient->personId; $handlerPatient->persist(); $objects['healthStatusHandlerPatient'] = $handler; return $objects; }
protected function _doDailyProcess() { try { $cacheCodeObjects = Zend_Registry::get('cacheCodeObjects'); } catch (Exception $e) { $cacheCodeObjects = array(); } $handlerPatient = new HealthStatusHandlerPatient(); $handlerPatientIterator = $handlerPatient->getIterator(); foreach ($handlerPatientIterator as $row) { $handler = $row->healthStatusHandler; $patient = $row->person; $patientId = $patient->personId; $handlerObject = $handler->handlerObject; if (!strlen($handlerObject) > 0) { $handlerObject = $handler->generateDefaultHandlerObject(); } $md5 = md5($handlerObject); if (!in_array($md5, $cacheCodeObjects)) { $cacheCodeObjects[] = $md5; eval($handlerObject); // TODO: needs to be validated } $datasource = $handler->datasource; if (!strlen($datasource) > 0) { $datasource = $handler->generateDefaultDatasource(); } $md5 = md5($datasource); if (!in_array($md5, $cacheCodeObjects)) { $cacheCodeObjects[] = $md5; eval($datasource); // TODO: needs to be validated } $handlerName = Handler::normalizeHandlerName($handler->name); $classHandlerObject = $handlerName . 'HealthStatusHandlerObject'; if (!parent::isParentOf($classHandlerObject, 'HealthStatusHandlerObjectAbstract')) { trigger_error($classHandlerObject . ' is not an instance of HealthStatusHandlerObjectAbstract', E_USER_NOTICE); continue; } $retPatientMatch = call_user_func_array(array($classHandlerObject, 'patientMatch'), array($handler, $patientId)); if ($retPatientMatch !== false) { $classHealthStatusDatasource = $handlerName . 'HealthStatusDatasource'; if (!parent::isParentOf($classHealthStatusDatasource, 'HealthStatusDatasourceAbstract')) { trigger_error($classHealthStatusDatasource . ' is not an instance of HealthStatusDatasourceAbstract', E_USER_NOTICE); continue; } try { $retSourcedata = call_user_func_array(array($classHealthStatusDatasource, 'sourceData'), array($patientId, $retPatientMatch)); } catch (Exception $e) { trigger_error('Exception error (' . $e->getCode() . '): ' . $e->getMessage(), E_USER_NOTICE); continue; } if (!strlen($handler->template) > 0) { $handler->template = $handler->generateDefaultTemplate(); } $message = TemplateXSLT::render($retSourcedata, $handler->template); $healthStatusAlert = new HealthStatusAlert(); $healthStatusAlert->message = $message; $healthStatusAlert->status = 'active'; $healthStatusAlert->personId = $patientId; $healthStatusAlert->healthStatusHandlerId = $handler->healthStatusHandlerId; $healthStatusAlert->dateDue = date('Y-m-d H:i:s', strtotime($handler->timeframe)); $healthStatusAlert->persist(); } else { $retFulfill = call_user_func_array(array($classHandlerObject, 'fulfill'), array($handler, $patientId)); } } Zend_Registry::set('cacheCodeObjects', $cacheCodeObjects); }
public static function generateUserLoggedOut() { $objects = self::_generatePatient(); $handler = new GeneralAlertHandler(); $handler->name = 'Logout Handler ' . NSDR::create_guid(); $handler->active = 1; $handler->condition = 0; $handlerName = Handler::normalizeHandlerName($handler->name); $handler->handlerObject = <<<EOL class {$handlerName}GeneralAlertHandlerObject extends GeneralAlertHandlerObjectAbstract { \t//abstract requires at least this method \tpublic static function matchAudit(Audit \$auditOrm) { \t\tif (\$auditOrm->objectClass == 'Logout' && \$auditOrm->type == '1') { \t\t\treturn true; \t\t} \t\treturn false; \t} } EOL; $handler->datasource = <<<EOL class {$handlerName}GeneralAlertDatasource extends GeneralAlertDatasourceAbstract { \t//abstract requires at least this method \tpublic static function sourceData(Audit \$audit) { \t\t\$eSignIterator = new ESignatureIterator(); \t\t\$eSignIterator->setFilter(\$audit->userId,'signList'); \t\t\$ret = array(); \t\tforeach (\$eSignIterator as \$eSign) { \t\t\t\$objectClass = \$eSign->objectClass; \t\t\t\$obj = new \$objectClass(); \t\t\tforeach (\$obj->_primaryKeys as \$key) { \t\t\t\t\$obj->\$key = \$eSign->objectId; \t\t\t} \t\t\t\$obj->populate(); \t\t\t\$personId = \$obj->personId; \t\t\t\$patient = new Patient(); \t\t\t\$patient->personId = \$personId; \t\t\t\$patient->populate(); \t\t\t\$teamId = \$patient->teamId; \t\t\t\$row = array(); \t\t\t\$row['teamId'] = \$teamId; \t\t\t\$row['signingUserId'] = \$eSign->signingUserId; \t\t\t\$row['objectId'] = \$eSign->objectId; \t\t\t\$row['objectClass'] = \$eSign->objectClass; \t\t\t\$ret[] = \$row; \t\t} \t\treturn \$ret; \t} } EOL; $handler->template = $handler->generateDefaultTemplate(); $handler->persist(); $objects['generalAlertHandler'] = $handler; return $objects; }