public function filterBykeyword(Request $request) { $filterKeyword = $request->input('filterKeyword'); $specimens = Specimen::where('genusName', $filterKeyword)->get(); // return response()->json(['name' => 'Abigail', 'state' => 'CA']); return $specimens; }
/** * Returns grouped specimen Counts with optional gender, age range, date range * * @param $gender, $ageRange, $from, $to */ public function groupedSpecimenCount($gender = null, $ageRange = null, $from = null, $to = null) { $specimens = Specimen::where('specimen_type_id', $this->id)->whereIn('specimen_status_id', [Specimen::ACCEPTED]); if ($to && $from) { $specimens = $specimens->whereBetween('time_accepted', [$from, $to]); } if ($gender) { $specimens = $specimens->join('tests', 'specimens.id', '=', 'tests.specimen_id')->join('visits', 'tests.visit_id', '=', 'visits.id')->join('patients', 'visits.patient_id', '=', 'patients.id')->whereIn('gender', $gender); } if ($ageRange) { $ageRange = explode('-', $ageRange); $ageStart = $ageRange[0]; $ageEnd = $ageRange[1]; $now = new DateTime('now'); $finishDate = $now->sub(new DateInterval('P' . $ageStart . 'Y'))->format('Y-m-d'); $startDate = $now->sub(new DateInterval('P' . $ageEnd . 'Y'))->format('Y-m-d'); $specimens = $specimens->whereBetween('dob', [$startDate, $finishDate]); } return $specimens->count(); }
public function testWaitTime() { $specIDs = Specimen::where('specimen_status_id', '!=', Specimen::NOT_COLLECTED)->lists('id'); if (count($specIDs) == 0) { $this->assertTrue(false); } foreach ($specIDs as $id) { $test = Specimen::find($id)->test()->first(); $this->assertTrue($test->getWaitTime() >= 0); } }
/** * Display a view of the daily patient records. * */ public function dailyLog() { $from = Input::get('start'); $to = Input::get('end'); $pendingOrAll = Input::get('pending_or_all'); $error = ''; // Check radiobutton for pending/all tests is checked and assign the 'true' value if (Input::get('tests') === '1') { $pending = 'true'; } $date = date('Y-m-d'); if (!$to) { $to = $date; } $toPlusOne = date_add(new DateTime($to), date_interval_create_from_date_string('1 day')); $records = Input::get('records'); $testCategory = Input::get('section_id'); $testType = Input::get('test_type'); $labSections = TestCategory::lists('name', 'id'); if ($testCategory) { $testTypes = TestCategory::find($testCategory)->testTypes->lists('name', 'id'); } else { $testTypes = array("" => ""); } if ($records == 'patients') { if ($from || $to) { if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) { $error = trans('messages.check-date-range'); } else { $visits = Visit::whereBetween('created_at', array($from, $toPlusOne))->get(); } if (count($visits) == 0) { Session::flash('message', trans('messages.no-match')); } } else { $visits = Visit::where('created_at', 'LIKE', $date . '%')->orderBy('patient_id')->get(); } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "daily_visits_log_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = View::make('reports.daily.exportPatientLog')->with('visits', $visits)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.daily.patient')->with('visits', $visits)->with('error', $error)->withInput(Input::all()); } } else { if ($records == 'rejections') { $specimens = Specimen::where('specimen_status_id', '=', Specimen::REJECTED); /*Filter by test category*/ if ($testCategory && !$testType) { $specimens = $specimens->join('tests', 'specimens.id', '=', 'tests.specimen_id')->join('test_types', 'tests.test_type_id', '=', 'test_types.id')->where('test_types.test_category_id', '=', $testCategory); } /*Filter by test type*/ if ($testCategory && $testType) { $specimens = $specimens->join('tests', 'specimens.id', '=', 'tests.specimen_id')->where('tests.test_type_id', '=', $testType); } /*Filter by date*/ if ($from || $to) { if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) { $error = trans('messages.check-date-range'); } else { $specimens = $specimens->whereBetween('time_rejected', array($from, $toPlusOne))->get(array('specimens.*')); } } else { $specimens = $specimens->where('time_rejected', 'LIKE', $date . '%')->orderBy('id')->get(array('specimens.*')); } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "daily_rejected_specimen_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = View::make('reports.daily.exportSpecimenLog')->with('specimens', $specimens)->with('testCategory', $testCategory)->with('testType', $testType)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.daily.specimen')->with('labSections', $labSections)->with('testTypes', $testTypes)->with('specimens', $specimens)->with('testCategory', $testCategory)->with('testType', $testType)->with('error', $error)->withInput(Input::all()); } } else { $tests = Test::whereNotIn('test_status_id', [Test::NOT_RECEIVED]); /*Filter by test category*/ if ($testCategory && !$testType) { $tests = $tests->join('test_types', 'tests.test_type_id', '=', 'test_types.id')->where('test_types.test_category_id', '=', $testCategory); } /*Filter by test type*/ if ($testType) { $tests = $tests->where('test_type_id', '=', $testType); } /*Filter by all tests*/ if ($pendingOrAll == 'pending') { $tests = $tests->whereIn('test_status_id', [Test::PENDING, Test::STARTED]); } else { if ($pendingOrAll == 'all') { $tests = $tests->whereIn('test_status_id', [Test::PENDING, Test::STARTED, Test::COMPLETED, Test::VERIFIED]); } else { $tests = $tests->whereIn('test_status_id', [Test::COMPLETED, Test::VERIFIED]); } } /*Get collection of tests*/ /*Filter by date*/ if ($from || $to) { if (strtotime($from) > strtotime($to) || strtotime($from) > strtotime($date) || strtotime($to) > strtotime($date)) { $error = trans('messages.check-date-range'); } else { $tests = $tests->whereBetween('time_created', array($from, $toPlusOne))->get(array('tests.*')); } } else { $tests = $tests->where('time_created', 'LIKE', $date . '%')->get(array('tests.*')); } if (Input::has('word')) { $date = date("Ymdhi"); $fileName = "daily_test_records_" . $date . ".doc"; $headers = array("Content-type" => "text/html", "Content-Disposition" => "attachment;Filename=" . $fileName); $content = View::make('reports.daily.exportTestLog')->with('tests', $tests)->with('testCategory', $testCategory)->with('testType', $testType)->with('pendingOrAll', $pendingOrAll)->withInput(Input::all()); return Response::make($content, 200, $headers); } else { return View::make('reports.daily.test')->with('labSections', $labSections)->with('testTypes', $testTypes)->with('tests', $tests)->with('counts', $tests->count())->with('testCategory', $testCategory)->with('testType', $testType)->with('pendingOrAll', $pendingOrAll)->with('error', $error)->withInput(Input::all()); } } } }
/** * Display specimen rejection chart * * @return Response */ public static function specimenRejectionChart($testTypeID = 0) { $from = Input::get('start'); $to = Input::get('end'); $spec_type = Input::get('specimen_type'); $months = json_decode(self::getMonths($from, $to)); // Get specimen rejection reasons available in the time period $rr = Specimen::select(DB::raw('DISTINCT(reason) AS rr, rejection_reason_id'))->join('rejection_reasons', 'rejection_reasons.id', '=', 'specimens.rejection_reason_id')->whereBetween('time_rejected', [$from, $to])->groupBy('rr')->get(); $options = '{ "chart": { "type": "spline" }, "title": { "text":"Rejected Specimen per Reason Overtime" }, "subtitle": { "text":'; if ($from == $to) { $options .= '"' . trans('messages.for-the-year') . ' ' . date('Y') . '"'; } else { $options .= '"' . trans('messages.from') . ' ' . $from . ' ' . trans('messages.to') . ' ' . $to . '"'; } $options .= '}, "credits": { "enabled": false }, "navigation": { "buttonOptions": { "align": "right" } }, "series": ['; $counts = count($rr); foreach ($rr as $rrr) { $options .= '{ "name": "' . $rrr->rr . '","data": ['; $counter = count($months); foreach ($months as $month) { $data = Specimen::where('rejection_reason_id', $rrr->rejection_reason_id)->whereRaw('MONTH(time_rejected)=' . $month->months); if ($spec_type) { $data = $data->where('specimen_type_id', $spec_type); } $data = $data->count(); $options .= $data; if ($counter == 1) { $options .= ''; } else { $options .= ','; } $counter--; } $options .= ']'; if ($counts == 1) { $options .= '}'; } else { $options .= '},'; } $counts--; } $options .= '], "xAxis": { "categories": ['; $count = count($months); foreach ($months as $month) { $options .= '"' . $month->label . " " . $month->annum; if ($count == 1) { $options .= '" '; } else { $options .= '" ,'; } $count--; } $options .= '] }, "yAxis": { "title": { "text": "No. of Rejected Specimen" } } }'; return View::make('reports.rejection.index')->with('options', $options)->withInput(Input::all()); }
public function testIsNotRejected() { $specimenRejected = Specimen::where('specimen_status_id', '!=', Specimen::REJECTED)->first(); $this->assertEquals($specimenRejected->isRejected(), false); }