public function persist() { $db = Zend_Registry::get('dbAdapter'); $reportBaseId = (int) $this->reportBaseId; if ($this->_persistMode == self::DELETE) { try { $db->delete($this->_table, 'reportBaseId = ' . $reportBaseId); $db->delete('reportQueries', 'reportBaseId = ' . $reportBaseId); $db->delete('reportViews', 'reportBaseId = ' . $reportBaseId); return true; } catch (Exception $e) { return false; } } $data = $this->toArray(); unset($data['reportFilters']); unset($data['reportQueries']); unset($data['reportViews']); if (strlen($data['guid']) <= 0) { $data['guid'] = uniqid('', true); } if ($reportBaseId > 0) { $ret = $db->update($this->_table, $data, 'reportBaseId = ' . $reportBaseId); } else { $this->reportBaseId = WebVista_Model_ORM::nextSequenceId(); $data['reportBaseId'] = $this->reportBaseId; $ret = $db->insert($this->_table, $data); } return $ret; }
public function persist() { $db = Zend_Registry::get('dbAdapter'); $clinicalNoteTemplateId = (int) $this->clinicalNoteTemplateId; $data = $this->toArray(); if ($clinicalNoteTemplateId > 0) { $ret = $db->update($this->_table, $data, 'clinicalNoteTemplateId = ' . $clinicalNoteTemplateId); } else { $this->clinicalNoteTemplateId = WebVista_Model_ORM::nextSequenceId(); $data['clinicalNoteTemplateId'] = $this->clinicalNoteTemplateId; $ret = $db->insert($this->_table, $data); } return $ret; }
public function persist() { $db = Zend_Registry::get('dbAdapter'); $reportViewId = (int) $this->reportViewId; $data = $this->toArray(); unset($data['reportBase']); if ($reportViewId > 0) { $ret = $db->update($this->_table, $data, 'reportViewId = ' . $reportViewId); } else { $this->reportViewId = WebVista_Model_ORM::nextSequenceId(); $data['reportViewId'] = $this->reportViewId; $data['viewOrder'] = $this->_getNextViewOrder(); $ret = $db->insert($this->_table, $data); } return $ret; }
public function persist() { if ($this->_persistMode == WebVista_Model_ORM::DELETE) { return parent::persist(); } $db = Zend_Registry::get('dbAdapter'); $dataIntegrationTemplateId = (int) $this->dataIntegrationTemplateId; $data = $this->toArray(); if ($dataIntegrationTemplateId > 0) { $ret = $db->update($this->_table, $data, 'dataIntegrationTemplateId = ' . $dataIntegrationTemplateId); } else { $this->dataIntegrationTemplateId = WebVista_Model_ORM::nextSequenceId(); $data['dataIntegrationTemplateId'] = $this->dataIntegrationTemplateId; $ret = $db->insert($this->_table, $data); } return $this; }
function addNode($parentId = 0, $newNodeName) { $db = Zend_Registry::get('dbAdapter'); $newNodeId = WebVista_Model_ORM::nextSequenceId(); $db->beginTransaction(); try { $sql = "SELECT @lftVal := lft FROM enumerations WHERE enumerationId = " . (int) $parentId; $db->query($sql); $sql = "UPDATE enumerations SET rgt = rgt + 2 WHERE rgt > @lftVal"; $db->query($sql); $sql = "UPDATE enumerations SET lft = lft + 2 WHERE lft > @lftVal"; $db->query($sql); $sql = "INSERT INTO enumerations(enumerationId, name, parentId, lft, rgt) VALUES({$newNodeId}," . $db->quote($newNodeName) . ", " . (int) $parentId . ",@lftVal + 1, @lftVal + 2)"; $db->query($sql); $db->commit(); } catch (Exception $e) { $db->rollBack(); } }
public static function createRevision($objectClass, $objectId, $revisionId = 0) { $db = Zend_Registry::get('dbAdapter'); $gd = new self(); if ($revisionId <= 0) { $revisionId = self::getUnsignedRevisionId($objectClass, $objectId); } $sqlSelect = $db->select()->from($gd->_table)->where('objectClass = ?', $objectClass)->where('objectId = ?', $objectId)->where('revisionId = ?', $revisionId); //trigger_error($sqlSelect->__toString(),E_USER_NOTICE); if ($rows = $db->fetchAll($sqlSelect)) { $newRevisionId = WebVista_Model_ORM::nextSequenceId(); foreach ($rows as $row) { $gd = new self(); $gd->populateWithArray($row); $gd->genericDataId = 0; $gd->revisionId = $newRevisionId; //trigger_error(print_r($gd->toArray(),true),E_USER_NOTICE); $gd->persist(); } } }
public function persist() { $db = Zend_Registry::get('dbAdapter'); if (!strlen($this->messagingId) > 0) { $this->messagingId = WebVista_Model_ORM::nextSequenceId(); } $db->delete('messaging', 'messagingId=' . $db->quote($this->messagingId)); if ($this->_persistMode != WebVista_Model_ORM::DELETE) { $data = $this->toArray(); foreach ($data as $key => $value) { if (!is_array($value) && strlen($value) > 0) { continue; } unset($data[$key]); } $db->insert('messaging', $data); } if ($this->object !== null) { $this->object->persist(); } return $this; }
public function processNewPatientAction() { $params = $this->_getParam('patient'); $patient = new Patient(); $patient->populateWithArray($params); if (!strlen($patient->recordNumber) > 0) { $patient->recordNumber = WebVista_Model_ORM::nextSequenceId('record_sequence'); } $patient->persist(); $personId = (int) $patient->personId; // save addresses and phones $addresses = $this->_getParam('addresses'); if (is_array($addresses)) { foreach ($addresses as $row) { $address = new Address(); $address->populateWithArray($row); $address->personId = $personId; $address->persist(); } } $phones = $this->_getParam('phones'); if (is_array($phones)) { foreach ($phones as $row) { $phone = new PhoneNumber(); $phone->populateWithArray($row); $phone->personId = $personId; $phone->persist(); } } $ret = array(); $ret['msg'] = 'Record Saved for Patient: ' . ucfirst($patient->firstName) . ' ' . ucfirst($patient->lastName); $ret['personId'] = $personId; $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($ret); }
protected function _dispatch() { file_put_contents('/tmp/smtp.log', "\ndispatched started for filename: {$this->messageFilename}", FILE_APPEND); $contents = file($this->messageFilename); file_put_contents('/tmp/smtp.log', "\ncontents: " . print_r($contents, true), FILE_APPEND); $boundary = null; $boundaryLen = 0; $boundaryStarted = false; $data = array(); $tmpData = array(); $headers = array('subject' => '', 'from' => '', 'to' => '', 'date' => '', 'messageId' => ''); $contentsCtr = count($contents); $subjectStarted = false; for ($i = 0; $i < $contentsCtr; $i++) { $line = trim($contents[$i]); $nextI = $i + 1; if (isset($contents[$nextI]) && preg_match('/^Content-(.*):/i', $line) && ($contents[$nextI][0] == "\t" || $contents[$nextI][0] == ' ')) { $contents[$nextI][0] = ' '; $line .= $contents[$nextI]; $i = $nextI; } if (!$boundaryStarted) { if ($boundary !== null && '--' . $boundary == substr($line, 0, $boundaryLen + 2)) { $boundaryStarted = true; continue; } if (preg_match('/^Subject:(.*)/i', $line, $matches)) { $headers['subject'] = ltrim($matches[1]); $subjectStarted = true; } else { if (preg_match('/^From:(.*)/i', $line, $matches)) { $headers['from'] = ltrim($matches[1]); } else { if (preg_match('/^To:(.*)/i', $line, $matches)) { $headers['to'] = ltrim($matches[1]); } else { if (preg_match('/^Content-Type:(.*)/i', $line, $matches)) { $contentType = ltrim($matches[1]); if (preg_match('/boundary=(.*)/i', $contentType, $matches)) { $boundary = $matches[1]; if (preg_match('/^"(.*)"/', $boundary, $matches)) { // some boundaries are enclosed in "" $boundary = $matches[1]; } $boundaryLen = strlen($boundary); } } else { if (preg_match('/^Date:(.*)/i', $line, $matches)) { $headers['date'] = ltrim($matches[1]); } else { if (preg_match('/^Message-Id:(.*)/i', $line, $matches)) { $headers['messageId'] = ltrim($matches[1]); } else { if (preg_match('/^X-Mailer:(.*)/i', $line, $matches)) { $headers['mailer'] = ltrim($matches[1]); } else { if ($subjectStarted) { $tmpData[] = $line; } } } } } } } } } else { if (substr($line, 0, $boundaryLen + 2) == '--' . $boundary) { if (isset($tmpData[0])) { $data[] = $tmpData; $tmpData = array(); } } else { $tmpData[] = $line; } } } if (isset($tmpData[0])) { $data[] = $tmpData; $tmpData = array(); } $dataContents = array(); $i = 0; foreach ($data as $lines) { $content = ''; $contentTypes = array(); foreach ($lines as $line) { if (preg_match('/^Content-(.*):(.*)/i', $line, $matches)) { $contentTypes['content-' . strtolower($matches[1])] = ltrim($matches[2]); } else { if ($line == '') { $lineStart = true; $lineEnd = true; } else { $content .= $line; } } } if (isset($contentTypes['content-disposition']) && (isset($contentTypes['content-transfer-encoding']) && strtolower($contentTypes['content-transfer-encoding']) == 'base64')) { // temporarily accept base64 encoding that serves as an attachment $tmpData[] = array('contentTypes' => $contentTypes, 'content' => $content); continue; } $dataContents[] = array('contentTypes' => $contentTypes, 'content' => $content); } if (isset($tmpData[0])) { $dataContents = $tmpData; } $recipients = array(); $addresses = explode(',', $headers['to']); $db = Zend_Registry::get('dbAdapter'); foreach ($addresses as $address) { if (preg_match('/<(.*)>/', $address, $matches)) { $address = $matches[1]; } $x = explode('@', $address); $username = $x[0]; $domain = $x[1]; $sqlSelect = $db->select()->from('patient', 'person_id')->where('record_number = ?', $username); $personId = 0; if ($row = $db->fetchRow($sqlSelect)) { $personId = $row['person_id']; } $recipients[] = array('personId' => $personId, 'address' => $address, 'username' => $username, 'domain' => $domain); } file_put_contents('/tmp/smtp.log', "\ndata contents: " . print_r($dataContents, true), FILE_APPEND); foreach ($dataContents as $content) { $contentTypes = $content['contentTypes']; $filename = null; // email has an attachments if (isset($contentTypes['content-disposition']) && (isset($contentTypes['content-transfer-encoding']) && strtolower($contentTypes['content-transfer-encoding']) == 'base64')) { // temporarily accept base64 encoding that serves as an attachment $contentType = $contentTypes['content-type']; // image/jpeg; name="sample-signature.jpeg" $types = explode(';', $contentType); $mimeType = array_shift($types); foreach ($types as $type) { $type = ltrim($type); if (preg_match('/^name="(.*)"/', $type, $matches)) { $filename = '/tmp/' . $matches[1]; break; } } if ($filename === null) { // try to create a random filename with specific extension based on mime type $extension = MimeType::extension($mimeType); $tmpFile = tempnam('/tmp', 'ch30_attach_'); $filename = $tmpFile . '.' . $extension; //rename($tmpFile,$filename); unlink($tmpFile); } $content['content'] = base64_decode($content['content']); // decode the base64 encoded file } foreach ($recipients as $recipient) { $personId = $recipient['personId']; $messagingId = WebVista_Model_ORM::nextSequenceId(); $messaging = array(); $messaging['note'] = 'Email message: ' . $content['content']; $attachmentId = 0; if ($filename !== null) { $attachmentId = WebVista_Model_ORM::nextSequenceId(); $attachment = array(); $attachment['attachmentId'] = $attachmentId; $attachment['attachmentReferenceId'] = md5($headers['messageId']); $attachment['name'] = basename($filename); $attachment['dateTime'] = date('Y-m-d H:i:s', strtotime($headers['date'])); $attachment['mimeType'] = $mimeType; $attachment['md5sum'] = md5($content['content']); $db->insert('attachments', $attachment); $audit = array(); $audit['objectClass'] = 'Attachment'; $audit['objectId'] = $attachment['attachmentId']; $audit['auditValues'] = $attachment; Audit::persistManualAuditArray($audit); $attachmentBlob = array(); $attachmentBlob['attachmentId'] = $attachment['attachmentId']; $attachmentBlob['data'] = $content['content']; $db->insert('attachmentBlobs', $attachmentBlob); $messaging['note'] = 'Scanned document for ' . $recipient['address']; } $messaging['messagingId'] = $messagingId; $messaging['objectType'] = Messaging::TYPE_INBOUND_FAX; $messaging['status'] = 'Fax/Email Received'; $messaging['dateStatus'] = date('Y-m-d H:i:s'); $db->insert('messaging', $messaging); $messagingInboundFax = array(); $messagingInboundFax['messagingId'] = $messaging['messagingId']; $messagingInboundFax['personId'] = $personId; $messagingInboundFax['mrn'] = $recipient['username']; $messagingInboundFax['subject'] = $headers['subject']; $messagingInboundFax['from'] = $headers['from']; $messagingInboundFax['to'] = $recipient['address']; $messagingInboundFax['messageId'] = $headers['messageId']; $messagingInboundFax['attachmentId'] = $attachmentId; $db->insert('messagingInboundFaxes', $messagingInboundFax); $audit = array(); $audit['objectClass'] = 'MessagingInboundFax'; $audit['objectId'] = $messagingInboundFax['messagingId']; $audit['auditValues'] = $messagingInboundFax; Audit::persistManualAuditArray($audit); } } unlink($this->messageFilename); return $this; }
protected function _sendToPayer($claimId, $payerId) { $id = WebVista_Model_ORM::nextSequenceId('claimSequences'); $userId = (int) Zend_Auth::getInstance()->getIdentity()->personId; $iterator = new ClaimLineIterator(); $iterator->setFilters(array('claimId' => (int) $claimId)); $visits = array(); //$discountPayerId = InsuranceProgram::lookupSystemId('Discounts'); // ID of System->Discounts foreach ($iterator as $claimLine) { $oldPayerId = (int) $claimLine->insuranceProgramId; $claimLine->claimLineId = 0; $claimLine->claimId = $id; $claimLine->insuranceProgramId = (int) $payerId; $claimLine->dateTime = date('Y-m-d H:i:s'); $oldBaseFee = (double) $claimLine->baseFee; $visitId = (int) $claimLine->visitId; if (!isset($visits[$visitId])) { $visit = new Visit(); $visit->visitId = $visitId; $visit->populate(); $visits[$visitId] = $visit; } $visit = $visits[$visitId]; // recalculates baseFee for new payer $claimLine->recalculateBaseFee($visit); $newBaseFee = (double) $claimLine->baseFee; $claimLine->persist(); // if new amount billed is less than than last amount billed then a writeoff is added to account for the difference if ($newBaseFee < $oldBaseFee) { $diff = $oldBaseFee - $newBaseFee; // add writeoffs $writeOff = new WriteOff(); $writeOff->personId = (int) $visit->patientId; $writeOff->claimLineId = $claimLine->claimLineId; $writeOff->visitId = $visitId; $writeOff->appointmentId = $visit->appointmentId; $writeOff->amount = $diff; $writeOff->userId = $userId; $writeOff->timestamp = date('Y-m-d H:i:s'); $writeOff->title = ''; $writeOff->payerId = $oldPayerId; $writeOff->persist(); } } }
protected function _processEdit() { $title = $this->_getParam('title'); $message = $this->_getParam('message'); $groupId = (int) $this->_getParam('groupId'); $event = (int) $this->_getParam('event'); $rules = $this->_getParam('rules'); $ret = false; if (is_array($rules)) { $validIds = array(); if ($groupId > 0) { $iterator = new ClaimRuleIterator(); $iterator->setFilters(array('groupId' => $groupId)); foreach ($iterator as $claimRule) { if (!isset($rules[$claimRule->claimRuleId])) { // delete orphaned rule $claimRule->setPersistMode(WebVista_Model_ORM::DELETE); $claimRule->persist(); } else { $validIds[$claimRule->claimRuleId] = $claimRule->claimRuleId; } } } else { $groupId = WebVista_Model_ORM::nextSequenceId(); } foreach ($rules as $claimRuleId => $value) { $claimRule = new ClaimRule(); $claimRule->populateWithArray($value); if (isset($validIds[$claimRuleId])) { $claimRule->claimRuleId = $claimRuleId; } else { $claimRule->claimRuleId = 0; $claimRule->dateTime = date('Y-m-d H:i:s'); } $claimRule->title = $title; $claimRule->message = $message; $claimRule->groupId = $groupId; $claimRule->event = $event; $claimRule->persist(); } $ret = true; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(true); }
public static function persistManualAuditArray(array $data) { $db = Zend_Registry::get('dbAdapter'); $seqTable = Zend_Registry::get('config')->audit->sequence->table; if (!isset($data['auditId']) || !(int) $data['auditId'] > 0) { $data['auditId'] = WebVista_Model_ORM::nextSequenceId($seqTable); } $audit = array(); $audit['auditId'] = (int) $data['auditId']; $audit['objectClass'] = isset($data['objectClass']) ? $data['objectClass'] : ''; $audit['objectId'] = isset($data['objectId']) ? $data['objectId'] : ''; $audit['userId'] = isset($data['userId']) ? $data['userId'] : ''; $audit['patientId'] = isset($data['patientId']) ? $data['patientId'] : ''; $audit['type'] = isset($data['type']) ? $data['type'] : WebVista_Model_ORM::REPLACE; $audit['message'] = isset($data['message']) ? $data['message'] : ''; $audit['dateTime'] = isset($data['dateTime']) ? $data['dateTime'] : date('Y-m-d H:i:s'); $audit['startProcessing'] = isset($data['startProcessing']) ? $data['startProcessing'] : ''; $audit['endProcessing'] = isset($data['endProcessing']) ? $data['endProcessing'] : ''; $audit['ipAddress'] = isset($data['ipAddress']) ? $data['ipAddress'] : '127.0.0.1'; $db->insert('audits', $audit); if (isset($data['auditValues']) && is_array($data['auditValues'])) { foreach ($data['auditValues'] as $key => $value) { if (is_array($value)) { $value = serialize($value); } $auditValue = array(); $auditValue['auditValueId'] = WebVista_Model_ORM::nextSequenceId($seqTable); $auditValue['auditId'] = $audit['auditId']; $auditValue['key'] = $key; $auditValue['value'] = (string) $value; $db->insert('auditValues', $auditValue); } } }
public function buildDefaultGenericData(SimpleXMLElement $xml = null) { if ($xml === null) { if (!strlen($this->clinicalNoteDefinition->clinicalNoteTemplate->template) > 0) { $this->clinicalNoteDefinition->populate(); } $xml = new SimpleXMLElement($this->clinicalNoteDefinition->clinicalNoteTemplate->template); } $revisionId = WebVista_Model_ORM::nextSequenceId(); $nsdrData = array(); if ((string) $xml->attributes()->useNSDR && (string) $xml->attributes()->useNSDR == 'true') { $nsdrData = ClinicalNote::getNSDRData($xml, $this, $revisionId); } $dateTime = date('Y-m-d H:i:s'); foreach ($xml as $question) { foreach ($question as $key => $item) { if ($key != 'dataPoint') { continue; } $namespace = NSDR2::extractNamespace((string) $item->attributes()->namespace); $name = preg_replace('/[-\\.]/', '_', $namespace); $value = ''; if (strlen((string) $item->attributes()->templateText) > 0) { $templateName = (string) $item->attributes()->templateText; $view = Zend_Layout::getMvcInstance()->getView(); $value = $view->action('templated-text', 'template-text', null, array('personId' => $this->personId, 'templateName' => $templateName)); } if ((string) $item->attributes()->default == true) { $value = (string) $item->attributes()->value; } if (isset($nsdrData[$name])) { $value = $nsdrData[$name]; } $gd = new GenericData(); $gd->objectClass = get_class($this); $gd->objectId = $this->clinicalNoteId; $gd->dateTime = $dateTime; $gd->name = $name; $gd->value = $value; $gd->revisionId = $revisionId; $gd->persist(); //trigger_error('PERSISTED:'.print_r($gd->toArray(),true),E_USER_NOTICE); } } return $revisionId; }
protected function _checkTableData($structure, $withSql = true) { $db = Zend_Registry::get('dbAdapter'); $ret = false; $tableName = (string) $structure->attributes()->name; trigger_error("Checking data for table: {$tableName}", E_USER_NOTICE); $rows = array(); foreach ($structure as $row) { if ((string) $row->getName() != 'row') { continue; } $ret = true; $tableColumns = $this->_tables[$tableName]; $primaryKey = null; foreach ($row as $objType => $field) { $fieldName = (string) $field->attributes()->name; if ($objType != 'field' || !array_key_exists($fieldName, $tableColumns)) { continue; } $fieldValue = (string) $field; if ($fieldName == 'guid') { $sqlSelect = $db->select()->from($tableName)->where('guid != ?', '')->where('guid = ?', $fieldValue); if ($guidRow = $db->fetchRow($sqlSelect)) { // data already exists continue 2; // proceed to the outer loop } } if (preg_match('/\\[@lastSequenceId(.*)\\]/', $fieldValue, $matches)) { $key = -1; if (strlen($matches[1]) > 0) { $index = substr($matches[1], 1); if (isset($this->_sequenceIds[$index])) { $key = $index; } } $fieldValue = $this->_sequenceIds[$key]; } $tableColumns[$fieldName] = $fieldValue; if ($this->_tables[$tableName][$fieldName]['Key'] == 'PRI' && !isset($matches[1])) { $primaryKey = $fieldName; } } if ($withSql && $primaryKey !== null) { if (preg_match('/\\[@nextSequenceId(.*)\\]/', $tableColumns[$primaryKey], $matches)) { $tableColumns[$primaryKey] = WebVista_Model_ORM::nextSequenceId(); $key = -1; if (strlen($matches[1]) > 0) { $key = substr($matches[1], 1); } $this->_sequenceIds[$key] = $tableColumns[$primaryKey]; trigger_error('nextSequenceId generated for: ' . $tableName . '.' . $primaryKey, E_USER_NOTICE); } } $rows[] = $tableColumns; } $ctr = count($rows); if ($ctr > 0) { $this->_changes[] = $ctr . ' insert statements to table ' . $tableName; } if (!$withSql) { return $ret; } $columnNames = array(); foreach ($this->_tables[$tableName] as $fieldName => $col) { $columnNames[] = $db->quoteIdentifier($fieldName); } $sql = "INSERT INTO " . $db->quoteTableAs($tableName) . " (" . implode(',', $columnNames) . ") VALUES"; foreach ($rows as $row) { $sql .= PHP_EOL . '(' . $db->quote($row) . '),'; } $sql = substr($sql, 0, -1) . ';' . PHP_EOL; return $sql; }
protected function _checkTableDataRow() { $data = $this->_tdRowData; $db = Zend_Registry::get('dbAdapter'); $tableName = isset($this->_tdData['attribs']['name']) ? $this->_tdData['attribs']['name'] : ''; //trigger_error("Checking data for table: $tableName",E_USER_NOTICE); $rows = array(); $ret = true; $tableColumns = isset($this->_tables[$tableName]) ? $this->_tables[$tableName] : array(); if ($tableColumns === true) { $tableColumns = array(); } $primaryKey = null; $guidRow = null; foreach ($data['data'] as $val) { $fieldName = isset($val['attribs']['name']) ? $val['attribs']['name'] : ''; if (isset($this->_tables[$tableName]) && isset($this->_tables[$tableName][$fieldName]) && $this->_tables[$tableName][$fieldName]['Key'] == 'PRI') { $primaryKey = $fieldName; } $objType = isset($val['name']) ? $val['name'] : ''; if ($objType != 'field' || !array_key_exists($fieldName, $tableColumns)) { continue; } $fieldValue = isset($val['value']) ? $val['value'] : ''; if ($fieldName == 'guid') { $sqlSelect = $db->select()->from($this->_dbName . '.' . $tableName)->where('guid != ?', '')->where('guid = ?', $fieldValue); if ($guidRow = $db->fetchRow($sqlSelect)) { // data already exists if ($this->_withSql && $primaryKey !== null) { if (preg_match('/\\[@nextSequenceId=(\\d+)\\]/', $tableColumns[$primaryKey], $matches)) { $tableColumns[$primaryKey] = $guidRow['enumerationId']; $key = -1; if (strlen($matches[1]) > 0) { $key = $matches[1]; } $this->_sequenceIds[$key] = $tableColumns[$primaryKey]; $this->_existingEnums[$tableColumns[$primaryKey]] = $tableColumns[$primaryKey]; } } } } if (preg_match_all('/\\[@lastSequenceId=(\\d+)\\]/', $fieldValue, $matches)) { $key = -1; if (strlen($matches[1][0]) > 0) { $index = $matches[1][0]; if (isset($this->_sequenceIds[$index])) { $key = $index; } } if (count($matches[1]) > 1) { foreach ($matches[1] as $match) { $index = -1; if (isset($this->_sequenceIds[$match])) { $index = $match; } $fieldValue = preg_replace('/\\[@lastSequenceId=' . $match . '\\]/mi', $this->_sequenceIds[$index], $fieldValue); } } else { $fieldValue = $this->_sequenceIds[$key]; } } $tableColumns[$fieldName] = $fieldValue; } if ($this->_withSql && $primaryKey !== null) { if (preg_match('/\\[@nextSequenceId=(\\d+)\\]/', $tableColumns[$primaryKey], $matches)) { $tableColumns[$primaryKey] = WebVista_Model_ORM::nextSequenceId(); $key = -1; if (strlen($matches[1]) > 0) { $key = $matches[1]; } $this->_sequenceIds[$key] = $tableColumns[$primaryKey]; trigger_error('nextSequenceId generated for: ' . $tableName . '.' . $primaryKey, E_USER_NOTICE); } } if (!isset($this->_tableColumnsCtr[$tableName])) { $this->_tableColumnsCtr[$tableName] = 0; } if (!($guidRow || $tableName == 'enumerationsClosure' && isset($tableColumns['descendant']) && isset($this->_existingEnums[$tableColumns['descendant']]))) { $this->_tableColumnsCtr[$tableName]++; if (!$this->_withSql) { return ''; } //trigger_error(print_r($tableColumns,true)); $row = array(); foreach ($this->_tables[$tableName] as $columnName => $col) { // making sure row columns are in order $row[$columnName] = isset($tableColumns[$columnName]) && is_string($tableColumns[$columnName]) ? $tableColumns[$columnName] : ''; } if ($this->_tdFirstRow) { $this->_tdFirstRow = false; } fwrite($this->_fd, $this->_sqlInsert . "(" . $db->quote($row) . ');'); } }
public function processAddAction() { $username = $this->_getParam('username'); $user = new User(); $user->username = $username; $user->personId = WebVista_Model_ORM::nextSequenceId(); $response = true; if (User::communityEditionPlusEnabled()) { // new user $response = $user->healthCloudActivation(); } if ($response === true) { $user->userId = $user->personId; $user->persist(); $ret = $user->personId; } else { $ret = array('error' => $response); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($ret); }
public static function recalculateClaims(self $visit, $newClaim = false) { $fees = $visit->calculateFees(true); $hasProcedure = false; if ($newClaim) { $claimId = WebVista_Model_ORM::nextSequenceId('claimSequences'); } $copay = $visit->getCopay(); $totalPaid = 0; $personId = (int) $visit->patientId; $userId = (int) Zend_Auth::getInstance()->getIdentity()->personId; $visitId = (int) $visit->visitId; $discountPayerId = InsuranceProgram::lookupSystemId('Discounts'); // ID of System->Discounts $creditPayerId = InsuranceProgram::lookupSystemId('Credit'); // ID of System->Credit $payerId = InsuranceProgram::lookupSystemId('Self Pay'); // ID of System->Self Pay foreach ($fees['details'] as $id => $values) { // update claim or create if not exists $fee = (double) $values['fee']; $feeDiscounted = (double) $values['feeDiscounted']; $claimLine = new ClaimLine(); $claimLine->populateWithPatientProcedure($values['orm'], $visit); if ($newClaim) { $claimLine->claimLineId = 0; $claimLine->claimId = $claimId; } $claimLine->baseFee = $fee; $claimLine->adjustedFee = $feeDiscounted; $claimLine->persist(); $claimLineId = (int) $claimLine->claimLineId; $billable = $feeDiscounted; /*$discount = 0; if ($feeDiscounted > 0) $discount = $fee - $feeDiscounted; if ($discount < 0) $discount = 0;*/ $discount = (double) $values['writeoff']; if ($newClaim && $discount > 0) { // add writeoffs $writeOff = new WriteOff(); $writeOff->personId = $personId; $writeOff->claimLineId = $claimLineId; $writeOff->visitId = $visitId; $writeOff->appointmentId = $visit->appointmentId; $writeOff->amount = $discount; $writeOff->userId = $userId; $writeOff->timestamp = date('Y-m-d H:i:s'); $writeOff->title = 'discount'; $writeOff->payerId = $discountPayerId; $writeOff->persist(); $billable -= $discount; } if ($newClaim && $billable > 0) { foreach ($copay['details'] as $paymentId => $payment) { $amount = (double) $payment->unallocated; if (!$amount > 0) { unset($copay['details'][$paymentId]); continue; } if ($amount > $billable) { $amount = $billable; } $payment->allocated += $amount; $payment->payerId = $payerId; $payment->persist(); $copay['details'][$paymentId] = $payment; $totalPaid += $amount; $postingJournal = new PostingJournal(); $postingJournal->paymentId = (int) $payment->paymentId; $postingJournal->patientId = $personId; $postingJournal->payerId = $payerId; $postingJournal->claimLineId = $claimLineId; $postingJournal->visitId = $visitId; $postingJournal->amount = $amount; $postingJournal->note = 'copay posting'; $postingJournal->userId = $userId; $dateTime = date('Y-m-d H:i:s'); $postingJournal->datePosted = $dateTime; $postingJournal->dateTime = $dateTime; $postingJournal->persist(); $billable -= $amount; if ($billable <= 0) { break; } } } $hasProcedure = true; } if ($newClaim && $copay['total'] > $totalPaid) { // if copay is greater than all claimlines reamining dollars are posted to credit program foreach ($copay['details'] as $paymentId => $payment) { $amount = (double) $payment->unallocated; $payment->allocated += $amount; $payment->persist(); $postingJournal = new PostingJournal(); $postingJournal->paymentId = (int) $payment->paymentId; $postingJournal->patientId = $personId; $postingJournal->payerId = $creditPayerId; $postingJournal->visitId = $visitId; $postingJournal->amount = $amount; $postingJournal->note = 'remaining copay balance'; $postingJournal->userId = $userId; $dateTime = date('Y-m-d H:i:s'); $postingJournal->datePosted = $dateTime; $postingJournal->dateTime = $dateTime; $postingJournal->persist(); } } if (!$hasProcedure) { $visitId = $visit->visitId; $payment = new Payment(); foreach ($payment->getIteratorByVisitId($visitId) as $row) { // If visit has copay then at closing copay should be turned into unallocated payment (not associated with visit). $row->visitId = 0; $row->persist(); } } else { $visit = ClaimRule::checkRules($visit, $fees); } return $visit; }
public function toSQL() { $db = Zend_Registry::get('dbAdapter'); $fields = $this->ormFields(); //var_dump($fields); $sql = ""; if ($this->_persistMode == WebVista_Model_ORM::REPLACE) { $sql = "REPLACE INTO `" . $this->_table . "` SET "; } elseif ($this->_persistMode == WebVista_Model_ORM::INSERT) { $sql = "INSERT INTO `" . $this->_table . "` SET "; } elseif ($this->_persistMode == WebVista_Model_ORM::DELETE) { $sql = "DELETE FROM `" . $this->_table . "` "; } $pWhere = "WHERE 1 "; for ($i = 0, $fieldsCount = count($fields); $i < $fieldsCount; $i++) { $field = $fields[$i]; //echo "setting: " . get_class($this) ." " . $field ."<br />"; $val = $this->__get($field); if (is_object($val)) { if ($val instanceof ORM && $val->_cascadePersist) { $val->setPersistMode($this->_persistMode); $val->persist(); } continue; } elseif (is_array($val)) { foreach ($val as $item) { if ($item instanceof ORM) { $item->persist(); } } continue; } if ($this->_persistMode == WebVista_Model_ORM::DELETE) { if (in_array($field, $this->_primaryKeys) && ($val > 0 || !is_numeric($val) && strlen($val) > 0)) { $pWhere .= " and `{$field}` = '" . preg_replace('/[^0-9_a-z-\\.]/i', '', $val) . "' "; } // code below is just for replace/insert continue; } if (in_array($field, $this->_primaryKeys) && !$val > 0) { $pWhere .= " and `{$field}` = '" . preg_replace('/[^0-9_a-z-\\.]/i', '', $val) . "' "; $seqTable = ""; if (get_class($this) == "Audit" || get_class($this) == "AuditValue") { $seqTable = Zend_Registry::get('config')->audit->sequence->table; } if (get_class($this) == "Audit" || get_class($this) == "AuditValue" || $this->_persistMode != WebVista_Model_ORM::DELETE) { $lastId = WebVista_Model_ORM::nextSequenceId($seqTable); //echo $lastId . "<br />"; //ob_flush(); $this->__set($field, $lastId); $val = $lastId; } /*if ($ordo->_createOwnership) { // add an ownership entry $me =& Me::getInstance(); $myid = $me->get_id(); $this->db->execute("insert into ownership values ($last_id,$myid)"); } if ($ordo->_createRegistry) { // add a ordo_registry entry $me =& Me::getInstance(); $myid = $me->get_id(); $this->db->execute("insert into ordo_registry values ($last_id,$myid,$myid)"); }*/ } if (substr($field, 0, 1) != "_") { //echo "field: " . $field . "<br/>"; $sql .= " `{$field}` = " . $db->quote($val) . ","; } } if (strrpos($sql, ",") == strlen($sql) - 1) { $sql = substr($sql, 0, strlen($sql) - 1); } if ($this->_persistMode == "update" || $this->_persistMode == WebVista_Model_ORM::DELETE) { $sql .= " {$pWhere} "; } return $sql; }
function processAction() { $clinicalNoteId = (int) $this->_getParam('clinicalNoteId'); $revisionId = (int) $this->_getParam('revisionId'); $data = $this->_getParam('namespaceData'); $saveDate = date('Y-m-d H:i:s'); $cn = new ClinicalNote(); $cn->clinicalNoteId = $clinicalNoteId; $cn->populate(); if (!$revisionId > 0) { $revisionId = GenericData::getUnsignedRevisionId(get_class($cn), $cn->clinicalNoteId); } $eSignatureId = ESignature::retrieveSignatureId(get_class($cn), $revisionId); if ($eSignatureId > 0) { $msg = __('Failed to save. Note is already signed'); } else { $cn->dateTime = date('Y-m-d H:i:s'); $cn->persist(); $msg = __('Data saved.'); $template = $cn->clinicalNoteDefinition->clinicalNoteTemplate->template; $xml = simplexml_load_string($template); $objectClass = 'ClinicalNote'; list($name, $value) = each($data); $gd = new GenericData(); $gd->objectClass = $objectClass; $gd->objectId = $clinicalNoteId; $gd->name = $name; $rowExists = $gd->doesRowExist(true); $preQueries = null; if ($rowExists) { $revisionId = (int) $gd->revisionId; $preQueries = 'DELETE FROM `' . $gd->_table . '` WHERE `revisionId`=' . $revisionId; } else { $revisionId = WebVista_Model_ORM::nextSequenceId(); } $otm = new WebVista_Model_ORMTransactionManager(); foreach ($data as $name => $value) { $gd = new GenericData(); $gd->objectClass = $objectClass; $gd->objectId = $clinicalNoteId; $gd->dateTime = $saveDate; $gd->name = $name; $gd->value = $value; $gd->revisionId = $revisionId; $otm->addORM($gd); } if (!$otm->persist($preQueries)) { $msg = __('Failed to save.'); } if ((string) $xml->attributes()->useNSDR && (string) $xml->attributes()->useNSDR == 'true') { if (!ClinicalNote::processNSDRPersist($xml, $cn, $data)) { $msg = __('Failed to save.'); } } } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($msg); }