public function populateEncounters(SimpleXMLElement $xml) { $component = $xml->addChild('component'); $section = $component->addChild('section'); $templateId = $section->addChild('templateId'); $templateId->addAttribute('root', '2.16.840.1.113883.10.20.1.3'); // <!-- Encounters section template --> $code = $section->addChild('code'); $code->addAttribute('code', '46240-8'); $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1'); $section->addChild('title', 'Encounters'); if ($this->visit !== null) { $visitIterator = array($this->visit); } else { $visitIterator = new VisitIterator(); $visitIterator->setFilters(array('patientId' => $this->_patientId)); } $rows = array(); foreach ($visitIterator as $visit) { $building = new Building(); $building->buildingId = $visit->buildingId; $building->populate(); $appointment = new Appointment(); $appointment->appointmentId = $visit->appointmentId; $appointment->populate(); $rows[] = array('encounter' => html_convert_entities($appointment->title), 'location' => html_convert_entities($building->displayName), 'date' => date('M d, Y', strtotime($visit->dateOfTreatment))); } $text = $section->addChild('text'); if ($rows) { $table = $text->addChild('table'); $thead = $table->addChild('thead'); $tr = $thead->addChild('tr'); $tr->addChild('th', 'Encounter'); $tr->addChild('th', 'Location'); $tr->addChild('th', 'Date'); $tbody = $table->addChild('tbody'); foreach ($rows as $row) { $tr = $tbody->addChild('tr'); $tr->addChild('td', $row['encounter']); $tr->addChild('td', $row['location']); $tr->addChild('td', $row['date']); } } }
function listVisitsAction() { $personId = (int) $this->_getParam('personId'); if (!$personId > 0) { $this->_helper->autoCompleteDojo(array()); } $visitIterator = new VisitIterator(); $visitIterator->setFilters(array('patientId' => $personId)); $acj = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $acj->suppressExit = true; $acj->direct(array("rows" => $visitIterator->toJsonArray('encounter_id', array('date_of_treatment', 'locationName', 'providerDisplayName'))), true); }
public function listVisitsAction() { $personId = (int) $this->_getParam('personId'); if (!$personId > 0) { $this->_helper->autoCompleteDojo(array()); } $visitIterator = new VisitIterator(); $visitIterator->setFilters(array('patientId' => $personId)); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $rows = array(); foreach ($visitIterator as $visit) { $rows[] = $this->_generateVisitRowData($visit); } $json->direct(array('rows' => $rows), true); }
public function listPatientAccountsAction() { $personId = (int) $this->_getParam('personId'); $rows = array(); $filters = $this->_session->patientFilters; $iterator = new VisitIterator(); $iterator->setFilters(array('patientId' => $personId, 'dateRange' => $filters['dateStart'] . ':' . $filters['dateEnd'], 'facilityId' => $filters['facilityId'], 'payerId' => $filters['payerId'], 'providerId' => $filters['providerId'], 'userId' => $filters['userId'], 'openClosed' => 1, 'void' => 0)); foreach ($iterator as $item) { $visitId = (int) $item->visitId; //$acct = $item->accountSummary; //$total = $acct['total']; //$payment = $acct['payment']; //$writeOff = $acct['writeoff']; //$balance = $acct['balance']; $billed = 0; $total = 0; $pendingInsurance = 0; // TODO: connect to claimFiles? $paidInsurance = 0; $paidPatient = 0; // $payment + $writeOff; $summary = $item->accountDetails; // charges foreach ($summary['charges']['details'] as $row) { $billed += (double) $row->adjustedFee; $total += (double) $row->baseFee; } // misc charges foreach ($summary['miscCharges']['details'] as $row) { $billed += (double) $row->amount; $total += (double) $row->amount; } // payments foreach ($summary['payments']['details'] as $row) { if ($row instanceof Payment) { $amount = (double) $row->unallocated; } else { $amount = (double) $row->amount; } $payer = InsuranceProgram::getInsuranceProgram($row->payerId); if (!strlen($payer) > 0 || strtolower(substr($payer, 0, 8)) == 'system->') { $paidPatient += $amount; } else { $paidInsurance += $amount; } } // writeoffs foreach ($summary['writeOffs']['details'] as $row) { $payer = InsuranceProgram::getInsuranceProgram($row->payerId); if (!strlen($payer) > 0) { continue; } // exclude/void writeoff if no payer specified $amount = (double) $row->amount; if (strtolower(substr($payer, 0, 8)) == 'system->') { $paidPatient += $amount; } else { $paidInsurance += $amount; } } $balance = $total - ($paidPatient + $paidInsurance + $pendingInsurance); if (!$billed > 0 && $total > 0) { $billed = $total; } $row = array(); $row['id'] = $visitId; $row['data'] = array(); $row['data'][] = $this->view->baseUrl . '/accounts.raw/list-patient-account-details?visitId=' . $visitId; $row['data'][] = substr($item->dateOfTreatment, 0, 10); $row['data'][] = $item->insuranceProgram; $row['data'][] = '$' . number_format(abs($billed), 2); $row['data'][] = '$' . number_format(abs($pendingInsurance), 2); $row['data'][] = '$' . number_format(abs($paidInsurance), 2); $row['data'][] = '$' . number_format(abs($paidPatient), 2); $row['data'][] = '$' . number_format(abs($balance), 2); $rows[] = $row; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct(array('rows' => $rows)); }
public function _setActivePatient($personId, $visitId) { if (!$personId > 0) { return; } $memcache = Zend_Registry::get('memcache'); $patient = new Patient(); $patient->personId = (int) $personId; $patient->populate(); $patient->person->populate(); $this->_patient = $patient; $this->view->patient = $this->_patient; $mostRecentRaw = $memcache->get('mostRecent'); $currentUserId = (int) Zend_Auth::getInstance()->getIdentity()->personId; $personId = $patient->personId; $teamId = $patient->teamId; if ($mostRecentRaw === false) { $mostRecent = array(); } else { $mostRecent = unserialize($mostRecentRaw); } if (!array_key_exists($currentUserId, $mostRecent)) { $mostRecent[$currentUserId] = array(); } if (array_key_exists($personId, $mostRecent[$currentUserId])) { unset($mostRecent[$currentUserId][$personId]); } $name = $patient->person->last_name . ', ' . $patient->person->first_name . ' ' . substr($patient->person->middle_name, 0, 1) . ' #' . $patient->record_number; $mostRecent[$currentUserId][$patient->personId] = array('name' => $name, 'teamId' => $teamId); $memcache->set('mostRecent', serialize($mostRecent)); if (strlen($patient->teamId) > 0) { $name = TeamMember::ENUM_PARENT_NAME; $enumeration = new Enumeration(); $enumeration->populateByEnumerationName($name); $enumerationsClosure = new EnumerationsClosure(); $rowset = $enumerationsClosure->getAllDescendants($enumeration->enumerationId, 1); $patientEnumerationId = 0; foreach ($rowset as $row) { if ($patient->teamId == $row->key) { $patientEnumerationId = $row->enumerationId; break; } } if ($patientEnumerationId !== 0) { $this->view->team = TeamMember::generateTeamTree($patientEnumerationId); } } // POSTINGS $allergies = array(); $patientAllergy = new PatientAllergy(); $patientAllergyIterator = $patientAllergy->getIteratorByPatient($personId); foreach ($patientAllergyIterator as $allergy) { if ($allergy->noKnownAllergies) { continue; } $allergies[] = $allergy->toArray(); } $this->view->allergies = $allergies; $notes = array(); $patientNote = new PatientNote(); $patientNoteIterator = $patientNote->getIterator(); $filters = array(); $filters['patient_id'] = $personId; $filters['active'] = 1; $filters['posting'] = 1; $patientNoteIterator->setFilters($filters); foreach ($patientNoteIterator as $note) { $notes[] = $note->toArray(); } $this->view->notes = $notes; //REMINDERS $ctr = 0; $hsa = new HealthStatusAlert(); $hsaIterator = $hsa->getIteratorByStatusWithPatientId('active', $personId); foreach ($hsaIterator as $row) { $ctr++; } if ($ctr > 0) { $this->view->reminders = $ctr; } // VISITS //$this->_visit = null; $visit = new Visit(); $visit->encounter_id = (int) $visitId; if (!$visit->populate() || $visit->patientId != $patient->personId) { try { $db = Zend_Registry::get('dbAdapter'); $dbSelect = $db->select()->from('encounter')->where('encounter.patient_id = ?', $patient->personId)->where('DATE_FORMAT(encounter.date_of_treatment,"%Y-%m-%d") = ?', date('Y-m-d'))->order('encounter.date_of_treatment DESC')->order('encounter.encounter_id DESC')->limit(1); $visitIterator = new VisitIterator($dbSelect); $visitIterator->valid(); $visit = $visitIterator->first(); if ($visit->encounter_id > 0) { $this->_visit = $visit; $this->view->visit = $this->_visit; } return; } catch (Exception $e) { // return; } return; } $this->_visit = $visit; $this->view->visit = $this->_visit; }
public function listAction() { $posStart = $this->_getParam('posStart'); if ($posStart < 0) { $msg = 'Invalid request'; trigger_error($msg); throw new Exception($msg); } $claimList = isset($this->_session->claimList) ? $this->_session->claimList : array(); $sessions = $this->_session->filters; if (!isset($sessions['DOSStart'])) { $sessions['DOSStart'] = date('Y-m-d', strtotime('-1 week')); } if (!isset($sessions['DOSEnd'])) { $sessions['DOSEnd'] = date('Y-m-d'); } $filters = array(); if (isset($sessions['batchHistoryId'])) { $claimFile = new ClaimFile(); $claimFile->claimFileId = (int) $sessions['batchHistoryId']; $claimFile->populate(); $filters['batchHistoryId'] = $claimFile->claimIds; } else { $filters['dateRange'] = $sessions['DOSStart'] . ':' . $sessions['DOSEnd']; if (isset($sessions['facilities']) && count($sessions['facilities']) > 0) { // practiceId_buildingId_roomId foreach ($sessions['facilities'] as $key => $value) { if (!$value) { continue; } $x = explode('_', $key); $practiceId = $x[0]; $buildingId = $x[1]; $roomId = $x[2]; if (!isset($filters['facilities'])) { $filters['facilities'] = array(); } $filters['facilities'][] = array('practice' => $practiceId, 'building' => $buildingId, 'room' => $roomId); } } if (isset($sessions['payers']) && count($sessions['payers']) > 0) { foreach ($sessions['payers'] as $key => $value) { if (!$value) { continue; } if (!isset($filters['payers'])) { $filters['payers'] = array(); } $filters['payers'][] = $key; } } $filters['total'] = isset($sessions['total']) ? $sessions['total'] : 0; $filters['billed'] = isset($sessions['billed']) ? $sessions['billed'] : 0; $filters['paid'] = isset($sessions['paid']) ? $sessions['paid'] : 0; $filters['writeoff'] = isset($sessions['writeoff']) ? $sessions['writeoff'] : 0; $filters['balance'] = isset($sessions['balance']) ? $sessions['balance'] : 0; $filters['openClosed'] = isset($sessions['openClosed']) ? (int) $sessions['openClosed'] : 2; } if (isset($sessions['mrn']) && strlen($sessions['mrn']) > 0) { $filters['mrn'] = $sessions['mrn']; } $rows = array(); $claimIterator = array(); $visitIterator = new VisitIterator(); //$filters['void'] = 0; // exclude void from list $visitIterator->setFilters($filters); foreach ($visitIterator as $visit) { $visitId = (int) $visit->visitId; $appointmentId = (int) $visit->appointmentId; $acct = $visit->accountSummary; $total = $acct['total']; $billed = $acct['billed']; $writeoff = $acct['writeoff']; $paid = $acct['payment']; $balance = $acct['balance']; $payerId = isset($acct['claimLine']) ? $acct['claimLine']->insuranceProgramId : $visit->activePayerId; $names = array('total', 'billed', 'paid', 'writeoff', 'balance'); foreach ($names as $name) { if (!isset($filters[$name]) || !$filters[$name]['active']) { continue; } $operator = $filters[$name]['operator']; $operand1 = $filters[$name]['operand1']; $operand2 = $filters[$name]['operand2']; if ($operator == '=' && !(${$name} == $operand1)) { continue 2; } else { if ($operator == '>' && !(${$name} > $operand1)) { continue 2; } else { if ($operator == '>=' && !(${$name} >= $operand1)) { continue 2; } else { if ($operator == '<' && !(${$name} < $operand1)) { continue 2; } else { if ($operator == '<=' && !(${$name} <= $operand1)) { continue 2; } else { if ($operator == 'between' && $operand2 > 0 && !(${$name} >= $operand1 && ${$name} <= $operand2)) { continue 2; } } } } } } } $paid += $writeoff; $dateOfService = substr($visit->dateOfTreatment, 0, 10); $personId = (int) $visit->patientId; $person = new Person(); $person->personId = $personId; $person->populate(); $color = ''; if ($visit->closed) { if ($total > 0 && $balance <= 0) { $color = '#82CA9D'; // pastel green for fully zeroed claims } else { if ($paid > 0) { $color = '#F7977A'; // pastel red for claims partly paid or with a denial status } } } if ($color == '') { $color = '#FFF79A'; // pastel yellow for rows transmitted } $facility = $visit->facility; $total = number_format(abs($total), 2, '.', ','); $billed = number_format(abs($billed), 2, '.', ','); $paid = number_format(abs($paid), 2, '.', ','); $balance = number_format(abs($balance), 2, '.', ','); $url = $this->view->baseUrl . '/claims.raw/list-claim-files?visitId=' . $visitId; if (isset($acct['claimLine'])) { $url .= '&claimId=' . $acct['claimLine']->claimId; } $row = array(); $row['id'] = $visitId; $row['data'] = array(); $row['data'][] = $url; $row['data'][] = $dateOfService; $row['data'][] = $person->displayName; $row['data'][] = '$' . $total; $row['data'][] = '$' . $billed; $row['data'][] = '$' . $paid; $row['data'][] = '$' . $balance; $row['data'][] = InsuranceProgram::getInsuranceProgram($payerId); $row['data'][] = $facility; $row['data'][] = $visit->displayStatus; $row['userdata']['pid'] = $personId; $row['userdata']['color'] = $color; $rows[] = $row; $claimList[$visitId] = array('billed' => $billed, 'paid' => $paid, 'balance' => $balance); } $this->_session->claimList = $claimList; $data = array('rows' => $rows); $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }