Beispiel #1
0
 public function executeMonthlyNotes(sfWebRequest $request)
 {
     $this->form = new ReportMonthlyNotesForm();
     if ($request->hasParameter('client_id')) {
         $this->form->setDefault('client_id', $request->getParameter('client_id'));
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $c = new Criteria();
             // limit to this provider
             $c->add(NoteEntryPeer::EMPLOYEE_ID, $this->getUser()->getProfile()->getEmployeeId());
             // don't include absent services
             #$c->add(NoteEntryPeer::ABSENT, 0);
             // limit to month selected
             $month = $this->form->getValue('date_month');
             $year = $this->form->getValue('date_year');
             $this->first_day = mktime(0, 0, 0, $month, 1, $year);
             $this->last_day = strtotime('+1 month -1 second', $this->first_day);
             $c->add(NoteEntryPeer::SERVICE_DATE, $this->first_day, Criteria::GREATER_EQUAL);
             $c->addAnd(NoteEntryPeer::SERVICE_DATE, $this->last_day, Criteria::LESS_EQUAL);
             $c->addJoin(NoteEntryPeer::CLIENT_SERVICE_ID, ClientServicePeer::ID);
             $c->add(ClientServicePeer::OBJECT_TYPE, $this->form->getValue('service_type'));
             // oldest first
             $c->addAscendingOrderByColumn(NoteEntryPeer::SERVICE_DATE);
             // limit to single client?
             if ($this->form->getValue('client_id') > 0) {
                 $c->add(NoteEntryPeer::CLIENT_ID, $this->form->getValue('client_id'));
             }
             $entries = NoteEntryPeer::doSelectJoinAll($c);
             // go over each entry to create groups by service, each service gets a monthly "voucher" with multiple note entries
             $services = array();
             foreach ($entries as $entry) {
                 if (!array_key_exists($entry->getClientServiceId(), $services)) {
                     // all of this only happens once for each service type
                     $services[$entry->getClientServiceId()]['entries'] = array();
                     $services[$entry->getClientServiceId()]['units'] = 0.0;
                     $services[$entry->getClientServiceId()]['client'] = $entry->getClientService()->getClient()->getFullName();
                     $services[$entry->getClientServiceId()]['dob'] = $entry->getClientService()->getClient()->getDob('U');
                     $services[$entry->getClientServiceId()]['district'] = $entry->getClientService()->getClient()->getDistrict() ? $entry->getClientService()->getClient()->getDistrict()->getName() : '';
                     $services[$entry->getClientServiceId()]['service'] = $entry->getClientService()->getService()->getName();
                     $services[$entry->getClientServiceId()]['location'] = $entry->getLocation() ? $entry->getLocation()->getName() : '';
                     $services[$entry->getClientServiceId()]['frequency'] = $entry->getFrequencyId() ? $entry->getFrequency()->getName() : '';
                     $services[$entry->getClientServiceId()]['type'] = $entry->getClientService()->getObjectType();
                     $services[$entry->getClientServiceId()]['provider'] = $entry->getEmployee()->getFullName();
                     $services[$entry->getClientServiceId()]['license'] = $entry->getEmployee()->getLicenseNumber();
                     $services[$entry->getClientServiceId()]['npi'] = $entry->getEmployee()->getNpi();
                     $services[$entry->getClientServiceId()]['authorization'] = $entry->getClientService()->getAuthorization();
                 }
                 $services[$entry->getClientServiceId()]['entries'][] = $entry;
                 $services[$entry->getClientServiceId()]['units'] += $entry->getUnits();
             }
             $this->services = $services;
             return 'Report' . ucfirst($this->form->getValue('service_type'));
         }
     }
 }
Beispiel #2
0
 public function executeDailyLog(sfWebRequest $request)
 {
     $this->form = new ReportDailyLogForm();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $month = $this->form->getValue('date_month');
             $this->year = $year = $this->form->getValue('date_year');
             $first_day = mktime(0, 0, 0, $month, 1, $year);
             $last_day = strtotime('+1 month -1 second', $first_day);
             $c = new Criteria();
             // only in this date range (the month selected)
             $c->add(NoteEntryPeer::SERVICE_DATE, $first_day, Criteria::GREATER_EQUAL);
             $c->addAnd(NoteEntryPeer::SERVICE_DATE, $last_day, Criteria::LESS_EQUAL);
             // include absent? lets go with no
             $c->add(NoteEntryPeer::ABSENT, 0);
             // sort by kids name
             $c->addAscendingOrderByColumn(ClientPeer::LAST_NAME);
             $c->addAscendingOrderByColumn(NoteEntryPeer::SERVICE_DATE);
             $c->addAscendingOrderByColumn(NoteEntryPeer::TIME_IN);
             // only the selected type
             if ($this->form->getValue('service_type')) {
                 $c->add(ClientServicePeer::OBJECT_TYPE, $this->form->getValue('service_type'));
             }
             $entries = NoteEntryPeer::doSelectJoinAll($c);
             // build array of all entries in the selected time period indexed by ID
             $this->all_entries = array();
             foreach ($entries as $entry) {
                 $this->all_entries[$entry->getId()] = $entry;
             }
             // build an array of overlaps of client
             $this->overlaps = array();
             $client_entry_times = array();
             $provider_entry_times = array();
             foreach ($this->all_entries as $anEntry) {
                 // skip grouped kids, for now
                 if (!$anEntry->inGroup()) {
                     if (!array_key_exists($anEntry->getEmployeeId(), $provider_entry_times)) {
                         $provider_entry_times[$anEntry->getEmployeeId()] = array();
                     }
                     $provider_entry_times[$anEntry->getEmployeeId()][$anEntry->getId()] = array($anEntry->getTimeIn('U'), $anEntry->getTimeOut('U'));
                 }
                 if (!array_key_exists($anEntry->getClientId(), $client_entry_times)) {
                     $client_entry_times[$anEntry->getClientId()] = array();
                 }
                 $client_entry_times[$anEntry->getClientId()][$anEntry->getId()] = array($anEntry->getTimeIn('U'), $anEntry->getTimeOut('U'));
             }
             // find clients with overlapping times
             foreach ($client_entry_times as $client_id => $client_entries) {
                 $entry_times[$client_id] = sort2d($client_entries, 0);
                 $previous = array(0, 0, 0);
                 foreach ($entry_times[$client_id] as $entry_id => $times) {
                     // this in time happened before previous out time.. we have a overlap
                     if ($times[0] < $previous[1] && $entry_id != $previous[2]) {
                         $this->overlaps[$entry_id] = $previous[2];
                         $this->overlaps[$previous[2]] = $entry_id;
                     }
                     $previous = array($times[0], $times[1], $entry_id);
                 }
             }
             // find providers with overlapping times
             foreach ($provider_entry_times as $client_id => $client_entries) {
                 $entry_times[$client_id] = sort2d($client_entries, 0);
                 $previous = array(0, 0, 0);
                 foreach ($entry_times[$client_id] as $entry_id => $times) {
                     // this in time happened before previous out time.. we have a overlap
                     if ($times[0] < $previous[1] && $entry_id != $previous[2]) {
                         $this->overlaps[$entry_id] = $previous[2];
                         $this->overlaps[$previous[2]] = $entry_id;
                     }
                     $previous = array($times[0], $times[1], $entry_id);
                 }
             }
             // initialize
             $this->classrooms = array();
             //        foreach($this->overlaps as $key => $blah) { echo $key .' => '. $blah->getId() .'<br />'; }
             //        die();
             foreach ($this->all_entries as $entry) {
                 // only kids that have been serviced by this employee
                 if (!$this->form->getValue('employee_id') || $this->form->getValue('employee_id') == $entry->getEmployeeId()) {
                     $office = $entry->getOffice();
                     $client = $entry->getClient();
                     $week = $entry->getServiceDate('W');
                     if (!is_object($office)) {
                         $office = new Office();
                         $office->setName('N/A');
                     }
                     // let's see if we have entered any for this classroom yet
                     if (!array_key_exists($office->getName(), $this->classrooms)) {
                         $this->classrooms[$office->getName()] = array_fill_keys(range(date('W', $first_day), date('W', $last_day)), array());
                     }
                     // initialize the row for this kid
                     if (!array_key_exists($week, $this->classrooms[$office->getName()]) || !array_key_exists($client->getFullName(), $this->classrooms[$office->getName()][$week])) {
                         $days = array();
                         for ($day = 1; $day <= 5; $day++) {
                             $days[date('m/d/Y', strtotime($entry->getServiceDate('Y') . "W" . $week . $day))] = array();
                         }
                         $this->classrooms[$office->getName()][$week][$client->getFullName()] = $days;
                     }
                     // save the entry to the appropriate cell in the table
                     $this->classrooms[$office->getName()][$week][$client->getFullName()][$entry->getServiceDate('m/d/Y')][] = $entry;
                 }
             }
             //        $weeks = array(
             //            'week_num' => array(
             //                'client_name' => array(
             //                    'date' => array(
             //                        'service_type' => 'cell data, time, absent, etc.'
             //                    )
             //                )
             //            )
             //        );
             return 'Report';
         }
     }
 }