예제 #1
0
 public function updateVisitProcedures()
 {
     $iterator = new PatientProcedureIterator();
     $iterator->setFilters(array('visitId' => $this->visitId));
     foreach ($iterator as $patientProcedure) {
         $patientProcedure->setUnsetDiagnosis($this->code, true);
         $patientProcedure->persist();
     }
 }
예제 #2
0
 public function populateProcedures(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.12');
     // <!-- Procedures section template -->
     $code = $section->addChild('code');
     $code->addAttribute('code', '47519-4');
     $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1');
     $section->addChild('title', 'Procedures');
     $rows = array();
     $filters = array('patientId' => $this->_patientId);
     $this->setFiltersDateRange($filters);
     $iterator = new PatientProcedureIterator(null, false);
     $iterator->setFilters($filters);
     $ctr = 1;
     foreach ($iterator as $procedure) {
         $rows[] = array('contents' => array('id' => 'Proc' . $ctr++, 'value' => html_convert_entities($procedure->procedure)), 'date' => date('M d, Y', strtotime($procedure->dateTime)));
     }
     $text = $section->addChild('text');
     if ($rows) {
         $table = $text->addChild('table');
         $thead = $table->addChild('thead');
         $tr = $thead->addChild('tr');
         $tr->addChild('th', 'Procedure');
         $tr->addChild('th', 'Date');
         $tbody = $table->addChild('tbody');
         foreach ($rows as $row) {
             $tr = $tbody->addChild('tr');
             $td = $tr->addChild('td');
             $content = $td->addChild('content', $row['contents']['value']);
             $content->addAttribute('ID', $row['contents']['id']);
             $tr->addChild('td', $row['date']);
         }
     }
 }
 public function listPatientProceduresAction()
 {
     $patientId = (int) $this->_getParam('patientId');
     $visitId = (int) $this->_getParam('visitId');
     $rows = array();
     if ($patientId > 0) {
         $patientProcedureIterator = new PatientProcedureIterator();
         $patientProcedureIterator->setFilters(array('patientId' => $patientId, 'visitId' => $visitId));
         foreach ($patientProcedureIterator as $proc) {
             $rows[] = $this->_generateRowData($proc);
         }
     }
     $data = array();
     $data['rows'] = $rows;
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
예제 #4
0
 public function calculateFees($recompute = null)
 {
     // pass true or false to override visit.closed checking
     if ($recompute === null) {
         $recompute = $this->closed ? false : true;
     }
     $visitId = (int) $this->encounter_id;
     $total = 0;
     $discounted = 0;
     $visitFlat = 0;
     $visitPercentage = 0;
     $codeFlat = 0;
     $codePercentage = 0;
     $discountApplied = array();
     if ($recompute) {
         $insuranceProgramId = (int) $this->activePayerId;
         $dateOfVisit = date('Y-m-d', strtotime($this->date_of_treatment));
         $statistics = PatientStatisticsDefinition::getPatientStatistics((int) $this->patient_id);
         $familySize = isset($statistics['family_size']) ? $statistics['family_size'] : 0;
         $monthlyIncome = isset($statistics['monthly_income']) ? $statistics['monthly_income'] : 0;
         $retDiscount = DiscountTable::checkDiscount($insuranceProgramId, $dateOfVisit, $familySize, $monthlyIncome);
         if ($retDiscount !== false) {
             $discount = (double) $retDiscount['discount'];
             switch ($retDiscount['discountType']) {
                 case DiscountTable::DISCOUNT_TYPE_FLAT_VISIT:
                     $discountApplied[] = 'Flat Visit: $' . $discount;
                     $visitFlat += $discount;
                     break;
                 case DiscountTable::DISCOUNT_TYPE_FLAT_CODE:
                     $discountApplied[] = 'Flat Code: $' . $discount;
                     $codeFlat += $discount;
                     break;
                 case DiscountTable::DISCOUNT_TYPE_PERC_VISIT:
                     $discountApplied[] = 'Percentage Visit: ' . $discount . '%';
                     $visitPercentage += $discount / 100;
                     break;
                 case DiscountTable::DISCOUNT_TYPE_PERC_CODE:
                     $discountApplied[] = 'Percentage Code: ' . $discount . '%';
                     $codePercentage += $discount / 100;
                     break;
             }
         }
     } else {
         $claimLineFees = array();
         $iterator = ClaimLine::mostRecentClaims($visitId);
         foreach ($iterator as $claimLine) {
             $code = $claimLine->procedureCode;
             if (!isset($claimLineFees[$code])) {
                 $claimLineFees[$code] = array('baseFee' => 0, 'adjustedFee' => 0);
             }
             $claimLineFees[$code]['baseFee'] += (double) $claimLine->baseFee;
             $claimLineFees[$code]['adjustedFee'] += (double) $claimLine->adjustedFee;
         }
     }
     $details = array();
     $iterator = new PatientProcedureIterator();
     $iterator->setFilters(array('visitId' => $visitId));
     $firstProcedureId = null;
     foreach ($iterator as $patientProcedure) {
         $patientProcedureId = (int) $patientProcedure->patientProcedureId;
         $code = $patientProcedure->code;
         $quantity = (int) $patientProcedure->quantity;
         $writeoff = 0;
         if ($recompute) {
             $fee = '-.--';
             $feeDiscounted = '-.--';
             $discountedRate = '';
             $retFee = FeeSchedule::checkFee($insuranceProgramId, $dateOfVisit, $code);
             if ($retFee !== false && (double) $retFee['fee'] != 0) {
                 $fee = (double) $retFee['fee'];
                 $tmpFee = 0;
                 for ($i = 1; $i <= 4; $i++) {
                     $modifier = 'modifier' . $i;
                     if (!strlen($patientProcedure->{$modifier}) > 0) {
                         continue;
                     }
                     switch ($patientProcedure->{$modifier}) {
                         case $retFee['modifier1']:
                             $tmpFee += (double) $retFee['modifier1fee'];
                             break 2;
                         case $retFee['modifier2']:
                             $tmpFee += (double) $retFee['modifier2fee'];
                             break 2;
                         case $retFee['modifier3']:
                             $tmpFee += (double) $retFee['modifier3fee'];
                             break 2;
                         case $retFee['modifier4']:
                             $tmpFee += (double) $retFee['modifier4fee'];
                             break 2;
                     }
                 }
                 if ($tmpFee > 0) {
                     $fee = $tmpFee;
                 }
                 if ($quantity > 0) {
                     $fee *= $quantity;
                     $feeDiscounted *= $quantity;
                 }
                 // calculate discounts
                 if ($codeFlat > 0) {
                     $tmpDiscount = $fee - $codeFlat;
                     if ($tmpDiscount < 0) {
                         $tmpDiscount = 0;
                     }
                     $feeDiscounted += $tmpDiscount;
                     $writeoff = $tmpDiscount;
                 }
                 if ($firstProcedureId !== null && $visitFlat > 0) {
                     $writeoff = $fee;
                     trigger_error('VISIT FLAT: ' . $visitFlat);
                     trigger_error('WRITEOFF: ' . $writeoff);
                 }
                 if ($codePercentage > 0) {
                     $tmpDiscount = $feeDiscounted * $codePercentage;
                     if ($tmpDiscount < 0) {
                         $tmpDiscount = 0;
                     }
                     $feeDiscounted += $tmpDiscount;
                     $writeoff = $tmpDiscount;
                 }
             }
             if ($firstProcedureId === null) {
                 $firstProcedureId = $patientProcedureId;
             }
         } else {
             if (isset($claimLineFees[$code])) {
                 $fee = $claimLineFees[$code]['baseFee'];
                 $feeDiscounted = $claimLineFees[$code]['adjustedFee'];
             } else {
                 $fee = $patientProcedure->baseFee;
                 $feeDiscounted = $patientProcedure->adjustedFee;
             }
             if ($quantity > 0) {
                 $fee *= $quantity;
                 $feeDiscounted *= $quantity;
             }
         }
         /*$quantity = (int)$patientProcedure->quantity;
         		if ($quantity > 0) {
         			$fee *= $quantity;
         			$feeDiscounted *= $quantity;
         		}*/
         $total += $fee;
         $discounted += (double) $feeDiscounted;
         $details[$patientProcedureId] = array();
         $details[$patientProcedureId]['orm'] = $patientProcedure;
         $details[$patientProcedureId]['fee'] = $fee;
         $details[$patientProcedureId]['feeDiscounted'] = $feeDiscounted;
         $details[$patientProcedureId]['writeoff'] = $writeoff;
     }
     if ($visitFlat > 0) {
         $discounted += $visitFlat;
         // update the first procedure
         if ($firstProcedureId !== null) {
             $details[$firstProcedureId]['feeDiscounted'] += $visitFlat;
             $writeoff = $details[$firstProcedureId]['fee'] - $details[$firstProcedureId]['feeDiscounted'];
             if ($writeoff < 0) {
                 $writeoff = 0;
             }
             $details[$firstProcedureId]['writeoff'] = $writeoff;
         }
     }
     if ($visitPercentage > 0) {
         $discounted += $discounted * $visitPercentage;
         // update the first procedure
         if ($firstProcedureId !== null) {
             $details[$firstProcedureId]['feeDiscounted'] += $details[$firstProcedureId]['feeDiscounted'] * $visitFlat;
         }
     }
     $row = array();
     $row['discountApplied'] = $discountApplied;
     $row['details'] = $details;
     $row['total'] = $total;
     $row['discounted'] = $discounted;
     return $row;
 }
예제 #5
0
 public function paymentReceiptAction()
 {
     // d96de46c-be90-45b0-b5f9-0b4abee76483
     $referenceId = $this->_getParam('referenceId');
     $personId = (int) $this->_getParam('personId');
     $visitId = (int) $this->_getParam('visitId');
     $data = $this->_getAttachmentData($referenceId);
     $patient = new Patient();
     $patient->personId = $personId;
     if ($personId > 0) {
         $patient->populate();
     }
     $person = $patient->person;
     $visit = new Visit();
     $visit->visitId = $visitId;
     if ($visitId > 0) {
         $visit->populate();
     }
     $practiceId = (int) $visit->practiceId;
     if (!$practiceId > 0) {
         $buildingId = (int) $visit->buildingId;
         if ($buildingId > 0) {
             $building = new Building();
             $building->buildingId = $buildingId;
             $building->populate();
             $practiceId = (int) $building->practiceId;
         } else {
             $roomId = (int) $visit->roomId;
             if ($roomId > 0) {
                 $room = new Room();
                 $room->roomId = $roomId;
                 $room->populate();
                 $practiceId = (int) $room->building->practiceId;
             }
         }
     }
     $practice = new Practice();
     $practice->practiceId = $practiceId;
     if ($practiceId > 0) {
         $practice->populate();
     }
     $primaryAddress = $practice->primaryAddress;
     $xml = new SimpleXMLElement('<data/>');
     $xmlPractice = $xml->addChild('practice');
     $this->_addChild($xmlPractice, 'name', $practice->name);
     $this->_addChild($xmlPractice, 'primaryLine1', $primaryAddress->line1);
     $primaryCityStateZip = $primaryAddress->city . ' ' . $primaryAddress->state . ' ' . $primaryAddress->postalCode;
     $this->_addChild($xmlPractice, 'primaryCityStateZip', $primaryCityStateZip);
     $this->_addChild($xmlPractice, 'mainPhone', $practice->mainPhone->number);
     $xmlPatient = $xml->addChild('patient');
     $name = $person->firstName . ' ' . $person->middleName . ' ' . $person->lastName;
     $this->_addChild($xmlPatient, 'name', $name);
     $addresses = Address::listAddresses($personId);
     if (isset($addresses[Address::TYPE_BILLING])) {
         $address = $addresses[Address::TYPE_BILLING];
     } else {
         if (isset($addresses[Address::TYPE_HOME])) {
             $address = $addresses[Address::TYPE_HOME];
         } else {
             if (isset($addresses[Address::TYPE_MAIN])) {
                 $address = $addresses[Address::TYPE_MAIN];
             } else {
                 if (isset($addresses[Address::TYPE_SEC])) {
                     $address = $addresses[Address::TYPE_SEC];
                 } else {
                     if (isset($addresses[Address::TYPE_OTHER])) {
                         $address = $addresses[Address::TYPE_OTHER];
                     } else {
                         $address = array_pop($addresses);
                     }
                 }
             }
         }
     }
     $billingCityStateZip = $address->city . ' ' . $address->state . ' ' . $address->postalCode;
     $this->_addChild($xmlPatient, 'billingLine1', $address->line1);
     $this->_addChild($xmlPatient, 'billingCityStateZip', $billingCityStateZip);
     $iterator = new PatientProcedureIterator();
     $iterator->setFilters(array('visitId' => $visitId));
     $procedures = array();
     foreach ($iterator as $row) {
         $procedures[] = $row->code;
     }
     $iterator = new PatientDiagnosisIterator();
     $iterator->setFilters(array('visitId' => $visitId));
     $diagnoses = array();
     foreach ($iterator as $row) {
         $diagnoses[] = $row->code;
     }
     $xmlNotes = $xmlPatient->addChild('notes');
     $note = implode(',', $procedures) . " \t " . implode(',', $diagnoses) . " \t " . date('m/d/y', strtotime($visit->dateOfTreatment));
     $this->_addChild($xmlNotes, 'note', $note);
     $today = date('Y-m-d');
     $todaysTotal = 0;
     $iterator = new PaymentIterator();
     $iterator->setFilters(array('visitId' => $visitId, 'company' => 'System', 'paymentDate' => $today));
     $payments = array();
     foreach ($iterator as $row) {
         $payments[] = $row;
     }
     $iterator->setFilters(array('personId' => $personId, 'unallocated' => true, 'paymentDate' => $today));
     foreach ($iterator as $row) {
         $payments[] = $row;
     }
     foreach ($payments as $row) {
         $xmlPayment = $xmlPatient->addChild('payments');
         $paymentDate = date('m/d/y', strtotime($row->paymentDate));
         $this->_addChild($xmlPayment, 'date', $paymentDate);
         $this->_addChild($xmlPayment, 'description', $row->title . ' .... Thank You');
         $this->_addChild($xmlPayment, 'method', $row->paymentType);
         $amount = (double) $row->amount;
         $todaysTotal += $amount;
         $this->_addChild($xmlPayment, 'amount', '-' . number_format($amount, 2));
         $this->_addChild($xmlPayment, 'insurance', $row->insuranceDisplay);
     }
     $fees = $visit->calculateFees();
     $previousBalance = $fees['total'];
     $this->_addChild($xmlPatient, 'previousBalance', number_format($previousBalance, 2));
     $this->_addChild($xmlPatient, 'todaysTotal', '-' . number_format($todaysTotal, 2));
     $totalDue = $previousBalance - $todaysTotal;
     $this->_addChild($xmlPatient, 'totalDue', number_format($totalDue, 2));
     $totalDueFromPatient = $previousBalance;
     $this->_addChild($xmlPatient, 'totalDueFromPatient', number_format($totalDueFromPatient, 2));
     try {
         $content = ReportBase::mergepdfset($xml, $data);
         $this->getResponse()->setHeader('Content-Type', 'application/pdf');
     } catch (Exception $e) {
         $content = '<script>alert("' . $e->getMessage() . '")</script>';
     }
     $this->view->content = $content;
     $this->render('binary-template');
 }
 public function listPatientProceduresAction()
 {
     $patientId = (int) $this->_getParam('patientId');
     $rows = array();
     if ($patientId > 0) {
         $patientProcedureIterator = new PatientProcedureIterator();
         $patientProcedureIterator->setFilters(array('patientId' => $patientId));
         $providerIterator = new ProviderIterator();
         $listProviders = $providerIterator->toArray('personId', 'displayName');
         foreach ($patientProcedureIterator as $proc) {
             $quantity = $proc->quantity;
             if ($quantity > 2) {
                 $quantity .= ' times';
             } else {
                 $quantity .= ' time';
             }
             $provider = '';
             if (isset($listProviders[$proc->providerId])) {
                 $provider = $listProviders[$proc->providerId];
             }
             $tmp = array();
             $tmp['id'] = $proc->code;
             $tmp['data'][] = $quantity;
             $tmp['data'][] = $proc->procedure;
             $tmp['data'][] = $provider;
             $tmp['data'][] = $proc->providerId;
             $tmp['data'][] = $proc->comments;
             $rows[] = $tmp;
         }
     }
     $data = array();
     $data['rows'] = $rows;
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
예제 #7
0
 public static function checkRules(Visit $visit, array $fees = array())
 {
     if (!isset($fees['details'])) {
         $fees = $visit->calculateFees(true);
     }
     $visitId = (int) $visit->visitId;
     $payerId = (int) $visit->activePayerId;
     $procedures = null;
     $iterator = new ClaimRuleIterator();
     foreach (self::listGroups() as $groupId => $values) {
         // TODO: use operators
         $matched = false;
         $iterator->setFilters(array('groupId' => $groupId));
         foreach ($iterator as $claimRule) {
             $type = $claimRule->type;
             switch ($type) {
                 case self::TYPE_PROCEDURE:
                 case self::TYPE_DIAGNOSIS:
                     if ($procedures === null) {
                         $procedures = array();
                         $patientProcedureIterator = new PatientProcedureIterator();
                         $patientProcedureIterator->setFilters(array('visitId' => $visitId));
                         foreach ($patientProcedureIterator as $patientProcedure) {
                             $procedures[] = $patientProcedure;
                         }
                     }
                     $code = $claimRule->code;
                     foreach ($procedures as $procedure) {
                         if ($type == self::TYPE_PROCEDURE) {
                             if ($procedure->code == $code) {
                                 $matched = true;
                                 break;
                             }
                         } else {
                             for ($i = 1; $i <= 8; $i++) {
                                 $key = 'diagnosisCode' . $i;
                                 if ($procedure->{$key} == $code) {
                                     $matched = true;
                                     break 2;
                                 }
                             }
                         }
                     }
                     break;
                 case self::TYPE_INSURANCE_PROGRAM:
                     if ($claimRule->value == $payerId) {
                         $matched = true;
                     }
                     break;
                 case self::TYPE_MODIFIER:
                     break;
                 case self::TYPE_LINE_AMOUNT:
                     break;
                 case self::TYPE_CLAIM_TOTAL:
                     break;
             }
         }
         if ($matched) {
             $visit->_claimRule = $values;
         }
     }
     return $visit;
 }