public function processEditSubscriptionAction() { $personId = (int) $this->_getParam('personId'); $subscribe = (bool) $this->_getParam('subscribe'); $handlerId = (int) $this->_getParam('handlerId'); $handlerPatient = new HealthStatusHandlerPatient(); $handlerPatient->personId = $personId; $handlerPatient->healthStatusHandlerId = $handlerId; if (!$subscribe) { // add handler to handlerPatient $handlerPatient->setPersistMode(WebVista_Model_ORM::DELETE); } $handlerPatient->persist(); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(true); }
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; }