public function run() { if (class_exists('Faker\\Factory')) { $faker = Faker\Factory::create(); $specimens = Specimen::all()->all(); $museums = Museum::all()->all(); $authors = Author::all()->all(); $animalGroups = AnimalGroup::all()->all(); for ($i = 1; $i <= 500; $i++) { Scan::create(['scanId' => $faker->randomNumber(5), 'scanQuality' => $faker->randomElement(['low', 'medium', 'high']), 'fileDirectory' => '//scan' . $faker->randomNumber(2), 'location' => $faker->country, 'scanTime' => $faker->dateTime, 'voltage' => $faker->randomFloat(2, 1, 20), 'voxelSize' => $faker->randomFloat(1, 0, 1) . 'mm', 'imageCount' => $faker->randomNumber(4), 'current' => '120v', 'sequence' => $faker->randomNumber(4), 'specimenId' => $faker->randomElement($specimens)->id, 'museumId' => $faker->randomElement($museums)->id, 'authorId' => $faker->randomElement($authors)->id, 'animalGroupId' => $faker->randomElement($animalGroups)->id]); } } }
public function run() { $rawData = array_map('str_getcsv', file(__DIR__ . '/../data/specimens.csv')); $headers = array_shift($rawData); $items = array_map(function ($row) use($headers) { return array_combine($headers, $row); }, $rawData); if (!array_walk($items, function ($item) { Specimen::updateOrCreate(['id' => $item['id']], $item); })) { throw new Exception('There was an issue importing 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); } }
public function testIsNotRejected() { $specimenRejected = Specimen::where('specimen_status_id', '!=', Specimen::REJECTED)->first(); $this->assertEquals($specimenRejected->isRejected(), false); }
/** * 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('reports.rejection.index')->with('options', $options)->withInput(Input::all()); }
/** * generate barcode * * @param int $id * @return Response */ public function barcode() { $id = Input::get('sId'); $spec = Specimen::find($id); return $spec->barcode(); }
public function createSpecimen($testStatus, $specimenStatus, $specimenTypeID, $acceptor = 0, $rejector = 0, $rejectReason = "") { $values["specimen_type_id"] = $specimenTypeID; $values["specimen_status_id"] = $specimenStatus; if ($specimenStatus == Specimen::ACCEPTED) { $values["accepted_by"] = $acceptor; $values["time_accepted"] = date('Y-m-d H:i:s'); } if ($specimenStatus == Specimen::REJECTED) { $values["rejected_by"] = $rejector; $values["rejection_reason_id"] = $rejectReason; $values["time_rejected"] = date('Y-m-d H:i:s'); } $specimen = Specimen::create($values); return $specimen->id; }
/** * Function for processing the requests we receive from the external system * and putting the data into our system. * * @var array lab_requests */ public function process($labRequest) { //First: Check if patient exists, if true dont save again $patient = Patient::where('external_patient_number', '=', $labRequest->patient->id)->get(); if (!$patient->first()) { $patient = new Patient(); $patient->external_patient_number = $labRequest->patient->id; $patient->patient_number = $labRequest->patient->id; $patient->name = $labRequest->patient->fullName; $gender = array('Male' => Patient::MALE, 'Female' => Patient::FEMALE); $patient->gender = $gender[$labRequest->patient->gender]; $patient->dob = $labRequest->patient->dateOfBirth; $patient->address = $labRequest->address->address; $patient->phone_number = $labRequest->address->phoneNumber; $patient->created_by = User::EXTERNAL_SYSTEM_USER; $patient->save(); } else { $patient = $patient->first(); } //We check if the test exists in our system if not we just save the request in stagingTable if ($labRequest->parentLabNo == '0') { $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation); } else { $testTypeId = null; } if (is_null($testTypeId) && $labRequest->parentLabNo == '0') { $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND); return; } //Check if visit exists, if true dont save again $visitType = array('ip' => 'In-patient', 'op' => 'Out-patient'); //Should be a constant $visit = Visit::where('visit_number', '=', $labRequest->patientVisitNumber)->where('visit_type', '=', $visitType[$labRequest->orderStage])->get(); if (!$visit->first()) { $visit = new Visit(); $visit->patient_id = $patient->id; $visit->visit_type = $visitType[$labRequest->orderStage]; $visit->visit_number = $labRequest->patientVisitNumber; // We'll save Visit in a transaction a little bit below } else { $visit = $visit->first(); if (strcmp($visitType[$labRequest->orderStage], $visit->visit_type) != 0) { $visit = new Visit(); $visit->patient_id = $patient->id; $visit->visit_type = $visitType[$labRequest->orderStage]; $visit->visit_number = $labRequest->patientVisitNumber; } } $test = null; //Check if parentLabNO is 0 thus its the main test and not a measure if ($labRequest->parentLabNo == '0') { //Check via the labno, if this is a duplicate request and we already saved the test $test = Test::where('external_id', '=', $labRequest->labNo)->get(); if (!$test->first()) { //Specimen $specimen = new Specimen(); $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0]; // We'll save the Specimen in a transaction a little bit below $test = new Test(); $test->test_type_id = $testTypeId; $test->test_status_id = Test::NOT_RECEIVED; $test->created_by = User::EXTERNAL_SYSTEM_USER; //Created by external system 0 $test->requested_by = $labRequest->requestingClinician; $test->external_id = $labRequest->labNo; DB::transaction(function () use($visit, $specimen, $test) { $visit->save(); $specimen->save(); $test->visit_id = $visit->id; $test->specimen_id = $specimen->id; $test->save(); }); $this->saveToExternalDump($labRequest, $test->id); return; } } $this->saveToExternalDump($labRequest, null); }
/** * Get the specimen registered by a user * * @return db resultset */ public static function getSpecimensRegistered($from, $to, $userID = 0) { $specimens = Specimen::select(['id'])->whereBetween('time_accepted', [$from, $to]); if ($userID > 0) { $specimens = $specimens->where('accepted_by', '=', $userID); } return $specimens->get(); }