public static function generateVitalSignsTemplateKeyValue($vitalSignTemplateId = 1)
 {
     $vitalSignTemplate = new self();
     $vitalSignTemplate->vitalSignTemplateId = $vitalSignTemplateId;
     $vitalSignTemplate->populate();
     $vitals = array();
     try {
         $template = new SimpleXMLElement($vitalSignTemplate->template);
         foreach ($template as $vital) {
             $title = (string) $vital->attributes()->title;
             $vitals[$title] = (string) $vital->attributes()->label;
         }
     } catch (Exception $e) {
         WebVista::debug($e->getMessage());
     }
     return $vitals;
 }
 public static function refillRequestActionHandler(Audit $auditOrm, array $dataSourceData)
 {
     if (!count($dataSourceData) > 0) {
         WebVista::debug('Received an empty datasource');
         return false;
     }
     $orm = new GeneralAlert();
     $orm->populateWithArray($dataSourceData);
     $orm->persist();
     return true;
 }
 public function persist()
 {
     if ($this->number_id > 0 && $this->_isv2x()) {
         // check if 2.x
         WebVista::debug('Unable to alter because 2.x phone number detected');
         return false;
     }
     if ($this->_persistMode != WebVista_Model_ORM::DELETE && (int) $this->displayOrder <= 0) {
         $this->displayOrder = self::nextDisplayOrder($this->personId);
     }
     return parent::persist();
 }
    public function persist($single = true)
    {
        if ($single) {
            return parent::persist();
        }
        $db = Zend_Registry::get('dbAdapter');
        if ($this->_persistMode == WebVista_Model_ORM::DELETE) {
            $sql = 'DELETE FROM `' . $this->_table . '` WHERE (`guid` = ' . $db->quote($this->guid) . ')';
            $db->query($sql);
            return $this;
        }
        if (!strlen($this->guid) > 0) {
            $this->guid = str_replace('-', '', NSDR::create_guid());
        }
        // Multiple fee schedule cannot be set for the same insurance programs for the same dates of service
        if ($this->hasConflicts()) {
            $error = __('Please choose different insurance programs or date of service.');
            throw new Exception($error);
        }
        if (!$this->dateObsolete || $this->dateObsolete == '0000-00-00') {
            $this->dateObsolete = $this->dateOfServiceEnd;
        }
        $updates = array();
        $fields = array();
        $values = array();
        $columns = array('name', 'guid', 'insuranceProgramIds', 'dateOfServiceStart', 'dateOfServiceEnd', 'procedureCode', 'fee', 'dateObsolete');
        foreach ($columns as $col) {
            $fields[$col] = '`' . $col . '`';
            $values[$col] = $db->quote($this->{$col});
            $updates[$col] = $fields[$col] . ' = ' . $values[$col];
        }
        $values['procedureCode'] = '`code`';
        unset($updates['guid']);
        unset($updates['procedureCode']);
        unset($updates['fee']);
        unset($updates['dateObsolete']);
        // name, guid, insuranceProgramIds, dateOfServiceStart, dateOfServiceEnd
        $sql = 'INSERT INTO `feeSchedules` (' . implode(', ', $fields) . ')
				SELECT ' . implode(', ', $values) . ' FROM procedureCodesCPT
			ON DUPLICATE KEY UPDATE ' . implode(', ', $updates);
        WebVista::debug($sql);
        $db->query($sql);
        return $this;
    }
 public function hasConflicts()
 {
     $db = Zend_Registry::get('dbAdapter');
     $ret = false;
     $dateStart = $db->quote($this->dateStart);
     $dateEnd = $db->quote($this->dateEnd);
     $sqlSelect = $db->select()->from($this->_table)->where('guid != ' . $db->quote($this->guid))->where('(' . $dateStart . ' >= dateStart AND ' . $dateStart . ' <= dateEnd) OR (' . $dateEnd . ' >= dateStart AND ' . $dateEnd . ' <= dateEnd)');
     $orWhere = array();
     foreach (explode(',', $this->insuranceProgramIds) as $ip) {
         $ip = (int) $ip;
         if (!$ip > 0) {
             continue;
         }
         $orWhere[] = "`insuranceProgramIds` LIKE '%{$ip}%'";
     }
     if (isset($orWhere[0])) {
         $sqlSelect->where(implode(' OR ', $orWhere));
     }
     $sqlSelect->limit(1);
     WebVista::debug($sqlSelect->__toString());
     if ($row = $db->fetchRow($sqlSelect)) {
         $ret = true;
     }
     return $ret;
 }