public static function getVisits($mdwsDao, $fromDate = '', $toDate = '') { try { if (!isset($fromDate) || trim($fromDate) == '') { $oneMonthAgo = MdwsUtils::getVistaDate(-1 * DEFAULT_GET_VISIT_DAYS); $fromDate = MdwsUtils::covertVistaDateToYYYYMMDD($oneMonthAgo); // TODO - get today-30 date in this format } if (!isset($toDate) || trim($toDate) == '') { $today = MdwsUtils::getVistaDate(0); $toDate = MdwsUtils::covertVistaDateToYYYYMMDD($today); //$toDate = '20140718'; // TODO - get today's date in this format } $soapResult = $mdwsDao->makeQuery('getVisits', array('fromDate' => $fromDate, 'toDate' => $toDate)); //$soapResult = $mdwsDao->makeQuery('getAllMeds', NULL); //$soapResult = $mdwsDao->makeQuery('getAllMeds', null); // TODO - remove this line and uncomment line above $result = array(); //return $result; // TODO - remove this line if (!isset($soapResult) || !isset($soapResult->getVisitsResult) || isset($soapResult->getVisitsResult->fault)) { throw new \Exception('Invalid getVisits result -> ' . print_r($soapResult, true)); // . "\n<br>MdwsDao=". $mdwsDao // . "\n<br>Which of these is TRUE? 1=[".!isset($soapResult->getVisitsResult).'] or 2=['.isset($soapResult->getVisitsResult->fault).']' // . "\n<br>". 'RAW SOAP RESULT='.print_r($soapResult,TRUE)); } // check for zero results if (!isset($soapResult->getVisitsResult->count) || $soapResult->getVisitsResult->count == 0) { return $result; // TBD - return null or empty array? } // homogenize result of 1 to array $visitAry = is_array($soapResult->getVisitsResult->visits->VisitTO) ? $soapResult->getVisitsResult->visits->VisitTO : array($soapResult->getVisitsResult->visits->VisitTO); foreach ($visitAry as $visit) { $aryItem = array('locationName' => $visit->location->name, 'locationId' => $visit->location->id, 'visitTimestamp' => $visit->timestamp, 'visitTO' => $visit); $result[] = $aryItem; //Already acending //array_push($result, $aryItem); } $aSorted = array_reverse($result); //Now this is descrnding. return $aSorted; } catch (\Exception $ex) { throw new \Exception('Trouble in getVisits because ' . $ex); } }