protected function _populateHandlers() { $this->_handlers = array(); $handler = new HealthStatusHandler(); $db = Zend_Registry::get('dbAdapter'); $dbSelect = $db->select()->from($handler->_table)->where('active = 1'); $handlerIterator = $handler->getIterator($dbSelect); foreach ($handlerIterator as $item) { $this->_evaluateCodes($item); $this->_handlers[] = $item; } }
public function generateDefaultCodesAction() { $code = $this->_getParam('code'); $handlerName = $this->_getParam('handlerName'); $condition = (int) $this->_getParam('condition'); $healthStatusHandler = new HealthStatusHandler(); $healthStatusHandler->name = $handlerName; $healthStatusHandler->condition = $condition; $data = ''; switch ($code) { case 'handlerObject': $data = $healthStatusHandler->generateDefaultHandlerObject(); break; case 'datasource': $data = $healthStatusHandler->generateDefaultDatasource(); break; case 'template': $data = $healthStatusHandler->generateDefaultTemplate(); break; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
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; }
public function testTetanusShotsFulfillWithAudit() { $this->_objects = HealthStatusHandler::generateTestTetanus(); $objects = array(); $timeTrigger = date('h:i A', strtotime('-10 minutes')); $processHSA = new ProcessHSA($timeTrigger); $process = Processingd::getInstance(); $process->clearProcesses(); $process->addProcess($processHSA); $process->startProcessing(false); $audit = new Audit(); $audit->_ormPersist = true; $audit->objectClass = get_class($this->_objects['medication']); $audit->objectId = $this->_objects['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; $time = date('h:i A', strtotime('-2 minutes')); // advance the time to 2 minutes due to fast processing $processHSA->setCurrentTime($time); $process->clearProcesses(); $process->addProcess($processHSA); $process->startProcessing(false); $healthStatusAlert = new HealthStatusAlert(); $healthStatusAlert->populateByHandlerPatientId($this->_objects['healthStatusHandler']->healthStatusHandlerId, $this->_objects['patient']->personId); $objects['healthStatusAlert'] = $healthStatusAlert; $this->_cleanUpObjects($objects); $this->assertTrue(strlen($healthStatusAlert->status) > 0, 'No alert created'); $this->assertEquals($healthStatusAlert->status, 'fulfilled', 'Alert is not fulfilled'); $this->assertEquals(date('Y-m-d', strtotime($healthStatusAlert->dateDue)), date('Y-m-d', strtotime('+1 month')), 'Due date is invalid'); }
public function generateTestDataAction() { HealthStatusHandler::generateTestData(); echo 'Done'; die; }