/** * Returns false if the name already exists */ public static function isUnique($facilityName, $id = false) { $fac = new Facility(); $select = $fac->select(); $select->where("facility_name = ?", $facilityName); if ($id) { $select->where("id != ?", $id); } if ($fac->fetchRow($select)) { return false; } return true; }
/** * a function to export data to excel */ public function excelDownload() { if (isset($_POST['records'])) { /** Include PHPExcel */ require_once dirname(__FILE__) . '/Classes/PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); $title = Input::get("vertical"); $pat = false; $usequery = ""; if (Input::get("horizontal") == "Year") { $from = Input::get('year') . "-01-01"; $to = Input::get('year') . "-12-31"; $patientquery = DB::table('patient'); $visitquery = DB::table('visit'); $query = $this->processQuery($patientquery, $visitquery); $title .= " " . $query[2] . " " . Input::get('Year'); $usequery = $query[0]->whereBetween('created_at', array($from, $to))->get(); } elseif (Input::get("horizontal") == "Years") { $from = Input::get('start') . "-01-01"; $to = Input::get('end') . "-12-31"; $patientquery = DB::table('patient'); $visitquery = DB::table('visit'); $query = $this->processQuery($patientquery, $visitquery); $title .= " " . $query[2] . " " . Input::get('Year'); $usequery = $query[0]->whereBetween('created_at', array($from, $to))->get(); } elseif (Input::get("horizontal") == "Age Range") { $patientquery = DB::table('patient'); $visitquery = DB::table('visit'); $query = $this->processQuery($patientquery, $visitquery); $usequery = $query[0]->get(); $title .= " Age Range " . $query[2] . " "; } // Set document properties $objPHPExcel->getProperties()->setCreator("Cervical Cancer Prevention Program")->setLastModifiedBy(Auth::user()->first_name)->setTitle($title)->setSubject($title)->setDescription("Cervical Cancer Prevention Program Reports")->setKeywords("cancer cecap openxml php")->setCategory("Result file"); // Tittle $objPHPExcel->setActiveSheetIndex(0)->mergeCells('A1:I1'); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $title); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A2', 'Name')->setCellValue('B2', 'Age')->setCellValue('C2', 'Region')->setCellValue('D2', 'District')->setCellValue('E2', 'Facility')->setCellValue('F2', 'Marital Status')->setCellValue('G2', 'HIV Status')->setCellValue('H2', 'Contraceptive Status')->setCellValue('I2', 'Last Visit'); $k = 3; foreach ($usequery as $us) { $patient = Patient::find($us->id); $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$k}", $us->first_name . " " . $us->middle_name . " " . $us->last_name)->setCellValue("B{$k}", date('Y') - date('Y', strtotime($us->birth_date)))->setCellValue("C{$k}", $patient->report->regions->region)->setCellValue("D{$k}", $patient->report->districts->district)->setCellValue("E{$k}", Facility::find($us->facility_id)->facility_name)->setCellValue("F{$k}", $patient->report->marital_status)->setCellValue("G{$k}", $patient->report->HIV_status)->setCellValue("H{$k}", $patient->report->contraceptive_status)->setCellValue("I{$k}", date('j M Y', strtotime($patient->visit()->orderBy('created_at', 'DESC')->first()->visit_date))); $k++; } // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle("Cervical Cancer Patient Report"); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="records.xlsx"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; } elseif (isset($_POST['reports'])) { /** Include PHPExcel */ require_once dirname(__FILE__) . '/Classes/PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); $title = Input::get("vertical"); $pat = false; $row = array(); $column = array(); $columntype = $this->generateArray(Input::get("show")); if (Input::get("vertical") == "Patients") { $pat = true; } if (Input::get("horizontal") == "Year") { $row = array("01" => "jan", "02" => "feb", "03" => "mar", "04" => "apr", "05" => "may", "06" => "jun", "07" => "jul", "08" => "aug", "09" => "sep", "10" => "oct", "11" => "nov", "12" => "dec"); foreach ($row as $key => $value) { $from = Input::get('year') . "-" . $key . "-01"; $to = Input::get('year') . "-" . $key . "-31"; if (isset($columntype)) { foreach ($columntype as $key1 => $value1) { $patientquery = DB::table('patient'); $visitquery = DB::table('visit'); $query = $this->processQuery($patientquery, $visitquery); $que = $this->checkCondition($query, $pat, $key1)->whereBetween('created_at', array($from, $to)); $column[$value1][] = $que->count(); } } } $title .= " " . $query[2] . " " . Input::get('year'); } elseif (Input::get("horizontal") == "Years") { $row = range(Input::get('start'), Input::get('end')); foreach ($row as $value) { $from = $value . "-01-01"; $to = $value . "-12-31"; if (isset($columntype)) { foreach ($columntype as $key1 => $value1) { $patientquery = DB::table('patient'); $visitquery = DB::table('visit'); $query = $this->processQuery($patientquery, $visitquery); $que = $this->checkCondition($query, $pat, $key1)->whereBetween('created_at', array($from, $to)); $column[$value1][] = $que->count(); } } } $title .= " " . $query[2] . " " . Input::get('start') . " - " . Input::get('end'); } elseif (Input::get("horizontal") == "Age Range") { //setting the limits $agetouse = Input::get('age') == 0 ? 3 : Input::get('age'); if (parent::maxAge() % $agetouse == 0) { $limit = parent::maxAge(); } else { $limit = parent::maxAge() - parent::maxAge() % $agetouse + $agetouse; } //making a loop for values //year iterator $k = 0; //getting age $range = Input::get('age'); $yeardate = date("Y") + 1; $yaerdate1 = $yeardate . "-01-01"; //creating title $data = array(); for ($i = $range; $i <= $limit; $i += $range) { $row[] = $k . " - " . $i; //start year $time = $k * 365 * 24 * 3600; $today = date("Y-m-d"); $timerange = strtotime($today) - $time; $start = date("Y", $timerange) + 1 . "-01-01"; //end year $time1 = $i * 365 * 24 * 3600; $timerange1 = strtotime($today) - $time1; $end = date("Y", $timerange1) . "-01-01"; if (isset($columntype)) { foreach ($columntype as $key1 => $value1) { $patientquery = DB::table('patient'); $visitquery = DB::table('visit'); $query = $this->processQuery($patientquery, $visitquery); $que = $this->checkCondition($query, true, $key1)->whereBetween('birth_date', array($end, $start)); $column[$value1][] = $que->count(); } } $k = $i; } $title .= " Age Range " . $query[2]; } // Set document properties $objPHPExcel->getProperties()->setCreator("Cervical Cancer Prevention Program")->setLastModifiedBy(Auth::user()->first_name)->setTitle($title)->setSubject($title)->setDescription("Cervical Cancer Prevention Program Reports")->setKeywords("cancer cecap openxml php")->setCategory("Result file"); $latterArr = array("A", "B", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BM", "BL", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "BZ"); $ttlecont = 1; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A2', Input::get("show")); foreach ($row as $header) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue("{$latterArr[$ttlecont]}2", $header); $ttlecont++; } $objPHPExcel->setActiveSheetIndex(0)->mergeCells("A1:{$latterArr[$ttlecont - 1]}1"); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $title); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $k = 3; $colcount = 1; foreach ($column as $keys => $cols) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$k}", $keys); foreach ($cols as $colsval) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue("{$latterArr[$colcount]}{$k}", $colsval); $colcount++; } $colcount = 1; $k++; } // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle("Cervical Cancer Patient Report"); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $title . '.xlsx"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; } }
foreach ($facs as $fac) { $alogs[$fac->name] = intval($fac->val); } $facs = $syslog_daily->todays_facilities()->findAll(); foreach ($facs as $fac) { $slogs[$fac->name] = intval($fac->val); } foreach ($alogs as $key => $val) { if (!isset($slogs[$key])) { $slogs[$key] = 0; } } $archive_logs = ksort($alogs); $system_logs = ksort($slogs); foreach ($alogs as $key => $val) { $labels[] = Facility::model()->findByPk($key)->name; } $this->Widget('ext.highcharts.HighchartsWidget', array('options' => array('chart' => array('type' => 'bar'), 'credits' => array('enabled' => false), 'title' => array('text' => 'Messages per Facility Today'), 'xAxis' => array('categories' => $labels), 'yAxis' => array('title' => array('text' => 'Messages Today')), 'series' => array(array('name' => 'Archive', 'data' => array_values($alogs)), array('name' => 'Syslog', 'data' => array_values($slogs)))))); $alogs = $slogs = $labels = array(); $facs = $archive_daily->todays_severities()->findAll(); foreach ($facs as $fac) { $alogs[$fac->name] = intval($fac->val); } $facs = $syslog_daily->todays_severities()->findAll(); foreach ($facs as $fac) { $slogs[$fac->name] = intval($fac->val); } foreach ($alogs as $key => $val) { if (!isset($slogs[$key])) { $slogs[$key] = 0; }
} catch (Exception $e) { redirect_to(array('location' => 'facility.php' . (isset($_REQUEST['id']) ? "?action=show&id=" . intval($_REQUEST['id']) : ""), 'status' => 'This facility does not exist.', 'class' => 'error')); } $updateFacility = $facility->create_or_update($_POST['facility']); if ($updateFacility) { redirect_to(array('location' => 'facility.php?action=show&id=' . intval($updateFacility), 'status' => "Successfully " . (isset($_REQUEST['id']) ? "updated" : "created") . " this facility.", 'class' => 'success')); } else { redirect_to(array('location' => 'facility.php' . (isset($_REQUEST['id']) ? "?action=edit&id=" . intval($_REQUEST['id']) : "?action=new"), 'status' => "An error occurred while " . (isset($_REQUEST['id']) ? "updating" : "creating") . " this facility.", 'class' => 'error')); } } if (!isset($_REQUEST['id'])) { $_REQUEST['id'] = 0; } start_html($user, "UC Medicine QA", "Manage Facilities", $_REQUEST['status'], $_REQUEST['class']); try { $facility = new Facility($database, intval($_REQUEST['id'])); } catch (Exception $e) { display_error("Error: Invalid facility ID", "Please check the facility ID and try again."); display_footer(); exit; } switch ($_REQUEST['action']) { case 'new': //ensure that user has sufficient privileges to add a facility. if (!$user->isAdmin()) { display_error("Error: Insufficient privileges", "You must be an administrator to add facilities."); break; } $facility->displayEditForm("Add a facility"); break; case 'edit':
public function getFacilities($continent) { $output = []; // Iterate through the Facility types foreach (FacilityType::orderBy('name')->get() as $type) { // Get the markers for the facilities nnnnnnnnnnnnnn $facilities = Facility::with('FacilityType')->with('linkedFacilities')->where('continent_id', '=', $continent->id)->where('facility_type_id', '=', $type->id)->orderBy('name')->get(); // Skip if no markers exist for that type if (count($facilities) == 0) { $this->log("No " . $type->name . " facilities found."); continue; } $output[$type->slug] = []; // Add the facilities to the output foreach ($facilities as $facility) { // Ignore if Warpgate facility has no position // if ( strpos($facility->name, 'Warpgate') !== false and (is_null($facility->lat) or is_null($facility->lng) or $facility->lat == 0 or $facility->lng == 0 )) { // $this->log($facility->name." has no position"); // continue; // } // Facility Name $output[$type->slug][$facility->id] = ['name' => $facility->name]; // Facility Position if (!is_null($facility->lat) or !is_null($facility->lng)) { $x = (double) $facility->lat; $y = (double) $facility->lng; // $output[$type->slug][$facility->id]['xy'] = [(float)$facility->lat, (float)$facility->lng ]; } else { $x = (double) $facility->lat_override; $y = (double) $facility->lng_override; // $output[$type->slug][$facility->id]['xy'] = [(float)$facility->lat_override, (float)$facility->lng_override ]; } if (!is_null($x) and !is_null($y) and $x != 0 and $y != 0) { $output[$type->slug][$facility->id]['xy'] = [$x, $y]; } // Lattice Links if (count($facility->linkedFacilities) > 0) { $output[$type->slug][$facility->id]['links'] = []; foreach ($facility->linkedFacilities as $linkedFacility) { $output[$type->slug][$facility->id]['links'][] = (int) $linkedFacility->id; } } } } return $output; }
/** * Refer the test * * @param specimenId * @return View */ public function showRefer($specimenId) { $specimen = Specimen::find($specimenId); $facilities = Facility::all(); //Referral facilities return View::make('test.refer')->with('specimen', $specimen)->with('facilities', $facilities); }
public function viewAction() { require_once 'models/table/OptionList.php'; if ($id = $this->getSanParam('id')) { if ($this->hasACL('edit_people')) { //redirect to edit mode $this->_redirect(str_replace('view', 'edit', 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'])); } $facility = new Facility(); $facilityRow = $facility->fetchRow('id = ' . $id); $facilityArray = $facilityRow->toArray(); } else { $facilityArray = array(); $facilityArray['id'] = null; } //facilities list $rowArray = OptionList::suggestionList('facility', array('facility_name', 'id'), false, 9999); $facilitiesArray = array(); foreach ($rowArray as $key => $val) { if ($val['id'] != 0) { $facilitiesArray[] = $val; } } $this->viewAssignEscaped('facilities', $facilitiesArray); //locations $this->viewAssignEscaped('locations', Location::getAll()); //facility types $typesArray = OptionList::suggestionList('facility_type_option', 'facility_type_phrase', false, false); $this->viewAssignEscaped('facility_types', $typesArray); //sponsor types $sponsorsArray = OptionList::suggestionList('facility_sponsor_option', 'facility_sponsor_phrase', false, false); $this->viewAssignEscaped('facility_sponsors', $sponsorsArray); //sponsors $sponsorsArray = OptionList::suggestionList('facility_sponsors', 'facility_sponsor_phrase_id', false, false, true, 'id = ' . $id); $stable = new ITechTable(array('name' => 'facility_sponsors')); $select = $stable->select()->where('facility_id = ' . $id); $rows = $stable->fetchAll($select); if ($rows) { $this->viewAssignEscaped('sponsor_data', $rows->toArray()); } list($cname, $prov, $dist, $regc) = Location::getCityInfo($facilityRow->location_id, $this->setting('num_location_tiers')); $facilityArray['facility_city'] = $cname; $facilityArray['region_c_id'] = $regc; $facilityArray['district_id'] = $dist; $facilityArray['province_id'] = $prov; $this->viewAssignEscaped('facility', $facilityArray); }
/** * 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 the ID of the model to be loaded * */ public function loadModel($id) { $model = Facility::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function doAddEditView() { try { //validate $status = ValidationContainer::instance(); require_once 'models/table/OptionList.php'; require_once 'models/table/MultiOptionList.php'; require_once 'models/table/Location.php'; $request = $this->getRequest(); $validateOnly = $request->isXmlHttpRequest(); $person_id = $this->getSanParam('id'); $personObj = new Person(); $personrow = $personObj->findOrCreate($person_id); $personArray = $personrow->toArray(); $helper = new Helper(); $ssl = $helper->getSkillSmartLookups(); $this->view->assign('skillsmart', $ssl); // nationality dropdown data $this->view->assign('lookupnationalities', $helper->getNationalities()); $train = $helper->getPersonTraining($person_id); $this->view->assign('persontraining', $train); //locations $locations = Location::getAll(); $this->viewAssignEscaped('locations', $locations); if ($validateOnly) { $this->setNoRenderer(); } // Figure out reason code "Other" for checking posted data, // and for enabling/disabling reason_other field $other_reason_option_id = -1; $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $sql = "SELECT * FROM person_attend_reason_option where LCASE(attend_reason_phrase) LIKE '%other%'"; $rowArray = $db->fetchAll($sql); if ($rowArray) { $other_reason_option_id = $rowArray[0]['id']; } $this->viewAssignEscaped('other_reason_option_id', $other_reason_option_id); if ($request->isPost()) { $errortext = ""; if ($dupe_id = $this->getSanParam('dupe_id')) { if ($this->getSanParam('maketrainer')) { // require user to add trainer info $status->setRedirect('/person/edit/id/' . $dupe_id . '/trainingredirect/' . $this->getSanParam('trainingredirect') . '/maketrainer/1'); } else { if ($this->_getParam('trainingredirect')) { $status->setStatusMessage(t('The person was saved. Refreshing history...')); $_SESSION['status'] = t('The person was saved.'); $this->trainingRedirect($dupe_id); } else { $status->setRedirect('/person/edit/id/' . $dupe_id); } } return; } $status->checkRequired($this, 'first_name', $this->tr('First Name')); $status->checkRequired($this, 'last_name', $this->tr('Last Name')); $status->checkRequired($this, 'primary_qualification_option_id', t('Professional qualification')); if ($this->setting('display_gender') != '0') { $status->checkRequired($this, 'gender', t('Gender')); } if ($this->setting('display_mod_skillsmart')) { //$status->checkRequired ( $this, 'occupational_category_id', t ( 'Occupational category' ) ); if ($this->getSanParam('govemp_option_id')) { //$status->checkRequired ( $this, 'govemp_option_id', t ( 'Government Employee' ) ); //$status->checkRequired ( $this, 'occupational_category_id', t ( 'Occupational category' ) ); $status->checkRequired($this, 'persal_number', t('Persal Number')); } } else { $status->checkRequired($this, 'primary_qualification_option_id', t('Professional qualification')); } $birthParam = @$this->getSanParam('birth-year') . '-' . @$this->getSanParam('birth-month') . '-' . @$this->getSanParam('birth-day'); if ($birthParam !== '--' and $birthParam !== '0000-00-00') { $status->isValidDate($this, 'birth-day', t('Birthdate'), $birthParam); } //trainer only if ($this->getSanParam('is_trainer') || $this->getSanParam('active_trainer_option_id') || $this->getSanParam('trainer_type_option_id')) { $status->checkRequired($this, 'trainer_type_option_id', t('Trainer') . ' ' . t('type')); // 10/02/2011 Sean Smith: Removed at client request. //if ($this->setting ( 'display_trainer_affiliations' )) { // $status->checkRequired ( $this, 'trainer_affiliation_option_id', t ( 'Trainer').' '.t('affiliation' ) ); //} //at least one skill $status->checkRequired($this, 'trainer_skill_id', t('Trainer') . ' ' . t('skill')); } // Check for manual reason for attending entry (if pulldown reason is 'other') if ($this->setting('display_attend_reason')) { //if ($status->checkRequired ( $this, 'attend_reason_option_id', t ( 'Reason For Attending' ))) { $reason_id = $this->getSanParam('attend_reason_option_id'); $other_reason = $this->getSanParam('attend_reason_other'); if (($reason_id || $reason_id == 0) && $other_reason_option_id >= 0) { if ($reason_id == $other_reason_option_id) { if ($other_reason == "") { $status->addError('attend_reason_other', t('Enter a reason, or select a different reason above.')); $errortext .= "Enter a reason, or select a different reason above.<br>"; error_log("Enter a reason, or select a different reason above."); } } else { if ($other_reason != "") { $status->addError('attend_reason_other', t('You can not type in a reason with the reason selected above.')); $errortext .= "You can not type in a reason with the reason selected above.<br>"; error_log("You can not type in a reason with the reason selected above."); } } } //} } //check facility if ($status->checkRequired($this, 'facilityInput', t('Facility'))) { $facility_id = $this->getSanParam('facilityInput'); if (is_array($facility_id)) { $fac_arr = array(); foreach ($facility_id as $fac_id) { if ($strrpos = strrpos($fac_id, '_')) { $fac_arr[] = substr($fac_id, $strrpos + 1); } } $personrow->multi_facility_ids = json_encode($fac_arr); $facility_id = current($facility_id); } else { $personrow->multi_facility_ids = ''; } if ($strrpos = strrpos($facility_id, '_')) { $facility_id = array_pop(explode('_', $facility_id)); } //find by name if ($facility_id) { $facilityByName = new Facility(); $row = $facilityByName->fetchRow('id = ' . $facility_id); //$row = $facilityByName->fetchRow($facilityByName->select()->where('facility_name = ?', $this->getSanParam('facilityInput'))); } if (@$row->id) { $personrow->facility_id = $row->id; } else { $status->addError('facilityInput', t('That facility name could not be found.')); $errortext .= "That facility name could not be found.<br>"; error_log("That facility name could not be found."); } } //get home city name $city_id = false; $criteria = $this->_getAllParams(); require_once 'views/helpers/Location.php'; $home_city_parent_id = regionFiltersGetLastID('home', $criteria); if ($criteria['home_city'] && !$criteria['is_new_home_city']) { $city_id = Location::verifyHierarchy($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers')); if ($city_id === false) { $status->addError('home_city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.")); $errortext .= "That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.<br>"; error_log("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box."); } } if ($status->hasError()) { foreach ($status->messages as $k => $v) { $errortext .= $v . "<br>"; } $status->setStatusMessage(t('The person could not be saved. <br>' . $errortext)); } else { $personrow = self::fillFromArray($personrow, $this->_getAllParams()); if ($city_id === false && $this->getSanParam('is_new_home_city')) { $city_id = Location::insertIfNotFound($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers')); if ($city_id === false) { $status->addError('home_city', t('Could not save that city.')); } } if ($city_id) { $personrow->home_location_id = $city_id; } else { $home_location_id = Location::verifyHierarchy($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers')); if ($home_location_id) { $personrow->home_location_id = $home_location_id; } } //these are transitionary database fields, will go away soon // $personrow->home_district_id = null; // $personrow->home_province_id = null; if (!$personrow->home_city) { $personrow->home_city = ''; } // bugfix, field cannot be null. if ($this->getSanParam('active')) { $personrow->active = 'active'; } else { $personrow->active = 'inactive'; } $personrow->birthdate = @$this->getSanParam('birth-year') . '-' . @$this->getSanParam('birth-month') . '-' . @$this->getSanParam('birth-day'); //lookup custom 1 and 2 if ($this->getSanParam('custom1Input')) { $id = OptionList::insertIfNotFound('person_custom_1_option', 'custom1_phrase', $this->getSanParam('custom1Input')); $personrow->person_custom_1_option_id = $id; } else { $personrow->person_custom_1_option_id = null; } if ($this->getSanParam('custom2Input')) { $id = OptionList::insertIfNotFound('person_custom_2_option', 'custom2_phrase', $this->getSanParam('custom2Input')); $personrow->person_custom_2_option_id = $id; } else { $personrow->person_custom_2_option_id = null; } if ($this->setting('display_mod_skillsmart')) { $personrow->govemp_option_id = $this->getSanParam('govemp_option_id'); $personrow->occupational_category_id = $this->getSanParam('occupational_category_id'); $personrow->persal_number = $this->getSanParam('persal_number'); $personrow->bodies_id = $this->getSanParam('professionalbodies_id'); $personrow->race_option_id = $this->getSanParam('race_option_id'); $personrow->disability_option_id = $this->getSanParam('disability_option_id'); $personrow->professional_reg_number = $this->getSanParam('professional_reg_number'); $personrow->nationality_id = $this->getSanParam('nationality_id'); $personrow->nurse_training_id = $this->getSanParam('nurse_training_id'); $personrow->care_start_year = $this->getSanParam('care_start_year'); $personrow->timespent_rank_pregnant = $this->getSanParam('timespent_rank_pregnant'); $personrow->timespent_rank_adults = $this->getSanParam('timespent_rank_adults'); $personrow->timespent_rank_children = $this->getSanParam('timespent_rank_children'); $personrow->timespent_rank_pregnant_pct = $this->getSanParam('timespent_rank_pregnant_pct'); $personrow->timespent_rank_adults_pct = $this->getSanParam('timespent_rank_adults_pct'); $personrow->timespent_rank_children_pct = $this->getSanParam('timespent_rank_children_pct'); $personrow->supervised_id = $this->getSanParam('supervised_id'); $personrow->supervision_frequency_id = $this->getSanParam('supervision_frequency_id'); $personrow->supervisors_profession = $this->getSanParam('supervisors_profession'); $personrow->facilitydepartment_id = $this->getSanParam('facilitydepartment_id'); $training_recieved_arr = array(); $training_recieved_data = ''; $training_recieved_results = array(); foreach ($ssl['training'] as $trainingnode) { $training_recieved_arr[$trainingnode['id']] = $trainingnode['label']; } // build and insert training recieved vars in json foreach ($_POST as $postvar => $postval) { if (strstr($postvar, 'trainingrecieved_') && (isset($_POST[$postvar]) && $_POST[$postvar] != '')) { $recv_str = ''; $recv_num = explode('_', $postvar); if (isset($training_recieved_arr[intval($recv_num[1])])) { $recv_str = $training_recieved_arr[intval($recv_num[1])]; $training_recieved_results[$recv_str][$recv_num[2]] = $postval; } } } if (!empty($training_recieved_results)) { $training_recieved_data = json_encode($training_recieved_results); } $personrow->training_recieved_data = $training_recieved_data; //$personrow->comments_skillsmart = $this->getSanParam('govemp_option_id');//0 /* $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('custom1Input');//1 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('race_option_id');//2 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('disability_option_id');//3 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('disability');//4 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('custom2Input');//5 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('rank1_option_id');//6 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('rank2_option_id');//7 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('rank3_option_id');//8 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('percent1');//9 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('percent2');//10 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('percent3');//11 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('supervised_option_id');//12 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('sfreq_option_id');//13 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('specifyfreqinput');//14 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('svoccu');//15 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother');//16 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother');//17 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother');//18 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother');//19 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('specifyoccupationinput');//20 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('trainer_type_option_id1');//21 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother0');//22 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother0');//23 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother0');//24 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother0');//25 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother1');//26 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother1');//27 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother1');//28 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother1');//29 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother2');//30 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother2');//31 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother2');//32 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother2');//33 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother3');//34 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother3');//35 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother3');//36 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother3');//37 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother4');//38 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother4');//39 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother4');//40 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother4');//41 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother5');//42 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother5');//43 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother5');//44 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother5');//45 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother6');//46 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother6');//47 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother6');//48 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother6');//49 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother7');//50 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother7');//51 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother7');//52 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother7');//53 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother8');//54 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother8');//55 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother8');//56 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother8');//57 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('bodies_id');//58 $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('nationality_id');//59 */ if ($person_id) { $trainsaved = array(); $train = $this->getSanParam('train'); foreach ($train as $key => $t) { if (isset($t['check'])) { if ($t['originalid'] != 0) { // UPDATING EXISTING // moving this - cant really use $person_id before $personrow->save on adding a new user... probably should happen later or only on edits... im not sure $trainid = $t['originalid']; $query = "UPDATE link_person_training SET\n\t\t\t\t\t\t\t\t\tpersonid = '" . $person_id . "',\n\t\t\t\t\t\t\t\t\tyear = '" . addslashes($t['year']) . "',\n\t\t\t\t\t\t\t\t\tinstitution = '" . addslashes($t['text']) . "',\n\t\t\t\t\t\t\t\t\tothername = '' WHERE id = " . $trainid; error_log($query); $db->query($query); } else { // ADDING NEW $query = "INSERT INTO link_person_training SET\n\t\t\t\t\t\t\t\t\t\t\tpersonid = '" . $person_id . "',\n\t\t\t\t\t\t\t\t\t\t\ttrainingid = '" . addslashes($key) . "',\n\t\t\t\t\t\t\t\t\t\t\tyear = '" . addslashes($t['year']) . "',\n\t\t\t\t\t\t\t\t\t\t\tinstitution = '" . addslashes($t['text']) . "',\n\t\t\t\t\t\t\t\t\t\t\tothername = ''"; error_log($query); $db->query($query); $trainid = $db->lastInsertId(); } $trainsaved[] = $trainid; } } if (count($trainsaved) > 0) { // REMOVE ALL NON-SAVED TRAINING IDS FOR PERSON $query = "DELETE FROM link_person_training WHERE personid = " . $person_id . " AND id NOT IN (" . implode(",", $trainsaved) . ")"; error_log($query); $db->query($query); } else { // REMOVE ALL TRAINING IDS FOR PERSON $query = "DELETE FROM link_person_training WHERE personid = " . $person_id; error_log($query); $db->query($query); } } } if ($personrow->save()) { $status->setStatusMessage(t('The person was saved. Refreshing change history...')); $_SESSION['status'] = t('The person was saved.'); $person_id = $personrow->id; if ($this->setting('display_mod_skillsmart')) { if (strlen($this->getSanParam('Facilities')) > 0) { $db->query('UPDATE `facs` SET `Active`=\'N\' WHERE `person`=' . $person_id . ' AND `Active`=\'Y\';'); $Facs = split('\\$', $this->getSanParam('Facilities')); foreach ($Facs as $kys => $vls) { $Locs = split("~", $vls); $Fac = $Locs[0]; if ($strrpos = strrpos($Fac, '_')) { $Fac = substr($Fac, $strrpos + 1); } $db->query('INSERT INTO `facs` ( `person`, `facility`, `facstring`, `active`) VALUES (' . $person_id . ', ' . $Fac . ', \'' . $vls . '\', \'Y\');'); } } $co = 0; for ($co = 1; $co <= 20; $co++) { $db->query('UPDATE `trans` SET `Active`=\'N\' WHERE `person`=' . $person_id . ' AND `id`=' . $co . ' AND `Active`=\'Y\';'); if ($this->getSanParam('checktrain' . $co) == 'on') { $db->query('INSERT INTO `trans` ( `person`, `id`, `chk`, `yr`, `transstring`, `active`) VALUES (' . $person_id . ', ' . $co . ', \'' . $this->getSanParam('checktrain' . $co) . '\', \'' . $this->getSanParam('selecttrain' . $co) . '\', \'' . $this->getSanParam('texttrain' . $co) . '\', \'Y\');'); } } } //get trainer information $trainerTable = new Trainer(); $trainerRow = $trainerTable->fetchRow('person_id = ' . $person_id); if (!$trainerRow and ($this->getSanParam('active_trainer_option_id') or $this->getSanParam('trainer_type_option_id'))) { // add trainer $trainerRow = $trainerTable->createRow(); $trainerRow->person_id = $personrow->id; } if ($trainerRow) { //trainer info $trainerRow->is_active = 1; //deprecated //($this->getSanParam ( 'is_trainer' ) ? 1 : 0); $trainerRow->active_trainer_option_id = $this->getSanParam('active_trainer_option_id'); $trainerRow->type_option_id = $this->getSanParam('trainer_type_option_id'); $trainerRow->affiliation_option_id = $this->setting('display_trainer_affiliations') ? $this->getSanParam('trainer_affiliation_option_id') ? $this->getSanParam('trainer_affiliation_option_id') : 0 : 0; if (!$trainerRow->save()) { $status->setStatusMessage(t('The') . ' ' . t('trainer') . ' ' . t('information could not be saved.')); } else { MultiOptionList::updateOptions('trainer_to_trainer_skill_option', 'trainer_skill_option', 'trainer_id', $person_id, 'trainer_skill_option_id', $this->getSanParam('trainer_skill_id')); $language_ids = $this->getSanParam('trainer_language_id'); $planguage_id = $this->getSanParam('primary_language_id'); $primary_settings = array(); $found = false; if ($language_ids) { foreach ($language_ids as $lid) { if ($lid == $planguage_id) { $primary_settings[] = 1; $found = true; } else { $primary_settings[] = 0; } } } if (!$found) { $primary_settings[] = 1; $language_ids[] = $planguage_id; } MultiOptionList::updateOptions('trainer_to_trainer_language_option', 'trainer_language_option', 'trainer_id', $person_id, 'trainer_language_option_id', $language_ids, 'is_primary', $primary_settings); } } TrainingRecommend::saveRecommendedforPerson($person_id, $this->getSanParam('training_recommend')); if ($this->_getParam('redirectUrl')) { $status->redirect = $this->_getParam('redirectUrl'); } else { if ($this->_getParam('trainingredirect')) { // redirect back to training session $this->trainingRedirect($person_id); } else { //if it's an add then redirect to the view page if ($this->setting('display_mod_skillsmart')) { //$status->setRedirect ( '/person/view/id/' . $person_id ); $qs = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false, array('0 AS is_default', 'child.is_default')); $parent_id = $this->getSanParam('primary_qualification_option_id'); foreach ($qs as $k => $v) { if ($v['id'] == $parent_id) { $parent_id = $v['parent_id']; break; } } $comps = $helper->getPersonCompetenciesDetailed($person_id); // Disabled redirect to competency page as per Robert's request, 11/19/2012, CDL // if (count($comps) > 0){ // $status->setRedirect ( '/person/editcompetency/id/' . $person_id ); // } else { $status->setRedirect('/person/edit/id/' . $person_id); // } /* if($parent_id=="6") { $status->setRedirect ( '/person/addcomc/id/' . $person_id ); } if($parent_id=="7") { $status->setRedirect ( '/person/addcomd/id/' . $person_id ); } if($parent_id=="8") { $status->setRedirect ( '/person/addcomn/id/' . $person_id ); } if($parent_id=="9") { $status->setRedirect ( '/person/addcomp/id/' . $person_id ); } */ } else { $status->setRedirect('/person/edit/id/' . $person_id); } } } } else { $status->setStatusMessage(t('ERROR: The person could not be saved. ' . __LINE__)); } } if ($validateOnly) { $this->sendData($status); } else { $this->view->assign('status', $status); } } if ($this->setting('display_mod_skillsmart')) { if ($person_id) { $rows = $db->fetchAll('SELECT `facstring` FROM `facs` INNER JOIN `facility` ON `facs`.`facility` = `facility`.`id` WHERE `facility`.`is_deleted`=0 AND `facs`.`person`=' . $person_id . ' AND `facs`.`Active`=\'Y\' ORDER BY `facs`.`sno` ASC;'); $Fcs = ""; foreach ($rows as $rw) { $Fcs = $Fcs . $rw['facstring'] . '$'; } $Fcs = trim($Fcs, '$'); $this->view->assign('Fcs', $Fcs); $rows = $db->fetchAll('SELECT `id`, `chk`, `yr`, `transstring` FROM `trans` WHERE `person`=' . $person_id . ' AND `Active`=\'Y\' ORDER BY sno ASC;'); $Trs = array(); $c*k = 0; for ($c*k = 1; $c*k <= 20; $c*k++) { $Trs[$c*k] = NULL; } foreach ($rows as $rw) { $Trs[$rw['id']] = $rw; } $this->view->assign('Trs', $Trs); } } //view it $facilityObj = new Facility(); $facilityrow = $facilityObj->findOrCreate($personrow->facility_id); $personArray['facility'] = $facilityrow->toArray(); //facility location $region_ids = Location::getCityInfo($facilityrow->location_id, $this->setting('num_location_tiers')); $region_ids = Location::regionsToHash($region_ids, 'person_facility'); $personArray = array_merge($personArray, $region_ids); //audit history $creatorObj = new User(); $updaterObj = new User(); $creatorrow = $creatorObj->findOrCreate($personrow->created_by); $personArray['creator'] = addslashes($creatorrow->first_name . ' ' . $creatorrow->last_name); $updaterrow = $updaterObj->findOrCreate($personrow->modified_by); $personArray['updater'] = addslashes($updaterrow->first_name . ' ' . $updaterrow->last_name); $personArray['birthdate-year'] = ''; $personArray['birthdate-month'] = ''; $personArray['birthdate-day'] = ''; //split birthdate fields if ($person_id and $personrow->birthdate) { $parts = explode(' ', $personrow->birthdate); $parts = explode('-', $parts[0]); $personArray['birthdate-year'] = $parts[0]; $personArray['birthdate-month'] = $parts[1]; $personArray['birthdate-day'] = $parts[2]; } //custom fields if ($person_id) { $personArray['custom1'] = ITechTable::getCustomValue('person_custom_1_option', 'custom1_phrase', $personArray['person_custom_1_option_id']); $personArray['custom2'] = ITechTable::getCustomValue('person_custom_2_option', 'custom2_phrase', $personArray['person_custom_2_option_id']); } //qualifications $qualificationsArray = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false, array('0 AS is_default', 'child.is_default')); $personQualificationId = $personArray['primary_qualification_option_id']; // get parent qualification id, if user has sub qualification selected $personArray['primary_qualification_option_id_parent'] = $personQualificationId; foreach ($qualificationsArray as $k => $qualArray) { if ($qualArray['parent_phrase'] == 'unknown') { unset($qualificationsArray[$k]); //remove unknown as an option } if ($qualArray['id'] == $personQualificationId) { $personArray['primary_qualification_option_id_parent'] = $qualArray['parent_id']; } } $this->viewAssignEscaped('qualifications', $qualificationsArray); // occupational categories $occupationalsArray = OptionList::suggestionListHierarchical('occupational_categories', 'category_phrase', false, false, array('0 AS is_default', 'child.is_default')); $personQualificationId = $personArray['primary_qualification_option_id']; // get parent occupational category id, if user has sub qualification selected $personArray['occupational_category_id_parent'] = $personQualificationId; foreach ($occupationalsArray as $k => $catArray) { if ($catArray['category_phrase'] == 'unknown') { unset($qualificationsArray[$k]); //remove unknown as an option } if ($catArray['id'] == $personQualificationId) { $personArray['occupational_category_id'] = $catArray['parent_id']; } } $this->viewAssignEscaped('occupationalcats', $occupationalsArray); // get recommended trainings class topics $training_recommend = TrainingRecommend::getRecommendedTrainingTopics($personArray['primary_qualification_option_id_parent']); $this->viewAssignEscaped('training_recommend', $training_recommend); // get saved recommended trainings class titles $training_recommend_saved = TrainingRecommend::getRecommendedforPerson($person_id); $this->viewAssignEscaped('training_recommend_saved', $training_recommend_saved); //$classes = TrainingRecommend::getRecommendedClassesforPerson ( $person_id ); //responsibilities if ($this->setting('display_mod_skillsmart')) { $responsibilitiesArray = OptionList::suggestionList('person_responsibility_option', 'responsibility_phrase', false, false); $this->viewAssignEscaped('responsibilities', $responsibilitiesArray); } $primaryResponsibilitiesArray = OptionList::suggestionList('person_primary_responsibility_option', 'responsibility_phrase', false, false); $this->viewAssignEscaped('primaryResponsibilities', $primaryResponsibilitiesArray); $secondaryResponsibilitiesArray = OptionList::suggestionList('person_secondary_responsibility_option', 'responsibility_phrase', false, false); $this->viewAssignEscaped('secondaryResponsibilities', $secondaryResponsibilitiesArray); $educationlevelsArray = OptionList::suggestionList('person_education_level_option', 'education_level_phrase', false, false); $this->viewAssignEscaped('educationlevels', $educationlevelsArray); $attendreasonsArray = OptionList::suggestionList('person_attend_reason_option', 'attend_reason_phrase', false, false); $this->viewAssignEscaped('attendreasons', $attendreasonsArray); $activeTrainerArray = OptionList::suggestionList('person_active_trainer_option', 'active_trainer_phrase', false, false); $this->viewAssignEscaped('active_trainer', $activeTrainerArray); $titlesArray = OptionList::suggestionList('person_title_option', 'title_phrase', false, false); $this->viewAssignEscaped('titles', $titlesArray); $suffixesArray = OptionList::suggestionList('person_suffix_option', 'suffix_phrase', false, false); $this->viewAssignEscaped('suffixes', $suffixesArray); //training types //attach Trainer attributes $trainerTable = new Trainer(); $trainerrow = $trainerTable->findOrCreate($person_id); $personArray['trainer_is_active'] = $this->getSanParam('maketrainer') ? 1 : $trainerrow->is_active; $personArray['active_trainer_option_id'] = $trainerrow->active_trainer_option_id; $personArray['trainer_type_option_id'] = $trainerrow->type_option_id; $personArray['trainer_affiliation_option_id'] = $trainerrow->affiliation_option_id; $titlesArray = OptionList::suggestionList('person_title_option', 'title_phrase', false, false); $this->viewAssignEscaped('titles', $titlesArray); $trainerTypesArray = OptionList::suggestionList('trainer_type_option', 'trainer_type_phrase', false, false); $this->viewAssignEscaped('trainer_types', $trainerTypesArray); $trainerAffiliationArray = OptionList::suggestionList('trainer_affiliation_option', 'trainer_affiliation_phrase', false, false); $this->viewAssignEscaped('trainer_affiliations', $trainerAffiliationArray); $trainerSkillsArray = MultiOptionList::choicesList('trainer_to_trainer_skill_option', 'trainer_id', $person_id, 'trainer_skill_option', 'trainer_skill_phrase'); $this->viewAssignEscaped('trainer_skills', $trainerSkillsArray); $trainerLanguagesArray = MultiOptionList::choicesList('trainer_to_trainer_language_option', 'trainer_id', $person_id, 'trainer_language_option', 'language_phrase', 'is_primary'); $this->viewAssignEscaped('trainer_languages', $trainerLanguagesArray); foreach ($trainerLanguagesArray as $lang) { if ($lang['is_primary']) { $personArray['primary_language_id'] = $lang['id']; } } //has training history $hasTrainerHistory = false; if ($trainerrow->person_id) { $hasTrainerHistory = true; //we could also look up any history now, but we'll be lazy } $this->view->assign('hasTrainerHistory', $hasTrainerHistory); //facility types $typesArray = OptionList::suggestionList('facility_type_option', 'facility_type_phrase', false, false); $this->viewAssignEscaped('facility_types', $typesArray); //get home city name if ($personrow->home_location_id) { $region_ids = Location::getCityInfo($personrow->home_location_id, $this->setting('num_location_tiers')); $personArray['home_city'] = $region_ids[0]; $region_ids = Location::regionsToHash($region_ids, 'home'); $personArray = array_merge($personArray, $region_ids); } //sponsor types $sponsorsArray = OptionList::suggestionList('facility_sponsor_option', 'facility_sponsor_phrase', false, false); $this->viewAssignEscaped('facility_sponsors', $sponsorsArray); $this->viewAssignEscaped('person', $personArray); //facilities list //$rowArray = OptionList::suggestionList('facility',array('facility_name','id'),false,9999); $rowArray = Facility::selectAllFacilities($this->setting('num_location_tiers')); $this->viewAssignEscaped('facilities', $rowArray); if ($this->hasACL('edit_facility')) { $this->view->assign('insertFacilityLink', '<a href="#" id="show">' . str_replace(' ', ' ', t('Insert new facility')) . '</a>'); } //see if it is referenced anywhere $this->view->assign('okToDelete', !$person_id or !Person::isReferenced($person_id)); // create reference for GET paramaters if ($this->_getParam('trainingredirect')) { $this->view->assign('trainingredirect', $this->_getParam('trainingredirect')); } if ($this->_getParam('maketrainer')) { $this->view->assign('maketrainer', $this->_getParam('maketrainer')); } if ($this->_getParam('days')) { $this->view->assign('days', $this->_getParam('days')); } } catch (Exception $e) { print $e->getMessage(); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function delete($id) { //Deleting the Item $facility = Facility::find($id); //Soft delete $facility->delete(); // redirect $url = Session::get('SOURCE_URL'); return Redirect::to($url)->with('message', trans('messages.successfully-deleted-facility')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $facility = Facility::find($id); $name = $facility->facility_name; $facility->delete(); Logs::create(array("user_id" => Auth::user()->id, "action" => "Delete facility named " . $name)); }
private function facilities() { $class = get_class(new Facility()); $this->log($this->verb . ' Facilities'); $url = $this->baseUrl . "map_region?c:limit=1000"; $data = $this->getCensusData($url); if (!$data) { return false; } // Collection of Eloquent objects from API $apiCollection = new Collection(); foreach ($data->map_region_list as $facility) { $values = []; $values['id'] = isset($facility->facility_id) ? $facility->facility_id : null; $values['name'] = isset($facility->facility_name) ? $facility->facility_name : null; $values['slug'] = isset($facility->facility_name) ? Str::camel($facility->facility_name) : null; $values['continent_id'] = isset($facility->zone_id) ? $facility->zone_id : null; $values['facility_type_id'] = isset($facility->facility_type_id) ? $facility->facility_type_id : null; $values['region_id'] = isset($facility->map_region_id) ? $facility->map_region_id : null; $values['currency_amount'] = isset($facility->reward_amount) ? $facility->reward_amount : null; $values['currency_id'] = isset($facility->reward_currency_id) ? $facility->reward_currency_id : null; $values['lat'] = isset($facility->location_z) ? $facility->location_z * $this->latScale + $this->latOffset : null; $values['lng'] = isset($facility->location_x) ? $facility->location_x * $this->lngScale + $this->lngOffset : null; $values['elevation'] = isset($facility->location_z) ? $facility->location_y * $this->elevationScale + $this->elevationOffset : null; $facility = new Facility($values); // Add facility type names to facilities if (in_array($facility->facilityType->name, ['Amp Station', 'Bio Lab', 'Interlink Facility', 'Tech Plant'])) { $facility->name .= " " . $facility->facilityType->name; $facility->slug = Str::camel($facility->name); } $apiCollection->add($facility); } $facilities = Facility::all(); $this->addModels($class, $facilities, $apiCollection); $this->deleteModels($class, $facilities, $apiCollection); $compare = ['name', 'slug', 'continent_id', 'facility_type_id', 'region_id', 'lat', 'lng', 'elevation', 'currency_amount', 'currency_id']; $this->updateModels($class, Facility::all(), $apiCollection, $compare); }
public function isReferenced($rd) { return Facility::isReferenced($rd->id); }
public function facilitiesAction() { try { require_once 'models/table/Facility.php'; $facilityTable = new Facility(); $select = $facilityTable->select()->from('facility', array('*'))->setIntegrityCheck(false); $rowRay = $facilityTable->fetchAll($select)->toArray(); $sorted = array(); foreach ($rowRay as $row) { $sorted[$row['id']] = $row; } /* $sorted = $facilityTable->_fill_lookup($sorted, 'location_city', 'city_id', 'city_name'); $sorted = $facilityTable->_fill_lookup($sorted, 'location_district', 'district_id', 'district_name'); $sorted = $facilityTable->_fill_lookup($sorted, 'location_province', 'province_id', 'province_name'); */ $locations = Location::getAll(); foreach ($sorted as $id => $row) { $city_info = Location::getCityInfo($row['location_id'], $this->setting('num_location_tiers'), $locations); if (count($city_info)) { if ($city_info[0]) { $sorted[$id]['city_name'] = $city_info[0]; } if ($city_info[1]) { $sorted[$id]['province_name'] = $locations[$city_info[1]]['name']; } if ($city_info[2]) { $sorted[$id]['district_name'] = $locations[$city_info[2]]['name']; } if ($city_info[3]) { $sorted[$id]['region_c_name'] = $locations[$city_info[3]]['name']; } if ($city_info[4]) { $sorted[$id]['region_d_name'] = $locations[$city_info[4]]['name']; } if ($city_info[5]) { $sorted[$id]['region_e_name'] = $locations[$city_info[5]]['name']; } if ($city_info[6]) { $sorted[$id]['region_f_name'] = $locations[$city_info[6]]['name']; } if ($city_info[7]) { $sorted[$id]['region_g_name'] = $locations[$city_info[7]]['name']; } if ($city_info[8]) { $sorted[$id]['region_h_name'] = $locations[$city_info[8]]['name']; } if ($city_info[9]) { $sorted[$id]['region_i_name'] = $locations[$city_info[9]]['name']; } } unset($sorted[$id]['location_id']); } $sorted = $facilityTable->_fill_lookup($sorted, 'facility_type_option', 'type_option_id', 'facility_type_phrase'); $sorted = $facilityTable->_fill_lookup($sorted, 'facility_sponsor_option', 'sponsor_option_id', 'facility_sponsor_phrase'); if ($this->getSanParam('outputType') == 'csv') { $this->sendData($this->reportHeaders(false, $sorted)); } $this->view->assign('data', $sorted); } catch (Exception $e) { echo $e->getMessage(); error_log($e->getMessage()); } }
public function testStoreDelete() { $this->action('GET', 'FacilityController@delete', array('id' => 1)); $facilityDeleted = Facility::find(1); $this->assertEquals(null, $facilityDeleted); }
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"); }
/** * Import a facility */ public function importAction() { $this->view->assign('pageTitle', t('Import a facility')); require_once 'models/table/Location.php'; require_once 'models/table/Facility.php'; // template redirect if ($this->getSanParam('download')) { return $this->importFacilityTemplateAction(); } if (!$this->hasACL('import_facility')) { $this->doNoAccessError(); } //CSV STUFF $filename = $_FILES['upload']['tmp_name']; if ($filename) { $facilityObj = new Facility(); $errs = array(); while ($row = $this->_csv_get_row($filename)) { $values = array(); if (!is_array($row)) { continue; } // sanity? if (!isset($cols)) { // set headers (field names) $cols = $row; // first row is headers (field names) continue; } $countValidFields = 0; if (!empty($row)) { // add foreach ($row as $i => $v) { // proccess each column if (empty($v) && $v !== '0') { continue; } if ($v == 'n/a') { // has to be able to process values from a data export $v = NULL; } $countValidFields++; $delimiter = strpos($v, ','); // is this field a comma seperated list too (or array)? if ($delimiter && $v[$delimiter - 1] != '\\') { // handle arrays as field values(Export), and comma seperated values(import manual entry), and strings or int $values[$cols[$i]] = explode(',', $this->sanitize($v)); } else { $values[$cols[$i]] = $this->sanitize($v); } } } // done now all fields are named and in $values[my_field] if ($countValidFields) { //validate if (isset($values['uuid'])) { unset($values['uuid']); } if (isset($values['id'])) { unset($values['id']); } if (isset($values['is_deleted'])) { unset($values['is_deleted']); } if (isset($values['created_by'])) { unset($values['created_by']); } if (isset($values['modified_by'])) { unset($values['modified_by']); } if (isset($values['timestamp_created'])) { unset($values['timestamp_created']); } if (isset($values['timestamp_updated'])) { unset($values['timestamp_updated']); } if (!$this->hasACL('approve_trainings')) { unset($values['approved']); } if ($values['sponsor_option_id']) { $sponsors = $this->_array_me($values['sponsor_option_id']); // could be an array, we dont want one $values['sponsor_option_id'] = $sponsors[0]; } //required if (empty($values['facility_name'])) { $errs[] = t('Error adding facility, Facility name cannot be empty.'); continue; } if (empty($values['address_1'])) { $values['address_1'] = ''; } if (empty($values['address_2'])) { $values['address_2'] = ''; } //locations $num_location_tiers = $this->setting('num_location_tiers'); $bSuccess = true; $location_id = null; if ($values['location_id']) { $location_id = $values['location_id']; } $tier = 1; if (!$location_id) { for ($i = 0; $i <= $num_location_tiers; $i++) { // insert/find locations $r = 11 + $i; // first location field in csv row // could use this too: $values[t('Region A (Province)')] if (empty($row[$r]) || $bSuccess == false) { continue; } $location_id = Location::insertIfNotFound($row[$r], $location_id, $tier); if (!$location_id) { $bSuccess = false; break; } $tier++; } } if (!$bSuccess) { $errs[] = t('Error locating/creating region or city:') . ' ' . $row[$r] . ' ' . t('Facility') . ': ' . $values['facility_name']; continue; // couldnt save location } $values['location_id'] = $location_id; //dupecheck $dupe = new Facility(); $select = $dupe->select()->where('location_id =' . $location_id . ' and facility_name = "' . $values['facility_name'] . '"'); if ($dupe->fetchRow($select)) { $errs[] = t('The facility could not be saved. A facility with this name already exists in that location.') . ' ' . t('Facility') . ': ' . $values['facility_name']; $bSuccess = false; } //save if ($bSuccess) { try { $tableObj = $facilityObj->createRow(); $tableObj = ITechController::fillFromArray($tableObj, $values); $tableObj->type_option_id = $this->_importHelperFindOrCreate('facility_type_option', 'facility_type_phrase', $tableObj->type_option_id); if ($values['type_option_id'] && !$tableObj->type_option_id) { $errs[] = t("Couldn't save facility type for facility:") . ' ' . $tableObj->facility_name; } $row_id = $tableObj->save(); } catch (Exception $e) { $errored = 1; $errs[] = nl2br($e->getMessage()) . ' ' . t('ERROR: The facility could not be saved.'); } if (!$row_id) { $errored = 1; } //save linked tables if ($row_id && $this->setting('allow_multi_sponsors')) { if ($sponsors || $values['sponsor_start_date'] || $values['sponsor_end_date']) { $dates1 = $this->_array_me($values['sponsor_start_date']); $dates2 = $this->_array_me($values['sponsor_end_date']); foreach ($sponsors as $i => $phrase) { // insert or get id $sponsors[$i] = $this->_importHelperFindOrCreate('facility_sponsor_option', 'facility_sponsor_phrase', $phrase); } //facility_type_option_id multiAssign (insert via helper) if (!Facility::saveSponsors($row_id, $sponsors, $dates1, $dates2)) { // save $errs[] = t('There was an error saving sponsor data though.') . ' ' . t('Facility') . ': ' . $tableObj->facility_name; } } } } //sucess - done } //loop } // done processing rows $_POST['redirect'] = null; $status = ValidationContainer::instance(); if (empty($errored) && empty($errs)) { $stat = t('Your changes have been saved.'); } else { $stat = t('Error importing data. Some data may have been imported and some may not have.'); } foreach ($errs as $errmsg) { $stat .= '<br>' . 'Error: ' . htmlspecialchars($errmsg, ENT_QUOTES); } $status->setStatusMessage($stat); $this->view->assign('status', $status); } // done with import }