Ejemplo n.º 1
0
 /**
  * @author Christian Schätzle
  * @param $pCollection
  */
 public static function initializeObjectFromCollection($pCollection)
 {
     $lObject = new Visit();
     if ($pCollection) {
         $lObject->fromArray($pCollection);
         return $lObject;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * Creates a new visit entry
  * @param $type
  * @param $owner_id
  * @param $ref_id
  */
 public static function create($type, $owner_id, $ref_id)
 {
     $o = new Visit();
     $o->type = $type;
     $o->owner = $owner_id;
     $o->ref = $ref_id;
     $o->time = sql_datetime(time());
     $o->store();
 }
Ejemplo n.º 3
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Visit::create(['type' => rand(0, 1), 'visit_date' => $faker->time($format = 'H:i:s', $max = 'now'), 'parent_id' => 0, 'purpose' => $faker->paragraph($nbSentences = 3), 'remarks' => $faker->paragraph($nbSentences = 3)]);
     }
 }
Ejemplo n.º 4
0
 public function mapAction($idVisit)
 {
     $visit = Visit::findFirst(array("conditions" => "idVisit = ?1", "bind" => array(1 => $idVisit)));
     if (!$visit) {
         $this->flashSession->error("Ocurrio un error procesando su solicitud, por favor intentelo nuevamente.");
         return $this->response->redirect('index');
     }
     $user = User::findFirst(array("conditions" => "idUser = ?1 AND idAccount = ?2", "bind" => array(1 => $visit->idUser, 2 => $this->user->idAccount)));
     if (!$user) {
         $this->flashSession->error("Ocurrio un error procesando su solicitud, por favor intentelo nuevamente.");
         return $this->response->redirect('visit/index');
     }
     try {
         $sql_rows = "SELECT v.idVisit AS idUser, v.start AS date, u.name AS name, u.lastName AS lastname, vt.name AS visit, c.name AS client, v.battery AS battery, v.latitude AS latitude, v.longitude AS longitude, v.location AS location " . "FROM Visit AS v " . " JOIN User AS u ON (u.idUser = v.idUser) " . " JOIN Visittype AS vt ON (vt.idVisittype = v.idVisittype) " . " JOIN Client AS c ON (c.idClient = v.idClient) " . " WHERE v.idVisit = {$idVisit}";
         //            $this->logger->log($sql_rows);
         $modelsManager = \Phalcon\DI::getDefault()->get('modelsManager');
         $rows = $modelsManager->executeQuery($sql_rows);
         $this->view->setVar('visit', $rows->getFirst());
         $this->view->setVar('user', $user);
     } catch (Exception $e) {
         $this->flashSession->error($e->getMessage());
         $this->trace("fail", $e->getMessage());
         return $this->response->redirect('visit/index');
     }
 }
Ejemplo n.º 5
0
 /**
  * Display the specified patient.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $patient = Patient::findOrFail($id);
     $tests = Test::select('tests.id', 'test', 'result', 'diagnosis', 'tests.created_at', 'item')->where('patient_id', '=', $id)->join('billings', 'billings.id', '=', 'tests.test')->get();
     $medications = Medication::select('medications.id', 'prescription', 'dosage', 'start_date', 'end_date', 'item')->where('patient_id', '=', $id)->join('billings', 'billings.id', '=', 'medications.prescription')->get();
     $visit = Visit::where('patient_id', '=', $id)->first();
     return View::make('patients.show', compact('patient', 'tests', 'medications', 'visit'));
 }
Ejemplo n.º 6
0
 public static function hasDone($uid)
 {
     $visit = Visit::findFirst("uid={$uid}");
     if (!$visit) {
         return false;
     }
     $advises = Advise::getAdvisesByUid($uid, Advise::STATUS_UNDO, 'visit');
     return $advises ? false : true;
 }
 protected function _createVisit($appointmentId)
 {
     $ret = 0;
     if ($appointmentId > 0) {
         $appointment = new Appointment();
         $appointment->appointmentId = $appointmentId;
         $appointment->populate();
         $personId = (int) $appointment->patientId;
         $insuredRelationship = new InsuredRelationship();
         $insuredRelationship->personId = $personId;
         $visit = new Visit();
         $visit->patientId = $personId;
         $visit->activePayerId = $insuredRelationship->defaultActivePayer;
         $visit->roomId = $appointment->roomId;
         $visit->practiceId = $appointment->practiceId;
         $room = new Room();
         $room->roomId = $visit->roomId;
         $room->populate();
         $visit->buildingId = $room->buildingId;
         $visit->createdByUserId = $appointment->creatorId;
         $visit->lastChangeUserId = $appointment->lastChangeId;
         $visit->treatingPersonId = $appointment->providerId;
         $visit->encounterReason = $appointment->reason;
         $visit->dateOfTreatment = $appointment->start;
         $visit->timestamp = date('Y-m-d H:i:s');
         $visit->appointmentId = $appointment->appointmentId;
         $visit->persist();
         $visitId = (int) $visit->visitId;
         $payment = new Payment();
         foreach ($payment->getIteratorByAppointmentId($appointmentId) as $row) {
             $row->visitId = $visitId;
             $row->persist();
         }
         $miscCharge = new MiscCharge();
         foreach ($miscCharge->getIteratorByAppointmentId($appointmentId) as $row) {
             $row->visitId = $visitId;
             $row->persist();
         }
         $ret = $visitId;
     }
     return $ret;
 }
Ejemplo n.º 8
0
 /**
  * Construct an Instruments API handler
  *
  * @param string $method The HTTP request method
  * @param string $CandID The CandID to get the instruments for
  * @param string $Visit  The visit label for $CandID to retrieve
  *                       instruments for
  */
 public function __construct($method, $CandID, $Visit)
 {
     if (empty($this->AllowedMethods)) {
         $this->AllowedMethods = ['GET'];
     }
     $requestDelegationCascade = $this->AutoHandleRequestDelegation;
     // Parent will validate CandID and Visit Label and abort if necessary
     parent::__construct($method, $CandID, $Visit);
     if ($requestDelegationCascade) {
         $this->handleRequest();
     }
 }
Ejemplo n.º 9
0
 public function xmlAction()
 {
     $personId = (int) $this->_getParam('personId');
     $visitId = (int) $this->_getParam('visitId');
     $providerId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $auditType = GenericAccessAudit::CCD_ALL_XML;
     $filename = 'ccd-' . $personId;
     $visit = new Visit();
     $visit->visitId = $visitId;
     if ($visitId > 0 && $visit->populate()) {
         $filename .= '-visit-' . $visitId;
         $auditType = GenericAccessAudit::CCD_VISIT_XML;
     }
     $this->_createAudit($providerId, $personId, $visitId, $auditType);
     $ccd = new CCD();
     $contents = $ccd->populate($personId, $providerId, $visitId);
     $this->getResponse()->setHeader('Content-Type', 'text/xml');
     $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '.xml"');
     $this->view->contents = $contents;
     $this->render();
 }
Ejemplo n.º 10
0
 /**
  * Store a newly created resource in storage.
  * POST /registrations
  *
  * @return Response
  */
 public function store(Patient $patient)
 {
     $visits = Visit::where('patient_id', '=', $patient->id)->get();
     if (isset($visits) && $visits->count()) {
         foreach ($visits as $visit) {
             if ($visit->done == 1) {
                 $visit = ['patient_id' => $patient->id, 'done' => 0];
                 Visit::create($visit);
                 return Redirect::route('patient-chart-get', $patient->id)->with('global', "New Visit Started");
             } elseif ($visit->done == 0) {
                 return Redirect::route('patient-chart-get', $patient->id)->with('global', "Visit in progress");
             }
         }
     }
     $visit = ['patient_id' => $patient->id, 'done' => 0];
     Visit::create($visit);
     return Redirect::route('patient-chart-get', $patient->id)->with('global', "New Visit Started");
 }
Ejemplo n.º 11
0
 public function loginAction(Request $request, Player $me)
 {
     if ($me->isValid()) {
         throw new ForbiddenException("You are already logged in!");
     }
     $query = $request->query;
     $session = $request->getSession();
     $token = $query->get("token");
     $username = $query->get("username");
     if (!$token || !$username) {
         throw new BadRequestException();
     }
     // Don't check whether IPs match if we're on a development environment
     $checkIP = !$this->isDebug();
     $info = validate_token($token, $username, array(), $checkIP);
     if (!isset($info)) {
         throw new ForbiddenException("There was an error processing your login. Please go back and try again.");
     }
     $session->set("username", $info['username']);
     $session->set("groups", $info['groups']);
     $redirectToProfile = false;
     if (!Player::playerBZIDExists($info['bzid'])) {
         // If they're new, redirect to their profile page so they can add some info
         $player = Player::newPlayer($info['bzid'], $info['username']);
         $redirectToProfile = true;
     } else {
         $player = Player::getFromBZID($info['bzid']);
         if ($player->isDeleted()) {
             $player->setStatus('active');
         }
     }
     $session->set("playerId", $player->getId());
     $player->updateLastLogin();
     $player->setUsername($info['username']);
     Visit::enterVisit($player->getId(), $request->getClientIp(), gethostbyaddr($request->getClientIp()), $request->server->get('HTTP_USER_AGENT'), $request->server->get('HTTP_REFERER'));
     $this->configPromoteAdmin($player);
     if ($redirectToProfile) {
         $profile = Service::getGenerator()->generate('profile_show');
         return new RedirectResponse($profile);
     } else {
         return $this->goBack();
     }
 }
Ejemplo n.º 12
0
 public static function updateStatus($uid, $status)
 {
     $info = LoanSketch::findFirst("uid={$uid}");
     if (!$info) {
         return false;
     }
     //面审
     if ($status == \App\LoanStatus::getStatusFace()) {
     } else {
         if ($status == \App\LoanStatus::getStatusVisit() and Car::hasDone($uid)) {
             $status = \App\LoanStatus::getStatusChecked();
         } else {
             if ($status == \App\LoanStatus::getStatusCarAssess() and Visit::hasDone($uid)) {
                 $status = \App\LoanStatus::getStatusChecked();
             } else {
                 if (in_array($status, [\App\LoanStatus::getStatusRcAgree(), \App\LoanStatus::getStatusRcRefuse()])) {
                 }
             }
         }
     }
     $info->status = $status;
     return $info->update();
 }
Ejemplo n.º 13
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());
             }
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Visit helper function
  *
  * @return array
  */
 public function getVisit($id)
 {
     return Visit::where('patient_id', '=', $id)->where('done', '=', 0)->first();
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Visit the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Visit::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 16
0
 public function populate($patientId, $userId, $visitId)
 {
     $this->_patientId = (int) $patientId;
     $patient = new Patient();
     $patient->personId = $this->_patientId;
     $patient->populate();
     $this->_title = $patient->displayName . ' Healthcare Record';
     $this->patient = $patient;
     $this->_userId = (int) $userId;
     $user = new User();
     $user->personId = $this->_userId;
     $user->populate();
     $this->user = $user;
     $visit = new Visit();
     $visit->visitId = (int) $visitId;
     if ($visit->visitId > 0 && $visit->populate()) {
         $this->visit = $visit;
     }
     $this->building = Building::getBuildingDefaultLocation($this->user->personId);
     $performers = array();
     $problemList = new ProblemList();
     $filters = array();
     $filters['personId'] = $this->_patientId;
     $this->setFiltersDateRange($filters);
     $problems = array();
     $problemListIterator = new ProblemListIterator();
     $problemListIterator->setFilters($filters);
     foreach ($problemListIterator as $problem) {
         $problems[] = $problem;
         $providerId = (int) $problem->providerId;
         if (!isset($performers[$providerId])) {
             $provider = new Provider();
             $provider->personId = $providerId;
             $provider->populate();
             $performers[$providerId] = $provider;
         }
     }
     $this->problemLists = $problems;
     unset($filters['personId']);
     $filters['patientId'] = $this->_patientId;
     $labResults = array();
     $labTests = array();
     $labOrderTests = array();
     $labsIterator = new LabsIterator();
     $labsIterator->setFilters($filters);
     foreach ($labsIterator as $lab) {
         // get the lab order
         $labTestId = (int) $lab->labTestId;
         if (!isset($labTests[$labTestId])) {
             $labTest = new LabTest();
             $labTest->labTestId = (int) $lab->labTestId;
             $labTest->populate();
             $labTests[$labTestId] = $labTest;
         }
         $labTest = $labTests[$labTestId];
         $orderId = (int) $labTest->labOrderId;
         if (!isset($labOrderTests[$orderId])) {
             $orderLabTest = new OrderLabTest();
             $orderLabTest->orderId = $orderId;
             $orderLabTest->populate();
             $labOrderTests[$orderId] = $orderLabTest;
         }
         $orderLabTest = $labOrderTests[$orderId];
         $providerId = (int) $orderLabTest->order->providerId;
         if (!isset($performers[$providerId])) {
             $provider = new Provider();
             $provider->personId = $providerId;
             $provider->populate();
             $performers[$providerId] = $provider;
         }
         if (!isset($labResults[$orderId])) {
             $labResults[$orderId] = array();
             $labResults[$orderId]['results'] = array();
             $labResults[$orderId]['labTest'] = $labTest;
             $labResults[$orderId]['orderLabTest'] = $orderLabTest;
         }
         $labResults[$orderId]['results'][] = $lab;
     }
     $this->labResults = $labResults;
     $this->performers = $performers;
     $this->populateHeader($this->_xml);
     $this->populateBody($this->_xml);
     return $this->_xml->asXML();
 }
Ejemplo n.º 17
0
        $this->createNew($this->CandID, $subprojectID, $this->VisitLabel);
        $this->header("HTTP/1.1 201 Created");
    }
    /**
     * Create a new timepoint
     *
     * This is a wrapper around the Timepoint::createNew function
     * that can be stubbed out for testing.
     *
     * @param integer $CandID       The candidate with the visit
     * @param integer $subprojectID The subproject for the new visit
     * @param string  $VL           The visit label of the visit to
     *                              be created
     *
     * @return none
     */
    function createNew($CandID, $subprojectID, $VL)
    {
        \TimePoint::createNew($CandID, $subprojectID, $VL);
    }
}
if (isset($_REQUEST['PrintVisit'])) {
    parse_str(urldecode(file_get_contents("php://input")), $InputDataArray);
    $InputData = json_encode($InputDataArray);
    if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
        $obj = new Visit($_SERVER['REQUEST_METHOD'], $_REQUEST['CandID'], $_REQUEST['VisitLabel'], $InputData);
    } else {
        $obj = new Visit($_SERVER['REQUEST_METHOD'], $_REQUEST['CandID'], $_REQUEST['VisitLabel']);
    }
    print $obj->toJSONString();
}
Ejemplo n.º 18
0
 public function actionDeletevisit()
 {
     if (Yii::app()->request->isPostRequest) {
         $model = Visit::model()->findByPk($_POST["id"]);
         if ($model->to_user == Yii::app()->user->id || Yii::app()->user->id == $model->from_user) {
             $model->delete();
             echo "ok";
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
Ejemplo n.º 19
0
 public function run()
 {
     /* Users table */
     $usersData = array(array("username" => "administrator", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "kBLIS Administrator", "designation" => "Programmer"), array("username" => "external", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "External System User", "designation" => "Administrator", "image" => "/i/users/user-2.jpg"), array("username" => "lmorena", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "L. Morena", "designation" => "Lab Technologist", "image" => "/i/users/user-3.png"), array("username" => "abumeyang", "password" => Hash::make("password"), "email" => "*****@*****.**", "name" => "A. Abumeyang", "designation" => "Doctor"));
     foreach ($usersData as $user) {
         $users[] = User::create($user);
     }
     $this->command->info('users seeded');
     /* Specimen Types table */
     $specTypesData = array(array("name" => "Ascitic Tap"), array("name" => "Aspirate"), array("name" => "CSF"), array("name" => "Dried Blood Spot"), array("name" => "High Vaginal Swab"), array("name" => "Nasal Swab"), array("name" => "Plasma"), array("name" => "Plasma EDTA"), array("name" => "Pleural Tap"), array("name" => "Pus Swab"), array("name" => "Rectal Swab"), array("name" => "S***n"), array("name" => "Serum"), array("name" => "Skin"), array("name" => "Sputum"), array("name" => "Stool"), array("name" => "Synovial Fluid"), array("name" => "Throat Swab"), array("name" => "Urethral Smear"), array("name" => "Urine"), array("name" => "Vaginal Smear"), array("name" => "Water"), array("name" => "Whole Blood"));
     foreach ($specTypesData as $specimenType) {
         $specTypes[] = SpecimenType::create($specimenType);
     }
     $this->command->info('specimen_types seeded');
     /* Test Categories table - These map on to the lab sections */
     $test_categories = TestCategory::create(array("name" => "PARASITOLOGY", "description" => ""));
     $lab_section_microbiology = TestCategory::create(array("name" => "MICROBIOLOGY", "description" => ""));
     $this->command->info('test_categories seeded');
     /* Measure Types */
     $measureTypes = array(array("id" => "1", "name" => "Numeric Range"), array("id" => "2", "name" => "Alphanumeric Values"), array("id" => "3", "name" => "Autocomplete"), array("id" => "4", "name" => "Free Text"));
     foreach ($measureTypes as $measureType) {
         MeasureType::create($measureType);
     }
     $this->command->info('measure_types seeded');
     /* Measures table */
     $measureBSforMPS = Measure::create(array("measure_type_id" => "2", "name" => "BS for mps", "unit" => ""));
     $measure1 = Measure::create(array("measure_type_id" => "2", "name" => "Grams stain", "unit" => ""));
     $measure2 = Measure::create(array("measure_type_id" => "2", "name" => "SERUM AMYLASE", "unit" => ""));
     $measure3 = Measure::create(array("measure_type_id" => "2", "name" => "calcium", "unit" => ""));
     $measure4 = Measure::create(array("measure_type_id" => "2", "name" => "SGOT", "unit" => ""));
     $measure5 = Measure::create(array("measure_type_id" => "2", "name" => "Indirect COOMBS test", "unit" => ""));
     $measure6 = Measure::create(array("measure_type_id" => "2", "name" => "Direct COOMBS test", "unit" => ""));
     $measure7 = Measure::create(array("measure_type_id" => "2", "name" => "Du test", "unit" => ""));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "No mps seen", "interpretation" => "Negative"));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "+", "interpretation" => "Positive"));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "++", "interpretation" => "Positive"));
     MeasureRange::create(array("measure_id" => $measureBSforMPS->id, "alphanumeric" => "+++", "interpretation" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure1->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure1->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure2->id, "alphanumeric" => "Low"));
     MeasureRange::create(array("measure_id" => $measure2->id, "alphanumeric" => "High"));
     MeasureRange::create(array("measure_id" => $measure2->id, "alphanumeric" => "Normal"));
     MeasureRange::create(array("measure_id" => $measure3->id, "alphanumeric" => "High"));
     MeasureRange::create(array("measure_id" => $measure3->id, "alphanumeric" => "Low"));
     MeasureRange::create(array("measure_id" => $measure3->id, "alphanumeric" => "Normal"));
     MeasureRange::create(array("measure_id" => $measure4->id, "alphanumeric" => "High"));
     MeasureRange::create(array("measure_id" => $measure4->id, "alphanumeric" => "Low"));
     MeasureRange::create(array("measure_id" => $measure4->id, "alphanumeric" => "Normal"));
     MeasureRange::create(array("measure_id" => $measure5->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure5->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure6->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure6->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure7->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure7->id, "alphanumeric" => "Negative"));
     $measures = array(array("measure_type_id" => "1", "name" => "URIC ACID", "unit" => "mg/dl"), array("measure_type_id" => "4", "name" => "CSF for biochemistry", "unit" => ""), array("measure_type_id" => "4", "name" => "PSA", "unit" => ""), array("measure_type_id" => "1", "name" => "Total", "unit" => "mg/dl"), array("measure_type_id" => "1", "name" => "Alkaline Phosphate", "unit" => "u/l"), array("measure_type_id" => "1", "name" => "Direct", "unit" => "mg/dl"), array("measure_type_id" => "1", "name" => "Total Proteins", "unit" => ""), array("measure_type_id" => "4", "name" => "LFTS", "unit" => "NULL"), array("measure_type_id" => "1", "name" => "Chloride", "unit" => "mmol/l"), array("measure_type_id" => "1", "name" => "Potassium", "unit" => "mmol/l"), array("measure_type_id" => "1", "name" => "Sodium", "unit" => "mmol/l"), array("measure_type_id" => "4", "name" => "Electrolytes", "unit" => ""), array("measure_type_id" => "1", "name" => "Creatinine", "unit" => "mg/dl"), array("measure_type_id" => "1", "name" => "Urea", "unit" => "mg/dl"), array("measure_type_id" => "4", "name" => "RFTS", "unit" => ""), array("measure_type_id" => "4", "name" => "TFT", "unit" => ""));
     foreach ($measures as $measure) {
         Measure::create($measure);
     }
     $measureGXM = Measure::create(array("measure_type_id" => "4", "name" => "GXM", "unit" => ""));
     $measureBG = Measure::create(array("measure_type_id" => "2", "name" => "Blood Grouping", "unit" => ""));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "O-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "O+"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "A-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "A+"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "B-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "B+"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "AB-"));
     MeasureRange::create(array("measure_id" => $measureBG->id, "alphanumeric" => "AB+"));
     $measureHB = Measure::create(array("measure_type_id" => Measure::NUMERIC, "name" => "HB", "unit" => "g/dL"));
     $measuresUrinalysisData = array(array("measure_type_id" => "4", "name" => "Urine microscopy", "unit" => ""), array("measure_type_id" => "4", "name" => "Pus cells", "unit" => ""), array("measure_type_id" => "4", "name" => "S. haematobium", "unit" => ""), array("measure_type_id" => "4", "name" => "T. vaginalis", "unit" => ""), array("measure_type_id" => "4", "name" => "Yeast cells", "unit" => ""), array("measure_type_id" => "4", "name" => "Red blood cells", "unit" => ""), array("measure_type_id" => "4", "name" => "Bacteria", "unit" => ""), array("measure_type_id" => "4", "name" => "Spermatozoa", "unit" => ""), array("measure_type_id" => "4", "name" => "Epithelial cells", "unit" => ""), array("measure_type_id" => "4", "name" => "ph", "unit" => ""), array("measure_type_id" => "4", "name" => "Urine chemistry", "unit" => ""), array("measure_type_id" => "4", "name" => "Glucose", "unit" => ""), array("measure_type_id" => "4", "name" => "Ketones", "unit" => ""), array("measure_type_id" => "4", "name" => "Proteins", "unit" => ""), array("measure_type_id" => "4", "name" => "Blood", "unit" => ""), array("measure_type_id" => "4", "name" => "Bilirubin", "unit" => ""), array("measure_type_id" => "4", "name" => "Urobilinogen Phenlpyruvic acid", "unit" => ""), array("measure_type_id" => "4", "name" => "pH", "unit" => ""));
     foreach ($measuresUrinalysisData as $measureU) {
         $measuresUrinalysis[] = Measure::create($measureU);
     }
     $measuresWBCData = array(array("measure_type_id" => Measure::NUMERIC, "name" => "WBC", "unit" => "x10³/µL"), array("measure_type_id" => Measure::NUMERIC, "name" => "Lym", "unit" => "L"), array("measure_type_id" => Measure::NUMERIC, "name" => "Mon", "unit" => "*"), array("measure_type_id" => Measure::NUMERIC, "name" => "Neu", "unit" => "*"), array("measure_type_id" => Measure::NUMERIC, "name" => "Eos", "unit" => ""), array("measure_type_id" => Measure::NUMERIC, "name" => "Baso", "unit" => ""));
     foreach ($measuresWBCData as $value) {
         $measuresWBC[] = Measure::create($value);
     }
     $measureRangesWBC = array(array("measure_id" => $measuresWBC[0]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 4, "range_upper" => 11), array("measure_id" => $measuresWBC[1]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 1.5, "range_upper" => 4), array("measure_id" => $measuresWBC[2]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 0.1, "range_upper" => 9), array("measure_id" => $measuresWBC[3]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 2.5, "range_upper" => 7), array("measure_id" => $measuresWBC[4]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 0, "range_upper" => 6), array("measure_id" => $measuresWBC[5]->id, "age_min" => 0, "age_max" => 100, "gender" => MeasureRange::BOTH, "range_lower" => 0, "range_upper" => 2));
     foreach ($measureRangesWBC as $value) {
         MeasureRange::create($value);
     }
     $this->command->info('measures seeded');
     /* Test Types table */
     $testTypeBS = TestType::create(array("name" => "BS for mps", "test_category_id" => $test_categories->id, "orderable_test" => 1));
     $testTypeStoolCS = TestType::create(array("name" => "Stool for C/S", "test_category_id" => $lab_section_microbiology->id));
     $testTypeGXM = TestType::create(array("name" => "GXM", "test_category_id" => $test_categories->id));
     $testTypeHB = TestType::create(array("name" => "HB", "test_category_id" => $test_categories->id, "orderable_test" => 1));
     $testTypeUrinalysis = TestType::create(array("name" => "Urinalysis", "test_category_id" => $test_categories->id));
     $testTypeWBC = TestType::create(array("name" => "WBC", "test_category_id" => $test_categories->id));
     $this->command->info('test_types seeded');
     /* TestType Measure table */
     TestTypeMeasure::create(array("test_type_id" => $testTypeBS->id, "measure_id" => $measureBSforMPS->id));
     TestTypeMeasure::create(array("test_type_id" => $testTypeGXM->id, "measure_id" => $measureGXM->id));
     TestTypeMeasure::create(array("test_type_id" => $testTypeGXM->id, "measure_id" => $measureBG->id));
     TestTypeMeasure::create(array("test_type_id" => $testTypeHB->id, "measure_id" => $measureHB->id));
     foreach ($measuresUrinalysis as $value) {
         TestTypeMeasure::create(array("test_type_id" => $testTypeUrinalysis->id, "measure_id" => $value->id));
     }
     foreach ($measuresWBC as $value) {
         TestTypeMeasure::create(array("test_type_id" => $testTypeWBC->id, "measure_id" => $value->id));
     }
     $this->command->info('testtype_measures seeded');
     /* testtype_specimentypes table */
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeBS->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeGXM->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[6]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[7]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeHB->id, "specimen_type_id" => $specTypes[12]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeUrinalysis->id, "specimen_type_id" => $specTypes[19]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeUrinalysis->id, "specimen_type_id" => $specTypes[20]->id));
     DB::table('testtype_specimentypes')->insert(array("test_type_id" => $testTypeWBC->id, "specimen_type_id" => $specTypes[count($specTypes) - 1]->id));
     $this->command->info('testtype_specimentypes seeded');
     /* Patients table */
     $patients_array = array(array("name" => "Jam Felicia", "email" => "*****@*****.**", "patient_number" => "1002", "dob" => "2000-01-01", "gender" => "1", "created_by" => "2"), array("name" => "Emma Wallace", "email" => "*****@*****.**", "patient_number" => "1003", "dob" => "1990-03-01", "gender" => "1", "created_by" => "2"), array("name" => "Jack Tee", "email" => "*****@*****.**", "patient_number" => "1004", "dob" => "1999-12-18", "gender" => "0", "created_by" => "1"), array("name" => "Hu Jintao", "email" => "*****@*****.**", "patient_number" => "1005", "dob" => "1956-10-28", "gender" => "0", "created_by" => "2"), array("name" => "Lance Opiyo", "email" => "*****@*****.**", "patient_number" => "2150", "dob" => "2012-01-01", "gender" => "0", "created_by" => "1"));
     foreach ($patients_array as $pat) {
         $patients[] = Patient::create($pat);
     }
     $this->command->info('patients seeded');
     /* Test Phase table */
     $test_phases = array(array("id" => "1", "name" => "Pre-Analytical"), array("id" => "2", "name" => "Analytical"), array("id" => "3", "name" => "Post-Analytical"));
     foreach ($test_phases as $test_phase) {
         TestPhase::create($test_phase);
     }
     $this->command->info('test_phases seeded');
     /* Test Status table */
     $test_statuses = array(array("id" => "1", "name" => "not-received", "test_phase_id" => "1"), array("id" => "2", "name" => "pending", "test_phase_id" => "1"), array("id" => "3", "name" => "started", "test_phase_id" => "2"), array("id" => "4", "name" => "completed", "test_phase_id" => "3"), array("id" => "5", "name" => "verified", "test_phase_id" => "3"));
     foreach ($test_statuses as $test_status) {
         TestStatus::create($test_status);
     }
     $this->command->info('test_statuses seeded');
     /* Specimen Status table */
     $specimen_statuses = array(array("id" => "1", "name" => "specimen-not-collected"), array("id" => "2", "name" => "specimen-accepted"), array("id" => "3", "name" => "specimen-rejected"));
     foreach ($specimen_statuses as $specimen_status) {
         SpecimenStatus::create($specimen_status);
     }
     $this->command->info('specimen_statuses seeded');
     /* Visits table */
     for ($i = 0; $i < 7; $i++) {
         $visits[] = Visit::create(array("patient_id" => $patients[rand(0, count($patients) - 1)]->id));
     }
     $this->command->info('visits seeded');
     /* Rejection Reasons table */
     $rejection_reasons_array = array(array("reason" => "Poorly labelled"), array("reason" => "Over saturation"), array("reason" => "Insufficient Sample"), array("reason" => "Scattered"), array("reason" => "Clotted Blood"), array("reason" => "Two layered spots"), array("reason" => "Serum rings"), array("reason" => "Scratched"), array("reason" => "Haemolysis"), array("reason" => "Spots that cannot elute"), array("reason" => "Leaking"), array("reason" => "Broken Sample Container"), array("reason" => "Mismatched sample and form labelling"), array("reason" => "Missing Labels on container and tracking form"), array("reason" => "Empty Container"), array("reason" => "Samples without tracking forms"), array("reason" => "Poor transport"), array("reason" => "Lipaemic"), array("reason" => "Wrong container/Anticoagulant"), array("reason" => "Request form without samples"), array("reason" => "Missing collection date on specimen / request form."), array("reason" => "Name and signature of requester missing"), array("reason" => "Mismatched information on request form and specimen container."), array("reason" => "Request form contaminated with specimen"), array("reason" => "Duplicate specimen received"), array("reason" => "Delay between specimen collection and arrival in the laboratory"), array("reason" => "Inappropriate specimen packing"), array("reason" => "Inappropriate specimen for the test"), array("reason" => "Inappropriate test for the clinical condition"), array("reason" => "No Label"), array("reason" => "Leaking"), array("reason" => "No Sample in the Container"), array("reason" => "No Request Form"), array("reason" => "Missing Information Required"));
     foreach ($rejection_reasons_array as $rejection_reason) {
         $rejection_reasons[] = RejectionReason::create($rejection_reason);
     }
     $this->command->info('rejection_reasons seeded');
     /* Specimen table */
     $this->command->info('specimens seeded');
     $now = new DateTime();
     /* Test table */
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::NOT_RECEIVED, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::NOT_RECEIVED, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeHB->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeGXM->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "created_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Dr. Abou Meyang"));
     $test_gxm_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeGXM->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Perfect match.", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Dr. Abou Meyang", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT12M8S'))->format('Y-m-d H:i:s')));
     $test_hb_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeHB->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Do nothing!", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Genghiz Khan", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT5M23S'))->format('Y-m-d H:i:s')));
     $tests_accepted_started = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeGXM->id, "specimen_id" => $this->createSpecimen(Test::STARTED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::STARTED, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id, "time_started" => $now->format('Y-m-d H:i:s')));
     $tests_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Positive", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Ariel Smith", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT7M34S'))->format('Y-m-d H:i:s')));
     $tests_accepted_verified = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::VERIFIED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Very high concentration of parasites.", "test_status_id" => Test::VERIFIED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "verified_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Genghiz Khan", "time_started" => $now, "time_completed" => $now->add(new DateInterval('PT5M17S'))->format('Y-m-d H:i:s'), "time_verified" => $now->add(new DateInterval('PT112M33S'))->format('Y-m-d H:i:s')));
     $tests_rejected_pending = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::REJECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id, $users[rand(0, count($users) - 1)]->id, $rejection_reasons[rand(0, count($rejection_reasons) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id, "time_started" => $now->format('Y-m-d H:i:s')));
     //  WBC Started
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeWBC->id, "specimen_id" => $this->createSpecimen(Test::STARTED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Fred Astaire", "created_by" => $users[rand(0, count($users) - 1)]->id));
     $tests_rejected_started = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::STARTED, Specimen::REJECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id, $users[rand(0, count($users) - 1)]->id, $rejection_reasons[rand(0, count($rejection_reasons) - 1)]->id), "test_status_id" => Test::STARTED, "created_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Bony Em", "time_started" => $now->format('Y-m-d H:i:s')));
     $tests_rejected_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeBS->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::REJECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id, $users[rand(0, count($users) - 1)]->id, $rejection_reasons[rand(0, count($rejection_reasons) - 1)]->id), "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Ed Buttler", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT30M4S'))->format('Y-m-d H:i:s')));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeUrinalysis->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeWBC->id, "specimen_id" => $this->createSpecimen(Test::PENDING, Specimen::NOT_COLLECTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "test_status_id" => Test::PENDING, "requested_by" => "Dr. Abou Meyang", "created_by" => $users[rand(0, count($users) - 1)]->id));
     $test_urinalysis_accepted_completed = Test::create(array("visit_id" => $visits[rand(0, count($visits) - 1)]->id, "test_type_id" => $testTypeUrinalysis->id, "specimen_id" => $this->createSpecimen(Test::COMPLETED, Specimen::ACCEPTED, SpecimenType::all()->last()->id, $users[rand(0, count($users) - 1)]->id), "interpretation" => "Whats this !!!! ###%%% ^ *() /", "test_status_id" => Test::COMPLETED, "created_by" => $users[rand(0, count($users) - 1)]->id, "tested_by" => $users[rand(0, count($users) - 1)]->id, "requested_by" => "Dr. Abou Meyang", "time_started" => $now->format('Y-m-d H:i:s'), "time_completed" => $now->add(new DateInterval('PT12M8S'))->format('Y-m-d H:i:s'), "external_id" => 596699));
     $this->command->info('tests seeded');
     /* Test Results table */
     $testResults = array(array("test_id" => $tests_accepted_verified->id, "measure_id" => $measureBSforMPS->id, "result" => "+++"), array("test_id" => $tests_accepted_completed->id, "measure_id" => $measureBSforMPS->id, "result" => "++"), array("test_id" => $test_gxm_accepted_completed->id, "measure_id" => $measureGXM->id, "result" => "COMPATIBLE WITH 061832914 B/G A POS.EXPIRY19/8/14"), array("test_id" => $test_gxm_accepted_completed->id, "measure_id" => $measureBG->id, "result" => "A+"), array("test_id" => $test_hb_accepted_completed->id, "measure_id" => $measureHB->id, "result" => "13.7"), array("test_id" => $tests_rejected_completed->id, "measure_id" => $measureBSforMPS->id, "result" => "No mps seen"));
     foreach ($measuresUrinalysis as $key => $measure) {
         $testResults[] = array("test_id" => $test_urinalysis_accepted_completed->id, "measure_id" => $measure->id, "result" => $key . "50");
     }
     foreach ($testResults as $testResult) {
         TestResult::create($testResult);
     }
     $this->command->info('test results seeded');
     /* Permissions table */
     $permissions = array(array("name" => "view_names", "display_name" => "Can view patient names"), array("name" => "manage_patients", "display_name" => "Can add patients"), array("name" => "receive_external_test", "display_name" => "Can receive test requests"), array("name" => "request_test", "display_name" => "Can request new test"), array("name" => "accept_test_specimen", "display_name" => "Can accept test specimen"), array("name" => "reject_test_specimen", "display_name" => "Can reject test specimen"), array("name" => "change_test_specimen", "display_name" => "Can change test specimen"), array("name" => "start_test", "display_name" => "Can start tests"), array("name" => "enter_test_results", "display_name" => "Can enter tests results"), array("name" => "edit_test_results", "display_name" => "Can edit test results"), array("name" => "verify_test_results", "display_name" => "Can verify test results"), array("name" => "send_results_to_external_system", "display_name" => "Can send test results to external systems"), array("name" => "refer_specimens", "display_name" => "Can refer specimens"), array("name" => "manage_users", "display_name" => "Can manage users"), array("name" => "manage_test_catalog", "display_name" => "Can manage test catalog"), array("name" => "manage_lab_configurations", "display_name" => "Can manage lab configurations"), array("name" => "view_reports", "display_name" => "Can view reports"), array("name" => "manage_inventory", "display_name" => "Can manage inventory"), array("name" => "request_topup", "display_name" => "Can request top-up"), array("name" => "manage_qc", "display_name" => "Can manage Quality Control"));
     foreach ($permissions as $permission) {
         Permission::create($permission);
     }
     $this->command->info('Permissions table seeded');
     /* Roles table */
     $roles = array(array("name" => "Superadmin"), array("name" => "Technologist"), array("name" => "Receptionist"));
     foreach ($roles as $role) {
         Role::create($role);
     }
     $this->command->info('Roles table seeded');
     $user1 = User::find(1);
     $role1 = Role::find(1);
     $permissions = Permission::all();
     //Assign all permissions to role administrator
     foreach ($permissions as $permission) {
         $role1->attachPermission($permission);
     }
     //Assign role Administrator to user 1 administrator
     $user1->attachRole($role1);
     /* Instruments table */
     $instrumentsData = array("name" => "Celltac F Mek 8222", "description" => "Automatic analyzer with 22 parameters and WBC 5 part diff Hematology Analyzer", "driver_name" => "KBLIS\\Plugins\\CelltacFMachine", "ip" => "192.168.1.12", "hostname" => "HEMASERVER");
     $instrument = Instrument::create($instrumentsData);
     $instrument->testTypes()->attach(array($testTypeWBC->id));
     $this->command->info('Instruments table seeded');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596699,"parentLabNo":0,"requestingClinician":"frankenstein Dr",
     "investigation":"Urinalysis","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596700,"parentLabNo":596699,"requestingClinician":"frankenstein Dr",
     "investigation":"Urine microscopy","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596701,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Pus cells","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596702,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"S. haematobium","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596703,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"T. vaginalis","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596704,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Yeast cells","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596705,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Red blood cells","requestDate":"2014-10-14 10:20:35","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596706,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Bacteria","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596707,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Spermatozoa","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596708,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"Epithelial cells","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596709,"parentLabNo":596700,"requestingClinician":"frankenstein Dr",
     "investigation":"ph","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596710,"parentLabNo":596699,"requestingClinician":"frankenstein Dr",
     "investigation":"Urine chemistry","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596711,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Glucose","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596712,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Ketones","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596713,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Proteins","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596714,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Blood","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596715,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Bilirubin","requestDate":"2014-10-14 10:20:36","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596716,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"Urobilinogen Phenlpyruvic acid","requestDate":"2014-10-14 10:20:37","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     $labRequestUrinalysis[] = json_decode('{"cost":null,"receiptNumber":null,"receiptType":null,"labNo":596717,"parentLabNo":596710,"requestingClinician":"frankenstein Dr",
     "investigation":"pH","requestDate":"2014-10-14 10:20:37","orderStage":"ip","patientVisitNumber":643660,"patient":{"id":326983,
     "fullName":"Macau Macau","dateOfBirth":"1996-10-09 00:00:00","gender":"Female"},"address":{"address":null,"postalCode":null,"phoneNumber":"","city":null}}');
     for ($i = 0; $i < count($labRequestUrinalysis); $i++) {
         $dumper = new ExternalDump();
         $dumper->lab_no = $labRequestUrinalysis[$i]->labNo;
         $dumper->parent_lab_no = $labRequestUrinalysis[$i]->parentLabNo;
         $dumper->test_id = $i == 0 ? $test_urinalysis_accepted_completed->id : null;
         $dumper->requesting_clinician = $labRequestUrinalysis[$i]->requestingClinician;
         $dumper->investigation = $labRequestUrinalysis[$i]->investigation;
         $dumper->provisional_diagnosis = '';
         $dumper->request_date = $labRequestUrinalysis[$i]->requestDate;
         $dumper->order_stage = $labRequestUrinalysis[$i]->orderStage;
         $dumper->patient_visit_number = $labRequestUrinalysis[$i]->patientVisitNumber;
         $dumper->patient_id = $labRequestUrinalysis[$i]->patient->id;
         $dumper->full_name = $labRequestUrinalysis[$i]->patient->fullName;
         $dumper->dob = $labRequestUrinalysis[$i]->patient->dateOfBirth;
         $dumper->gender = $labRequestUrinalysis[$i]->patient->gender;
         $dumper->address = $labRequestUrinalysis[$i]->address->address;
         $dumper->postal_code = '';
         $dumper->phone_number = $labRequestUrinalysis[$i]->address->phoneNumber;
         $dumper->city = $labRequestUrinalysis[$i]->address->city;
         $dumper->cost = $labRequestUrinalysis[$i]->cost;
         $dumper->receipt_number = $labRequestUrinalysis[$i]->receiptNumber;
         $dumper->receipt_type = $labRequestUrinalysis[$i]->receiptType;
         $dumper->waiver_no = '';
         $dumper->system_id = "sanitas";
         $dumper->save();
     }
     $this->command->info('ExternalDump table seeded');
     //  Begin seed for prevalence rates report
     /* Test Categories table - These map on to the lab sections */
     $lab_section_hematology = TestCategory::create(array("name" => "HEMATOLOGY", "description" => ""));
     $lab_section_serology = TestCategory::create(array("name" => "SEROLOGY", "description" => ""));
     $lab_section_trans = TestCategory::create(array("name" => "BLOOD TRANSFUSION", "description" => ""));
     $this->command->info('Lab Sections seeded');
     /* Test Types for prevalence */
     $test_types_salmonella = TestType::create(array("name" => "Salmonella Antigen Test", "test_category_id" => $test_categories->id));
     $test_types_direct = TestType::create(array("name" => "Direct COOMBS Test", "test_category_id" => $lab_section_trans->id));
     $test_types_du = TestType::create(array("name" => "DU Test", "test_category_id" => $lab_section_trans->id));
     $test_types_sickling = TestType::create(array("name" => "Sickling Test", "test_category_id" => $lab_section_hematology->id));
     $test_types_borrelia = TestType::create(array("name" => "Borrelia", "test_category_id" => $test_categories->id));
     $test_types_vdrl = TestType::create(array("name" => "VDRL", "test_category_id" => $lab_section_serology->id));
     $test_types_pregnancy = TestType::create(array("name" => "Pregnancy Test", "test_category_id" => $lab_section_serology->id));
     $test_types_brucella = TestType::create(array("name" => "Brucella", "test_category_id" => $lab_section_serology->id));
     $test_types_pylori = TestType::create(array("name" => "H. Pylori", "test_category_id" => $lab_section_serology->id));
     $this->command->info('Test Types seeded');
     /* Test Types and specimen types relationship for prevalence */
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_salmonella->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_direct->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_du->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_sickling->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_borrelia->id, "23"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_vdrl->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_pregnancy->id, "20"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_brucella->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($test_types_pylori->id, "13"));
     DB::insert('INSERT INTO testtype_specimentypes (test_type_id, specimen_type_id) VALUES (?, ?)', array($testTypeStoolCS->id, "16"));
     $this->command->info('TestTypes/SpecimenTypes seeded');
     /*New measures for prevalence*/
     $measure_salmonella = Measure::create(array("measure_type_id" => "2", "name" => "Salmonella Antigen Test", "unit" => ""));
     $measure_direct = Measure::create(array("measure_type_id" => "2", "name" => "Direct COOMBS Test", "unit" => ""));
     $measure_du = Measure::create(array("measure_type_id" => "2", "name" => "Du Test", "unit" => ""));
     $measure_sickling = Measure::create(array("measure_type_id" => "2", "name" => "Sickling Test", "unit" => ""));
     $measure_borrelia = Measure::create(array("measure_type_id" => "2", "name" => "Borrelia", "unit" => ""));
     $measure_vdrl = Measure::create(array("measure_type_id" => "2", "name" => "VDRL", "unit" => ""));
     $measure_pregnancy = Measure::create(array("measure_type_id" => "2", "name" => "Pregnancy Test", "unit" => ""));
     $measure_brucella = Measure::create(array("measure_type_id" => "2", "name" => "Brucella", "unit" => ""));
     $measure_pylori = Measure::create(array("measure_type_id" => "2", "name" => "H. Pylori", "unit" => ""));
     MeasureRange::create(array("measure_id" => $measure_salmonella->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_salmonella->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_direct->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_direct->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_du->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_du->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_sickling->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_sickling->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_borrelia->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_borrelia->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_vdrl->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_vdrl->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_pregnancy->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_pregnancy->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_brucella->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_brucella->id, "alphanumeric" => "Negative"));
     MeasureRange::create(array("measure_id" => $measure_pylori->id, "alphanumeric" => "Positive"));
     MeasureRange::create(array("measure_id" => $measure_pylori->id, "alphanumeric" => "Negative"));
     $this->command->info('Measures seeded again');
     /* TestType Measure for prevalence */
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_salmonella->id, "measure_id" => $measure_salmonella->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_direct->id, "measure_id" => $measure_direct->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_du->id, "measure_id" => $measure_du->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_sickling->id, "measure_id" => $measure_sickling->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_borrelia->id, "measure_id" => $measure_borrelia->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_vdrl->id, "measure_id" => $measure_vdrl->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_pregnancy->id, "measure_id" => $measure_pregnancy->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_brucella->id, "measure_id" => $measure_brucella->id));
     $testtype_measure = TestTypeMeasure::create(array("test_type_id" => $test_types_pylori->id, "measure_id" => $measure_pylori->id));
     $this->command->info('Test Type Measures seeded again');
     /*  Tests for prevalence rates  */
     $tests_completed_one = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_salmonella->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-07-23 15:16:15", "time_started" => "2014-07-23 16:07:15", "time_completed" => "2014-07-23 16:17:19"));
     $tests_completed_two = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_direct->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-07-26 10:16:15", "time_started" => "2014-07-26 13:27:15", "time_completed" => "2014-07-26 13:57:01"));
     $tests_completed_three = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_du->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-08-13 09:16:15", "time_started" => "2014-08-13 10:07:15", "time_completed" => "2014-08-13 10:18:11"));
     $tests_completed_four = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_sickling->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-08-16 09:06:53", "time_started" => "2014-08-16 09:09:15", "time_completed" => "2014-08-16 09:23:37"));
     $tests_completed_five = Test::create(array("visit_id" => "5", "test_type_id" => $test_types_borrelia->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-08-23 10:16:15", "time_started" => "2014-08-23 11:54:39", "time_completed" => "2014-08-23 12:07:18"));
     $tests_completed_six = Test::create(array("visit_id" => "6", "test_type_id" => $test_types_vdrl->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-09-07 07:23:15", "time_started" => "2014-09-07 08:07:20", "time_completed" => "2014-09-07 08:41:13"));
     $tests_completed_seven = Test::create(array("visit_id" => "7", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-03 11:52:15", "time_started" => "2014-10-03 12:31:04", "time_completed" => "2014-10-03 12:45:18"));
     $tests_completed_eight = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_brucella->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-15 17:01:15", "time_started" => "2014-10-15 17:05:24", "time_completed" => "2014-10-15 18:07:15"));
     $tests_completed_nine = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_pylori->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-23 16:06:15", "time_started" => "2014-10-23 16:07:15", "time_completed" => "2014-10-23 16:39:02"));
     $tests_completed_ten = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_salmonella->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::COMPLETED, "created_by" => "2", "tested_by" => "3", "requested_by" => "Ariel Smith", "time_created" => "2014-10-21 19:16:15", "time_started" => "2014-10-21 19:17:15", "time_completed" => "2014-10-21 19:52:40"));
     $tests_verified_one = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_direct->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-07-21 19:16:15", "time_started" => "2014-07-21 19:17:15", "time_completed" => "2014-07-21 19:52:40", "time_verified" => "2014-07-21 19:53:48"));
     $tests_verified_two = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_du->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-08-21 19:16:15", "time_started" => "2014-08-21 19:17:15", "time_completed" => "2014-08-21 19:52:40", "time_verified" => "2014-08-21 19:53:48"));
     $tests_verified_three = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_sickling->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-08-26 19:16:15", "time_started" => "2014-08-26 19:17:15", "time_completed" => "2014-08-26 19:52:40", "time_verified" => "2014-08-26 19:53:48"));
     $tests_verified_four = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_borrelia->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-21 19:16:15", "time_started" => "2014-09-21 19:17:15", "time_completed" => "2014-09-21 19:52:40", "time_verified" => "2014-09-21 19:53:48"));
     $tests_verified_five = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_vdrl->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-22 19:16:15", "time_started" => "2014-09-22 19:17:15", "time_completed" => "2014-09-22 19:52:40", "time_verified" => "2014-09-22 19:53:48"));
     $tests_verified_six = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-23 19:16:15", "time_started" => "2014-09-23 19:17:15", "time_completed" => "2014-09-23 19:52:40", "time_verified" => "2014-09-23 19:53:48"));
     $tests_verified_seven = Test::create(array("visit_id" => "1", "test_type_id" => $test_types_brucella->id, "specimen_id" => "2", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-09-27 19:16:15", "time_started" => "2014-09-27 19:17:15", "time_completed" => "2014-09-27 19:52:40", "time_verified" => "2014-09-27 19:53:48"));
     $tests_verified_eight = Test::create(array("visit_id" => "3", "test_type_id" => $test_types_pylori->id, "specimen_id" => "4", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-10-22 19:16:15", "time_started" => "2014-10-22 19:17:15", "time_completed" => "2014-10-22 19:52:40", "time_verified" => "2014-10-22 19:53:48"));
     $tests_verified_nine = Test::create(array("visit_id" => "4", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "3", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-10-17 19:16:15", "time_started" => "2014-10-17 19:17:15", "time_completed" => "2014-10-17 19:52:40", "time_verified" => "2014-10-17 19:53:48"));
     $tests_verified_ten = Test::create(array("visit_id" => "2", "test_type_id" => $test_types_pregnancy->id, "specimen_id" => "1", "interpretation" => "Budda Boss", "test_status_id" => Test::VERIFIED, "created_by" => "3", "tested_by" => "2", "verified_by" => "3", "requested_by" => "Genghiz Khan", "time_created" => "2014-10-02 19:16:15", "time_started" => "2014-10-02 19:17:15", "time_completed" => "2014-10-02 19:52:40", "time_verified" => "2014-10-02 19:53:48"));
     $this->command->info('Tests seeded again');
     //  Test results for prevalence
     $results = array(array("test_id" => $tests_completed_one->id, "measure_id" => $measure_salmonella->id, "result" => "Positive"), array("test_id" => $tests_completed_two->id, "measure_id" => $measure_direct->id, "result" => "Positive"), array("test_id" => $tests_completed_three->id, "measure_id" => $measure_du->id, "result" => "Positive"), array("test_id" => $tests_completed_four->id, "measure_id" => $measure_sickling->id, "result" => "Positive"), array("test_id" => $tests_completed_five->id, "measure_id" => $measure_borrelia->id, "result" => "Positive"), array("test_id" => $tests_completed_six->id, "measure_id" => $measure_vdrl->id, "result" => "Positive"), array("test_id" => $tests_completed_seven->id, "measure_id" => $measure_pregnancy->id, "result" => "Positive"), array("test_id" => $tests_completed_eight->id, "measure_id" => $measure_brucella->id, "result" => "Positive"), array("test_id" => $tests_completed_nine->id, "measure_id" => $measure_pylori->id, "result" => "Positive"), array("test_id" => $tests_completed_ten->id, "measure_id" => $measure_salmonella->id, "result" => "Positive"), array("test_id" => $tests_verified_one->id, "measure_id" => $measure_direct->id, "result" => "Negative"), array("test_id" => $tests_verified_two->id, "measure_id" => $measure_du->id, "result" => "Positive"), array("test_id" => $tests_verified_three->id, "measure_id" => $measure_sickling->id, "result" => "Positive"), array("test_id" => $tests_verified_four->id, "measure_id" => $measure_borrelia->id, "result" => "Negative"), array("test_id" => $tests_verified_five->id, "measure_id" => $measure_vdrl->id, "result" => "Negative"), array("test_id" => $tests_verified_six->id, "measure_id" => $measure_pregnancy->id, "result" => "Negative"), array("test_id" => $tests_verified_seven->id, "measure_id" => $measure_brucella->id, "result" => "Positive"), array("test_id" => $tests_verified_eight->id, "measure_id" => $measure_pylori->id, "result" => "Positive"), array("test_id" => $tests_verified_nine->id, "measure_id" => $measure_pregnancy->id, "result" => "Negative"), array("test_id" => $tests_verified_ten->id, "measure_id" => $measure_pregnancy->id, "result" => "Positive"));
     foreach ($results as $result) {
         TestResult::create($result);
     }
     $this->command->info('Test results seeded again');
     //  End prevalence rates seed
     //Seed for facilities
     $facilitiesSeed = array(array('name' => "WALTER REED"), array('name' => "AGA KHAN UNIVERSITY HOSPITAL"), array('name' => "TEL AVIV GENERAL HOSPITAL"), array('name' => "GK PRISON DISPENSARY"), array('name' => "KEMRI ALUPE"), array('name' => "AMPATH"));
     foreach ($facilitiesSeed as $facility) {
         Facility::create($facility);
     }
     $this->command->info('Facilities table seeded');
     //Seed for suppliers
     $supplier = Supplier::create(array("name" => "UNICEF", "phone_no" => "0775112233", "email" => "*****@*****.**", "physical_address" => "un-hqtr"));
     $this->command->info('Suppliers table seeded');
     //Seed for metrics
     $metric = Metric::create(array("name" => "mg", "description" => "milligram"));
     $this->command->info('Metrics table seeded');
     //Seed for commodities
     $commodity = Commodity::create(array("name" => "Ampicillin", "description" => "Capsule 250mg", "metric_id" => $metric->id, "unit_price" => "500", "item_code" => "no clue", "storage_req" => "no clue", "min_level" => "100000", "max_level" => "400000"));
     $this->command->info('Commodities table seeded');
     //Seed for receipts
     $receipt = Receipt::create(array("commodity_id" => $commodity->id, "supplier_id" => $supplier->id, "quantity" => "130000", "batch_no" => "002720", "expiry_date" => "2018-10-14", "user_id" => "1"));
     $this->command->info('Receipts table seeded');
     //Seed for Top Up Request
     $topUpRequest = TopupRequest::create(array("commodity_id" => $commodity->id, "test_category_id" => 1, "order_quantity" => "1500", "user_id" => 1, "remarks" => "-"));
     $this->command->info('Top Up Requests table seeded');
     //Seed for Issues
     Issue::create(array("receipt_id" => $receipt->id, "topup_request_id" => $topUpRequest->id, "quantity_issued" => "1700", "issued_to" => 1, "user_id" => 1, "remarks" => "-"));
     $this->command->info('Issues table seeded');
     //Seed for diseases
     $malaria = Disease::create(array('name' => "Malaria"));
     $typhoid = Disease::create(array('name' => "Typhoid"));
     $dysentry = Disease::create(array('name' => "Shigella Dysentry"));
     $this->command->info("Dieases table seeded");
     $reportDiseases = array(array("test_type_id" => $testTypeBS->id, "disease_id" => $malaria->id), array("test_type_id" => $test_types_salmonella->id, "disease_id" => $typhoid->id), array("test_type_id" => $testTypeStoolCS->id, "disease_id" => $dysentry->id));
     foreach ($reportDiseases as $reportDisease) {
         ReportDisease::create($reportDisease);
     }
     $this->command->info("Report Disease table seeded");
     //Seeding for QC
     $lots = array(array('number' => '0001', 'description' => 'First lot', 'expiry' => date('Y-m-d H:i:s', strtotime("+6 months")), 'instrument_id' => 1), array('number' => '0002', 'description' => 'Second lot', 'expiry' => date('Y-m-d H:i:s', strtotime("+7 months")), 'instrument_id' => 1));
     foreach ($lots as $lot) {
         $lot = Lot::create($lot);
     }
     $this->command->info("Lot table seeded");
     //Control seeding
     $controls = array(array('name' => 'Humatrol P', 'description' => 'HUMATROL P control serum has been designed to provide a suitable basis for the quality control (imprecision, inaccuracy) in the clinical chemical laboratory.', 'lot_id' => 1), array('name' => 'Full Blood Count', 'description' => 'Né pas touchér', 'lot_id' => 1));
     foreach ($controls as $control) {
         Control::create($control);
     }
     $this->command->info("Control table seeded");
     //Control measures
     $controlMeasures = array(array('name' => 'ca', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'pi', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'mg', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'na', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'K', 'unit' => 'mmol', 'control_id' => 1, 'control_measure_type_id' => 1), array('name' => 'WBC', 'unit' => 'x 103/uL', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'RBC', 'unit' => 'x 106/uL', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'HGB', 'unit' => 'g/dl', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'HCT', 'unit' => '%', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'MCV', 'unit' => 'fl', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'MCH', 'unit' => 'pg', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'MCHC', 'unit' => 'g/dl', 'control_id' => 2, 'control_measure_type_id' => 1), array('name' => 'PLT', 'unit' => 'x 103/uL', 'control_id' => 2, 'control_measure_type_id' => 1));
     foreach ($controlMeasures as $controlMeasure) {
         ControlMeasure::create($controlMeasure);
     }
     $this->command->info("Control Measure table seeded");
     //Control measure ranges
     $controlMeasureRanges = array(array('upper_range' => '2.63', 'lower_range' => '7.19', 'control_measure_id' => 1), array('upper_range' => '11.65', 'lower_range' => '15.43', 'control_measure_id' => 2), array('upper_range' => '12.13', 'lower_range' => '19.11', 'control_measure_id' => 3), array('upper_range' => '15.73', 'lower_range' => '25.01', 'control_measure_id' => 4), array('upper_range' => '17.63', 'lower_range' => '20.12', 'control_measure_id' => 5), array('upper_range' => '6.5', 'lower_range' => '7.5', 'control_measure_id' => 6), array('upper_range' => '4.36', 'lower_range' => '5.78', 'control_measure_id' => 7), array('upper_range' => '13.8', 'lower_range' => '17.3', 'control_measure_id' => 8), array('upper_range' => '81.0', 'lower_range' => '95.0', 'control_measure_id' => 9), array('upper_range' => '1.99', 'lower_range' => '2.63', 'control_measure_id' => 10), array('upper_range' => '27.6', 'lower_range' => '33.0', 'control_measure_id' => 11), array('upper_range' => '32.8', 'lower_range' => '36.4', 'control_measure_id' => 12), array('upper_range' => '141', 'lower_range' => ' 320.0', 'control_measure_id' => 13));
     foreach ($controlMeasureRanges as $controlMeasureRange) {
         ControlMeasureRange::create($controlMeasureRange);
     }
     $this->command->info("Control Measure ranges table seeded");
     //Control Tests
     $controlTests = array(array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('entered_by' => 3, 'control_id' => 1, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('entered_by' => 1, 'control_id' => 2, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('entered_by' => 1, 'control_id' => 2, 'created_at' => date('Y-m-d', strtotime('-2 days'))));
     foreach ($controlTests as $controltest) {
         ControlTest::create($controltest);
     }
     $this->command->info("Control test table seeded");
     //Control results
     $controlResults = array(array('results' => '2.78', 'control_measure_id' => 1, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '13.56', 'control_measure_id' => 2, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '14.77', 'control_measure_id' => 3, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '25.92', 'control_measure_id' => 4, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '18.87', 'control_measure_id' => 5, 'control_test_id' => 1, 'created_at' => date('Y-m-d', strtotime('-10 days'))), array('results' => '6.78', 'control_measure_id' => 1, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '15.56', 'control_measure_id' => 2, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '18.77', 'control_measure_id' => 3, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '30.92', 'control_measure_id' => 4, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '17.87', 'control_measure_id' => 5, 'control_test_id' => 2, 'created_at' => date('Y-m-d', strtotime('-9 days'))), array('results' => '8.78', 'control_measure_id' => 1, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '17.56', 'control_measure_id' => 2, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '21.77', 'control_measure_id' => 3, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '27.92', 'control_measure_id' => 4, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '22.87', 'control_measure_id' => 5, 'control_test_id' => 3, 'created_at' => date('Y-m-d', strtotime('-8 days'))), array('results' => '6.78', 'control_measure_id' => 1, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '18.56', 'control_measure_id' => 2, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '19.77', 'control_measure_id' => 3, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '12.92', 'control_measure_id' => 4, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '22.87', 'control_measure_id' => 5, 'control_test_id' => 4, 'created_at' => date('Y-m-d', strtotime('-7 days'))), array('results' => '3.78', 'control_measure_id' => 1, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '16.56', 'control_measure_id' => 2, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '17.77', 'control_measure_id' => 3, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '28.92', 'control_measure_id' => 4, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '19.87', 'control_measure_id' => 5, 'control_test_id' => 5, 'created_at' => date('Y-m-d', strtotime('-6 days'))), array('results' => '5.78', 'control_measure_id' => 1, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '15.56', 'control_measure_id' => 2, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '11.77', 'control_measure_id' => 3, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '29.92', 'control_measure_id' => 4, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '14.87', 'control_measure_id' => 5, 'control_test_id' => 6, 'created_at' => date('Y-m-d', strtotime('-5 days'))), array('results' => '9.78', 'control_measure_id' => 1, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '11.56', 'control_measure_id' => 2, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '19.77', 'control_measure_id' => 3, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '32.92', 'control_measure_id' => 4, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '29.87', 'control_measure_id' => 5, 'control_test_id' => 7, 'created_at' => date('Y-m-d', strtotime('-4 days'))), array('results' => '5.45', 'control_measure_id' => 6, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '5.01', 'control_measure_id' => 7, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '12.3', 'control_measure_id' => 8, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '89.7', 'control_measure_id' => 9, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '2.15', 'control_measure_id' => 10, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '34.0', 'control_measure_id' => 11, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '37.2', 'control_measure_id' => 12, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '141.5', 'control_measure_id' => 13, 'control_test_id' => 8, 'created_at' => date('Y-m-d', strtotime('-3 days'))), array('results' => '7.45', 'control_measure_id' => 6, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '9.01', 'control_measure_id' => 7, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '9.3', 'control_measure_id' => 8, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '94.7', 'control_measure_id' => 9, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '12.15', 'control_measure_id' => 10, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '37.0', 'control_measure_id' => 11, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '30.2', 'control_measure_id' => 12, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))), array('results' => '121.5', 'control_measure_id' => 13, 'control_test_id' => 9, 'created_at' => date('Y-m-d', strtotime('-2 days'))));
     foreach ($controlResults as $controlResult) {
         ControlMeasureResult::create($controlResult);
     }
     $this->command->info("Control results table seeded");
 }
Ejemplo n.º 20
0
 public function loadVisitModel($bid)
 {
     $uid = Yii::app()->user->getId();
     $model = Visit::model()->findByAttributes(array('user_id' => $uid, 'product_id' => $bid));
     if ($model === null) {
         $model = new Visit();
     }
     return $model;
 }
 public function _setActivePatient($personId, $visitId)
 {
     if (!$personId > 0) {
         return;
     }
     $memcache = Zend_Registry::get('memcache');
     $patient = new Patient();
     $patient->personId = (int) $personId;
     $patient->populate();
     $patient->person->populate();
     $this->_patient = $patient;
     $this->view->patient = $this->_patient;
     $mostRecentRaw = $memcache->get('mostRecent');
     $currentUserId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
     $personId = $patient->personId;
     $teamId = $patient->teamId;
     if ($mostRecentRaw === false) {
         $mostRecent = array();
     } else {
         $mostRecent = unserialize($mostRecentRaw);
     }
     if (!array_key_exists($currentUserId, $mostRecent)) {
         $mostRecent[$currentUserId] = array();
     }
     if (array_key_exists($personId, $mostRecent[$currentUserId])) {
         unset($mostRecent[$currentUserId][$personId]);
     }
     $name = $patient->person->last_name . ', ' . $patient->person->first_name . ' ' . substr($patient->person->middle_name, 0, 1) . ' #' . $patient->record_number;
     $mostRecent[$currentUserId][$patient->personId] = array('name' => $name, 'teamId' => $teamId);
     $memcache->set('mostRecent', serialize($mostRecent));
     if (strlen($patient->teamId) > 0) {
         $name = TeamMember::ENUM_PARENT_NAME;
         $enumeration = new Enumeration();
         $enumeration->populateByEnumerationName($name);
         $enumerationsClosure = new EnumerationsClosure();
         $rowset = $enumerationsClosure->getAllDescendants($enumeration->enumerationId, 1);
         $patientEnumerationId = 0;
         foreach ($rowset as $row) {
             if ($patient->teamId == $row->key) {
                 $patientEnumerationId = $row->enumerationId;
                 break;
             }
         }
         if ($patientEnumerationId !== 0) {
             $this->view->team = TeamMember::generateTeamTree($patientEnumerationId);
         }
     }
     // POSTINGS
     $allergies = array();
     $patientAllergy = new PatientAllergy();
     $patientAllergyIterator = $patientAllergy->getIteratorByPatient($personId);
     foreach ($patientAllergyIterator as $allergy) {
         if ($allergy->noKnownAllergies) {
             continue;
         }
         $allergies[] = $allergy->toArray();
     }
     $this->view->allergies = $allergies;
     $notes = array();
     $patientNote = new PatientNote();
     $patientNoteIterator = $patientNote->getIterator();
     $filters = array();
     $filters['patient_id'] = $personId;
     $filters['active'] = 1;
     $filters['posting'] = 1;
     $patientNoteIterator->setFilters($filters);
     foreach ($patientNoteIterator as $note) {
         $notes[] = $note->toArray();
     }
     $this->view->notes = $notes;
     //REMINDERS
     $ctr = 0;
     $hsa = new HealthStatusAlert();
     $hsaIterator = $hsa->getIteratorByStatusWithPatientId('active', $personId);
     foreach ($hsaIterator as $row) {
         $ctr++;
     }
     if ($ctr > 0) {
         $this->view->reminders = $ctr;
     }
     // VISITS
     //$this->_visit = null;
     if (!$visitId > 0) {
         return;
     }
     $visit = new Visit();
     $visit->encounter_id = (int) $visitId;
     $visit->populate();
     $this->_visit = $visit;
     $this->view->visit = $this->_visit;
 }
Ejemplo n.º 22
0
 public function visitFromUser($user)
 {
     if (!$user) {
         return null;
     }
     return Visit::whereUserId($user->id)->whereSpotId($this->id)->first();
 }
Ejemplo n.º 23
0
 protected function _populateAppointmentRow(Appointment $app, array &$columnData, $colIndex, $index, $rowsLen)
 {
     $startToTime = strtotime($app->start);
     $endToTime = strtotime($app->end);
     $tmpStart = date('H:i', $startToTime);
     $tmpEnd = date('H:i', $endToTime);
     $timeLen = ceil(($endToTime - $startToTime) / 60 / self::FILTER_MINUTES_INTERVAL);
     $appointmentId = (int) $app->appointmentId;
     $patientId = (int) $app->patientId;
     $providerId = (int) $app->providerId;
     $roomId = (int) $app->roomId;
     $patient = new Patient();
     $patient->personId = $patientId;
     $patient->populate();
     $id = isset($columnData[$colIndex]['id']) ? $columnData[$colIndex]['id'] : '';
     $columnData[$colIndex]['id'] = $appointmentId;
     if (strlen($id) > 0) {
         $columnData[$colIndex]['id'] .= 'i' . $id;
     }
     $visit = new Visit();
     $visit->appointmentId = $appointmentId;
     $visit->populateByAppointmentId();
     $visitIcon = $visit->visitId > 0 ? '<img src="' . $this->view->baseUrl . '/img/appointment_visit.png" alt="' . __('Visit') . '" title="' . __('Visit') . '" style="border:0px;height:18px;width:18px;margin-left:5px;" />' : '';
     $routingStatuses = array();
     if (strlen($app->appointmentCode) > 0) {
         $routingStatuses[] = __('Mark') . ': ' . $app->appointmentCode;
     }
     $routing = new Routing();
     $routing->personId = $patientId;
     $routing->appointmentId = $appointmentId;
     $routing->providerId = $providerId;
     $routing->roomId = $roomId;
     $routing->populateByAppointments();
     if (strlen($routing->stationId) > 0) {
         $routingStatuses[] = __('Station') . ': ' . $routing->stationId;
     }
     $routingStatus = implode(' ', $routingStatuses);
     $nameLink = $patientId > 0 ? "<a href=\"javascript:showPatientDetails({$patientId});\">{$patient->person->displayName} (#{$patient->recordNumber})</a>" : '';
     $cellRow = 20;
     $height = $cellRow * $timeLen * 1.1;
     $marginTop = 2;
     // compute and adjust margin top and height
     $heightPerMinute = $cellRow / self::FILTER_MINUTES_INTERVAL;
     $map = $columnData[$colIndex]['map'];
     $diff = ($startToTime - $map['start']) / 60;
     if ($diff > 0) {
         $marginTop += $diff * $heightPerMinute;
         $height -= $marginTop;
     }
     $marginLeft = $rowsLen > 1 && $index > 0 ? $index * 250 : 8;
     $zIndex = $colIndex . $index;
     $columnData[$colIndex]['data'][0] .= "<div onmousedown=\"calendarSetAppointmentId('{$appointmentId}')\" ondblclick=\"timeSearchDoubleClicked(this,event)\" appointmentId=\"{$appointmentId}\" visitId=\"{$visit->visitId}\" style=\"float:left;position:absolute;margin-top:{$marginTop}px;height:{$height}px;width:230px;overflow:hidden;border:thin solid black;margin-left:{$marginLeft}px;padding-left:2px;background-color:lightgrey;z-index:{$zIndex};\" class=\"dataForeground\" id=\"event{$appointmentId}\" onmouseover=\"calendarExpandAppointment({$appointmentId},this,{$height});\" onmouseout=\"calendarShrinkAppointment({$appointmentId},this,{$height},{$zIndex});\">{$tmpStart}-{$tmpEnd} {$nameLink} {$visitIcon} <br />{$routingStatus}<div class=\"bottomInner\" id=\"bottomInnerId{$appointmentId}\" style=\"white-space:normal;\">{$app->title}</div></div>";
     $columnData[$colIndex]['userdata']['visitId'] = $visit->visitId;
     $columnData[$colIndex]['userdata']['appointmentId'] = $appointmentId;
     $columnData[$colIndex]['userdata']['length'] = $timeLen;
 }
Ejemplo n.º 24
0
 public function getVisitCheck($VisitId)
 {
     $visit = Visit::find($VisitId);
     $visit->check = '1';
     $visit->save();
     return Redirect::to('branch/visit-all')->with('success', '回访审核成功!');
 }
Ejemplo n.º 25
0
 /**
  * View user profile
  *
  * @param Request $request
  * @param $matches
  * @return mixed|string
  */
 public function profile(Request $request, $matches)
 {
     try {
         /** @var \User $user */
         $user = \User::find($matches['id']);
     } catch (\Exception $e) {
         return $this->error404($request);
     }
     // User access log filter
     $access_filter = ['conditions' => ['user_id = ?', $user->id]];
     // Paginator access log
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \Visit::count($access_filter)]);
     $access_filter['order'] = 'id DESC';
     $access_filter = array_merge($access_filter, $paginator->limit());
     // Unban user
     if ($request->get('unban')) {
         $user->ban_time = null;
         $user->ban_user_id = null;
         $user->ban_reason = null;
         $user->save();
         static::redirect_response($this->map->reverse('users.profile', ['id' => $user->id]));
     }
     if ($request->isMethod('post')) {
         $changed = false;
         // Edit rating
         $rating = intval($request->get('rating', 0));
         if ($user->rating != $rating) {
             $user->rating = $rating;
             $changed = true;
         }
         // Change ban user
         $ban_time = $request->get('ban_time', false);
         $ban_reason = $request->get('ban_reason', false);
         if ($ban_time) {
             if ($ban_time == '-1' || strtolower(trim($ban_time)) == 'forever') {
                 $ban_time = -1;
             } else {
                 $ban_time = strtotime($ban_time, time());
             }
             $user->ban($this->user, $ban_time, $ban_reason);
             $changed = true;
         }
         // Edit username
         $new_login = $request->get('username');
         if ($new_login && $new_login != $user->username) {
             $exists = \User::find_by_username($new_login);
             if ($exists && $exists->id) {
                 return static::json_response(['status' => $this->lang->translate('user.edit.exists', $new_login), 'class' => 'error']);
             } else {
                 $changed = true;
                 $user->username = $new_login;
             }
         }
         // Edit email
         $new_email = $request->get('email');
         if ($new_email && $new_email != $user->email) {
             $exists = \User::find_by_email($new_email);
             if ($exists && $exists->id) {
                 return static::json_response(['status' => $this->lang->translate('user.edit.exists_email', $new_email), 'class' => 'error']);
             } else {
                 $changed = true;
                 $user->email = $new_email;
             }
         }
         // Edit group
         $new_group = intval($request->get('group', $user->group_id));
         if (!\Group::find($new_group)) {
             return static::json_response(['status' => $this->lang->translate('user.edit.wrong_group'), 'class' => 'error']);
         } else {
             $changed = true;
             $user->group_id = $new_group;
         }
         // Change password
         $new_password = $request->get('new_password');
         if ($new_password) {
             $user->password = $new_password;
             if (strlen($new_password) > 5 && $user->save()) {
                 return static::json_response(['status' => $this->lang->translate('form.saved'), 'class' => 'success']);
             } else {
                 return static::json_response(['status' => $this->lang->translate('form.failed'), 'class' => 'error']);
             }
         }
         if ($changed && $user->save()) {
             return static::json_response(['status' => $this->lang->translate('form.saved'), 'class' => 'success']);
         } else {
             return static::json_response(['status' => $this->lang->translate('form.failed'), 'class' => 'error']);
         }
     }
     return $this->view->render('users/profile.twig', ['title' => $this->lang->translate('user.profile.name', $user->username), 'profile' => $user->to_array(), 'groups' => array_map(function ($i) {
         return $i->to_array();
     }, \Group::all()), 'visits_list' => \Visit::as_array(\Visit::find('all', $access_filter)), 'user_ips' => array_map(function ($ip) {
         $data = ['addr' => long2ip($ip->ip)];
         $data['banned'] = !Env::$kernel->ipwall->allowed(long2ip($ip->ip));
         return $data;
     }, \Visit::ips_by_user($user)), 'listing' => $paginator->pages(), 'page' => $paginator->cur_page]);
 }
Ejemplo n.º 26
0
 /**
  * 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);
 }
Ejemplo n.º 27
0
            writeImage("stats8.gif", $stier);
        } elseif ($ind['billed'] == "trans") {
            writeImage("stats_trans.gif", $stier);
        } elseif ($ind['billed'] == "taelsh") {
            zipcount(0, $stier, $ind, $datafil);
        } elseif ($ind['billed'] == "taelhs") {
            zipcount(1, $stier, $ind, $datafil);
        } else {
            writeImage("stats1.gif", $stier);
        }
    }
}
//Register visits collectively?
if ($stier->getOption('collective') === 1) {
    require_once "lib/ZipStatEngine.php";
    $visit = new Visit();
    $visit->setUnique($lib->isVisitUnique(getenv('REMOTE_ADDR')) ? 1 : 0);
    $visit->setTime($lib->getTimeAdjusted());
    $visit->setBrowser(ZipStatEngine::short_browser(getenv('HTTP_USER_AGENT')));
    $visit->setOs(ZipStatEngine::platform(getenv('HTTP_USER_AGENT')));
    $visit->setResolution(isset($ind['ssto']) ? $ind['ssto'] : '');
    //Todo: Test for correct syntax
    $visit->setColorDepth(isset($ind['colors']) ? $ind['colors'] : '');
    if (isset($ind['java']) and strlen($ind['java']) > 0) {
        $visit->setJavaEnabled($ind['java'] === "true" ? 1 : 0);
    } else {
        $visit->setJavaEnabled(2);
    }
    if (isset($ind['js']) and strlen($ind['js']) > 0) {
        $visit->setJavaScriptEnabled($ind['js'] === "true" ? 1 : 0);
    } else {
Ejemplo n.º 28
0
 public function store_followup($id)
 {
     $patient = Patient::find($id);
     $patient->first_name = Input::get("firstname");
     $patient->middle_name = Input::get("middlename");
     $patient->last_name = Input::get("lastname");
     $patient->birth_date = Input::get("dob");
     $patient->hospital_id = Input::get("hosp_no");
     $patient->phone = Input::get("phone");
     $patient->facility_id = Input::get("facility");
     $patient->save();
     //adding patient visit info
     $visit = Visit::create(array("patient_id" => $patient->id, "visit_date" => date('Y-m-d'), "server_status" => 'not', "user" => Auth::user()->firstname . " " . Auth::user()->middlename . " " . Auth::user()->lastname));
     //adding address information
     PatientInfo::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "hospital_id" => "somenumber", "region" => Input::get("region"), "district" => Input::get("district"), "ward" => Input::get("ward"), "ten_cell_leader" => Input::get("t_cell_leadr")));
     //adding gynecological history inforamtion for a visit
     GynecologicalHistory::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "parity" => Input::get("parity"), "number_of_pregnancy" => Input::get("number_of_preg"), "menarche" => Input::get("menarche"), "age_at_sexual_debut" => Input::get("start_sex_age"), "marital_status" => Input::get("marital"), "age_at_first_marriage" => Input::get("first_marriage"), "sexual_partner" => Input::get("sexual_partner"), "partner_sexual_partner" => Input::get("partner_sexual_partner")));
     //adding contraceptive history
     ContraceptiveHistory::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "current_status" => Input::get("current_on_contra"), "current_contraceptive_id" => Input::has("current_contra") ? Input::get("current_contra") : ""));
     //adding HIV status
     HivStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "status" => Input::has("hiv_status") ? Input::get("hiv_status") : "", "test_status" => Input::has("hiv_test_status") ? Input::get("hiv_test_status") : "", "unknown_reason" => Input::has("unknown_reason") ? Input::get("unknown_reason") : "", "years_since_first_diagnosis" => Input::has("year_since_diagnosis") ? Input::get("year_since_diagnosis") : "", "year_of_last_test" => Input::has("last_test") ? Input::get("last_test") : "", "art_status" => Input::has("art_status") ? Input::get("art_status") : "", "current_art_status" => Input::has("current_art_status") ? Input::get("current_art_status") : "", "pitc_offered" => Input::get("test_again") == "yes" ? "yes" : "no", "pitc_agreed" => Input::has("test_again") ? Input::get("test_again") : "", "pitc_result" => Input::has("current_test_result") ? Input::get("current_test_result") : "", "pitc_cd4_count" => Input::has("current_cd4") ? Input::get("current_cd4") : "", "prev_cd4_count" => Input::has("prev_cd4") ? Input::get("prev_cd4") : ""));
     //adding VIA Status
     ViaStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "via_counselling_status" => Input::get("via_counceling"), "via_test_status" => Input::get("via_test"), "reject_reason" => Input::has("via_reason") ? Input::get("via_reason") : "", "via_result" => Input::has("via_results") ? Input::get("via_results") : ""));
     //adding colposcopy
     ColposcopyStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "status" => Input::get("colposcopy_status"), "result_id" => Input::has("colpo_result") ? Input::get("colpo_result") : ""));
     //adding Pap smear result
     PapsmearStatus::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "status" => Input::get("pap_status"), "result_id" => Input::has("pap_result") ? Input::get("pap_result") : ""));
     //adding intervetion status
     Intervention::create(array("patient_id" => $patient->id, "visit_id" => $visit->id, "type_id" => Input::has("intervention") ? Input::get("intervention") : "", "indicator_id" => Input::has("indicator") ? Input::get("indicator") : "", "histology_id" => Input::has("histology") ? Input::get("histology") : "", "cancer_id" => Input::has("cancer") ? Input::get("cancer") : "", "grade" => Input::has("hist_grade") ? Input::get("hist_grade") : "", "stages" => Input::has("stages") ? Input::get("stages") : "", "differentiation" => Input::has("differentiation") ? Input::get("differentiation") : ""));
     $report = PatientReport::where('patient_id', $patient->id)->first();
     $report->region = Input::get("region");
     $report->district = Input::get("district");
     $report->number_of_pregnancy = Input::get("number_of_preg");
     $report->marital_status = Input::get("marital");
     $report->first_marriage = Input::get("first_marriage");
     $report->partners = Input::get("sexual_partner");
     $report->partners_partner = Input::get("partner_sexual_partner");
     $report->contraceptive_status = Input::get("current_on_contra");
     $report->facility_id = Input::get("facility");
     if (Input::has("current_contra")) {
         $report->contraceptive_type = Input::get("current_contra");
     }
     if (Input::has("hiv_status")) {
         $report->HIV_status = Input::get("hiv_status");
     }
     if (Input::has("current_cd4")) {
         $report->cd4_count = Input::get("current_cd4");
     } elseif (Input::has("prev_cd4")) {
         $report->cd4_count = Input::has("prev_cd4");
     }
     $report->save();
     if (Input::get("next_visit") != "") {
         Notification::create(array("patient_id" => $patient->id, "message" => "Kumbuka Kwenda katika kituo ulichopimwa mara ya mwisho saratani ya shingo ya kizazi. Tafadhali fika bila kukosa tarehe  " . Input::get('next_visit'), "status" => "pending", "phone_number" => $patient->phone, "next_visit" => Input::get('next_visit')));
     }
     Logs::create(array("user_id" => Auth::user()->id, "action" => "Patient followup for " . $patient->first_name . " " . $patient->last_name));
     $msg = "Patient followup stored successfull";
     return View::make('visit.index', compact('patient', "msg"));
 }
Ejemplo n.º 29
0
 /**
  *	@fn attribute_visits
  *	@short Action method to attribute a visit to a person.
  *	@details This method is designed to be called with AJAX, and does not render anything.
  *	It assigns a visit object to a person object.
  */
 public function attribute_visits()
 {
     $conn = Db::get_connection();
     $visit_factory = new Visit();
     $visits = $visit_factory->find_all(array('where_clause' => "`date` >= '{$conn->escape(date("Y-m-d H:i:s", Time::ago(@$_REQUEST['t'])))}' " . "AND (`ip_addr` = '{$conn->escape(@$_REQUEST['ip'])}' " . "OR `params` LIKE '%Apache'' => ''{$conn->escape(@$_REQUEST['ip'])}%')"));
     if (count($visits) > 0) {
         foreach ($visits as $visit) {
             $visit->person_id = @$_REQUEST['person_id'];
             $visit->save();
         }
     }
     Db::close_connection($conn);
     $this->render(NULL);
 }
Ejemplo n.º 30
0
 public static function advise($uid, $foid, $adviseType, $reason, $loan = false)
 {
     $isLoanSketch = false;
     switch ($adviseType) {
         case 'loansketch':
             $status = \App\LoanStatus::getStatusSketch();
             $oid = User::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
         case 'visit':
             $status = \App\LoanStatus::getStatusCarAssess();
             $oid = Visit::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
         case 'car':
             $status = \App\LoanStatus::getStatusVisit();
             $oid = Car::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
         case 'face':
             $status = \App\LoanStatus::getStatusChecked();
             $oid = Face::findFirst("uid={$uid}")->oid;
             $isLoanSketch = true;
             break;
     }
     if (empty($oid)) {
         return false;
     }
     if ($isLoanSketch) {
         $model = LoanSketch::findFirst("uid={$uid}");
         $model->status = $status;
         $model->update();
     }
     Advise::add($uid, $oid, $foid, $adviseType, $reason);
     return true;
 }