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 viewSubscribedPatientsAction()
 {
     $handlerId = (int) $this->_getParam('handlerId');
     $handlerPatient = new HealthStatusHandlerPatient();
     $handlerPatientIterator = $handlerPatient->getIteratorByHandlerId($handlerId);
     $rows = array();
     foreach ($handlerPatientIterator as $row) {
         $data = array();
         $data[] = $row->person->person->getDisplayName();
         $rows[$row->personId] = $data;
     }
     $this->view->rows = $rows;
     $this->render('view-subscribed-patients');
 }
Example #3
0
 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);
 }