예제 #1
0
 public function adminSection()
 {
     $adminId = Session::get('admin_id');
     if (!isset($adminId)) {
         return Redirect::to('/');
     }
     $expertCount = Expert::where('status', '=', 'active')->count();
     $patientCount = Patient::where('status', '=', 'active')->count();
     return View::make('admin.admin-section')->with('expertCount', $expertCount)->with('patientCount', $patientCount);
 }
 public function index()
 {
     $query = e(Input::get('q', ''));
     if (!$query && $query == '') {
         return Response::json(array(), 400);
     }
     $patients = Patient::where('first_name', 'like', '%' . $query . '%')->orWhere('last_name', 'like', '%' . $query . '%')->orderBy('first_name', 'asc')->take(5)->get(array('id', 'first_name', 'last_name'))->toArray();
     $patients = $this->appendURL($patients, 'transactions');
     return Response::json(array('data' => $patients));
 }
 public function store()
 {
     if (Request::ajax()) {
         $data = array("agenda_id" => Input::get("agenda_id"), "patient" => Input::get("patient"), "reason" => Input::get("reason"), "fecha" => Input::get("fecha"), "start" => Input::get("start"), "end" => Input::get("end"));
         $rules = array("agenda_id" => 'required', "patient" => 'required|min:2|max:100', "reason" => 'required|min:2|max:200', "fecha" => 'required|min:1|max:100', "start" => 'required|min:1|max:100', "end" => 'required|min:1|max:100');
         $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png');
         $validation = Validator::make(Input::all(), $rules, $messages);
         //si la validación falla redirigimos al formulario de registro con los errores
         if ($validation->fails()) {
             return Response::json(array('success' => false, 'errors' => $validation->getMessageBag()->toArray()));
         } else {
             $agenda = Agenda::find(Input::get('agenda_id'));
             $user = User::where('email', Input::get('patient'))->orWhere('username', Input::get('patient'))->first();
             if ($user) {
                 $patient = Patient::where('user_id', $user->id)->first();
                 if (!$patient) {
                     $patient = new Patient();
                     $patient->user_id = $user->id;
                     $patient->save();
                 }
                 $docPatient = DoctorPatient::where('patient_id', $patient->id)->where('doctor_id', $agenda->doctor_id)->first();
                 if (!$docPatient) {
                     $docPatient = new DoctorPatient();
                     $docPatient->patient_id = $patient->id;
                     $docPatient->doctor_id = $agenda->doctor_id;
                     $docPatient->save();
                 }
                 $apo = new Appointment();
                 $apo->patient_id = $patient->id;
                 $apo->agenda_id = $agenda->id;
                 $apo->day = Input::get("fecha");
                 $apo->start_date = Input::get('start');
                 $apo->end_date = Input::get('end');
                 $apo->reason = Input::get('reason');
                 if ($agenda->appointment_state == 0) {
                     $apo->state = 'confirmed';
                 } else {
                     $apo->state = 'pending';
                 }
                 $apo->save();
                 if ($apo) {
                     if ($agenda->appointment_state == 0) {
                         $mgs = new MgsAppointment();
                         $mgs->appointment_id = $apo->id;
                         $mgs->text = "Su cita fue Confirmada";
                         $mgs->save();
                     }
                     return Response::json(array('success' => true));
                 }
             } else {
                 return Response::json(array('success' => false, 'errors' => 'El usuario no existe'));
             }
         }
     }
 }
예제 #4
0
 public function getPatient()
 {
     $patient = Patient::where('id', Input::get('patient'))->first();
     if (Until::isNull($patient)) {
         return Response::json('false');
     }
     $pres = Prescription::where('patient', $patient->id)->orderBy('created_at', 'desc')->take(5)->get();
     Until::isNull($pres) ?: $pres[0]->detail;
     $currentDay = Until::isNull($pres) ? false : date('Y-m-d') == date('Y-m-d', strtotime($pres[0]->created_at));
     return Response::json(array('patient' => $patient, 'pres' => $pres, 'currentDay' => $currentDay));
 }
예제 #5
0
 public function home()
 {
     if (Auth::guest()) {
         return Redirect::to('/login');
     }
     //appel des composants en base
     $nb_patients_total = Patient::all()->count();
     $nb_seances_total = Seance::all()->count();
     $nb_patients_semaine = Patient::where('created_at', '>=', time() - 7 * 24 * 60 * 60)->count();
     $nb_seances_semaine = Seance::where('date', '>=', time() - 7 * 24 * 60 * 60)->count();
     //retour de la vue
     return View::make('backend.home', compact('nb_patients_total', 'nb_seances_total', 'nb_patients_semaine', 'nb_seances_semaine'));
 }
 /**
  *	Función responsable de validar la existencia del un nuevo 
  *	paciente por su número de identificación ("identificationNumber").
  *
  *	@param string $identificationNumber, representa el nuevo número de identificación a validar.
  *	@return boolean, true: el número de identificación existe, false: el número de identificación 
  *	no existe
  */
 public function checkUnique($field = 'identificationNumber', $id = '')
 {
     // se asume el peor de los casos, que el paciente exista
     $response['isUnique'] = false;
     if ($field == Config::get('constants.PATIENT.ATTRS.IDENTIFICATION_NUMBER')) {
         // se obtiene el valor del campo a validar
         $value = trim(Input::get($field));
         // se consulta la cantidad de usuarios que coinciden con el filtro
         $patientsCount = Patient::where($field, $value)->where(Config::get('constants.PATIENT.ATTRS.PATIENT_ID'), '!=', $id)->count();
         // si la cantidad de usuarios es "== 0", quiere decir q el paciente aún NO EXISTE
         if ($patientsCount == 0) {
             $response['isUnique'] = true;
         }
     } else {
         $response = $this->respondWithError(sprintf(self::UNKNOW_PARAMETER, $field), self::CODE_WRONG_ARGUMENTS);
     }
     return $this->respondWithItem($response, new GenericTransformer());
 }
예제 #7
0
 function dataGetPatients($page = 1, $status = 'active')
 {
     $patients = Patient::where('status', $status)->get();
     if (isset($patients) && count($patients) > 0) {
         return json_encode(array('message' => 'found', 'patients' => $patients));
     } else {
         return json_encode(array('message' => 'empty'));
     }
 }
예제 #8
0
 /**
  * Display a listing of the resource.
  *
  * @param int $id
  * @return Response
  */
 public function facilityPatient($id)
 {
     $patients = Patient::where("facility_id", $id)->get();
     return View::make('patient.list_by_facility', compact('patients', 'id'));
 }
예제 #9
0
 /**
  * Function for processing the requests we receive from the external system
  * and putting the data into our system.
  *
  * @var array lab_requests
  */
 public function process($labRequest)
 {
     //First: Check if patient exists, if true dont save again
     $patient = Patient::where('external_patient_number', '=', $labRequest->patient->id)->get();
     if (!$patient->first()) {
         $patient = new Patient();
         $patient->external_patient_number = $labRequest->patient->id;
         $patient->patient_number = $labRequest->patient->id;
         $patient->name = $labRequest->patient->fullName;
         $gender = array('Male' => Patient::MALE, 'Female' => Patient::FEMALE);
         $patient->gender = $gender[$labRequest->patient->gender];
         $patient->dob = $labRequest->patient->dateOfBirth;
         $patient->address = $labRequest->address->address;
         $patient->phone_number = $labRequest->address->phoneNumber;
         $patient->created_by = User::EXTERNAL_SYSTEM_USER;
         $patient->save();
     } else {
         $patient = $patient->first();
     }
     //We check if the test exists in our system if not we just save the request in stagingTable
     if ($labRequest->parentLabNo == '0') {
         $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation);
     } else {
         $testTypeId = null;
     }
     if (is_null($testTypeId) && $labRequest->parentLabNo == '0') {
         $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND);
         return;
     }
     //Check if visit exists, if true dont save again
     $visitType = array('ip' => 'In-patient', 'op' => 'Out-patient');
     //Should be a constant
     $visit = Visit::where('visit_number', '=', $labRequest->patientVisitNumber)->where('visit_type', '=', $visitType[$labRequest->orderStage])->get();
     if (!$visit->first()) {
         $visit = new Visit();
         $visit->patient_id = $patient->id;
         $visit->visit_type = $visitType[$labRequest->orderStage];
         $visit->visit_number = $labRequest->patientVisitNumber;
         // We'll save Visit in a transaction a little bit below
     } else {
         $visit = $visit->first();
         if (strcmp($visitType[$labRequest->orderStage], $visit->visit_type) != 0) {
             $visit = new Visit();
             $visit->patient_id = $patient->id;
             $visit->visit_type = $visitType[$labRequest->orderStage];
             $visit->visit_number = $labRequest->patientVisitNumber;
         }
     }
     $test = null;
     //Check if parentLabNO is 0 thus its the main test and not a measure
     if ($labRequest->parentLabNo == '0') {
         //Check via the labno, if this is a duplicate request and we already saved the test
         $test = Test::where('external_id', '=', $labRequest->labNo)->get();
         if (!$test->first()) {
             //Specimen
             $specimen = new Specimen();
             $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0];
             // We'll save the Specimen in a transaction a little bit below
             $test = new Test();
             $test->test_type_id = $testTypeId;
             $test->test_status_id = Test::NOT_RECEIVED;
             $test->created_by = User::EXTERNAL_SYSTEM_USER;
             //Created by external system 0
             $test->requested_by = $labRequest->requestingClinician;
             $test->external_id = $labRequest->labNo;
             DB::transaction(function () use($visit, $specimen, $test) {
                 $visit->save();
                 $specimen->save();
                 $test->visit_id = $visit->id;
                 $test->specimen_id = $specimen->id;
                 $test->save();
             });
             $this->saveToExternalDump($labRequest, $test->id);
             return;
         }
     }
     $this->saveToExternalDump($labRequest, null);
 }
예제 #10
0
 /**
  * Search for patients meeting given criteria
  *
  * @param String $searchText
  * @return Collection 
  */
 public static function search($searchText)
 {
     return Patient::where('patient_number', '=', $searchText)->orWhere('name', 'LIKE', '%' . $searchText . '%')->orWhere('external_patient_number', '=', $searchText);
 }
예제 #11
0
 public function run()
 {
     Patient::where('patient_id', 'P01')->delete();
     Patient::create(['name' => 'Ahmed Raza', 'dob' => date('Y-m-d', strtotime('-25 years')), 'gender' => 'Male', 'age' => 25, 'email' => '*****@*****.**', 'city' => 'Lahore', 'country' => 'Pakistan', 'address' => 'DHA', 'phone' => '(0092) 334-4050495', 'cnic' => '12345-1234567-8', 'note' => 'Care the patient well.', 'patient_id' => 'P01']);
 }
예제 #12
0
 public function process($labRequest)
 {
     //First: Check if patient exists, if true dont save again
     $patient = Patient::where('external_patient_number', '=', $labRequest->PatientNumber)->get();
     if (!$patient->first()) {
         $patient = new Patient();
         $patient->external_patient_number = $labRequest->PatientNumber;
         $patient->patient_number = $labRequest->PatientNumber;
         $patient->name = $labRequest->FullNames;
         $gender = array('M' => Patient::MALE, 'F' => Patient::FEMALE, 'U' => Patient::UNKNOWN);
         $patient->gender = $gender[$labRequest->Sex];
         $patient->dob = $this->getDobFromAge($labRequest->Age);
         $patient->address = $labRequest->PoBox;
         $patient->phone_number = $labRequest->PatientsContact;
         $patient->created_by = User::EXTERNAL_SYSTEM_USER;
     } else {
         $patient = $patient->first();
     }
     //We check if the test exists in our system if not we just save the request in stagingTable
     $testTypeId = TestType::getTestTypeIdByTestName($labRequest->investigation);
     if (is_null($testTypeId) && $labRequest->parentLabNo == '0') {
         $this->saveToExternalDump($labRequest, ExternalDump::TEST_NOT_FOUND);
         return;
     }
     //Check if visit exists, if true dont save again
     $visit = Visit::where('visit_number', '=', $labRequest->RevisitNumber)->get();
     if (!$visit->first()) {
         $visit = new Visit();
         $visit->visit_type = 'Out-patient';
         // We'll save Visit in a transaction a little bit below
     } else {
         $visit = $visit->first();
     }
     $test = null;
     //Check via the labno, if this is a duplicate request and we already saved the test
     $test = Test::where('external_id', '=', $labRequest->RequestID)->get();
     if (!$test->first()) {
         //Specimen
         $specimen = new Specimen();
         $specimen->specimen_type_id = TestType::find($testTypeId)->specimenTypes->lists('id')[0];
         // We'll save the Specimen in a transaction a little bit below
         $test = new Test();
         $test->test_type_id = $testTypeId;
         $test->test_status_id = Test::NOT_RECEIVED;
         $test->created_by = User::EXTERNAL_SYSTEM_USER;
         //Created by external system 0
         $test->requested_by = $labRequest->DoctorRequesting;
         $test->external_id = $labRequest->RequestID;
         DB::transaction(function () use($visit, $specimen, $test, $patient) {
             $patient->save();
             $visit->patient_id = $patient->id;
             $visit->visit_number = Visit::orderBy('id', 'desc')->first()->id + 1;
             //$labRequest->RevisitNumber;
             $visit->save();
             $specimen->save();
             $test->visit_id = $visit->id;
             $test->specimen_id = $specimen->id;
             $test->save();
         });
         $this->saveToExternalDump($labRequest, $test->id);
         return;
     }
     $this->saveToExternalDump($labRequest, null);
     mssql_close($connection);
 }
 public function testPaymentRequest()
 {
     // Invoke API URL making a single test request (presumed successful)
     $this->call('POST', 'api/receiver', array(), array(), array(), $this->labRequestJsonSimpleTest);
     $labR = json_decode($this->labRequestJsonSimpleTest);
     // Was the data stored in the external dump?
     $externalDump = ExternalDump::where('lab_no', '=', $labR->labNo)->get();
     $this->assertTrue(count($externalDump) > 0);
     // Was a new patient created?
     $patient = Patient::where('external_patient_number', '=', $externalDump->first()->patient_id)->get();
     $this->assertTrue(count($patient) > 0);
     // Is there a Visit for this new patient?
     $visit = Visit::where('patient_id', '=', $patient->first()->id)->get();
     $this->assertTrue(count($visit) > 0);
     // Is there a Test for this visit?
     $test = Test::where('visit_id', '=', $visit->first()->id)->get();
     $this->assertTrue(count($visit) > 0);
     // Is there a Specimen for this new Test?
     $specimen = $test->first()->specimen;
     $this->assertTrue(count($specimen) > 0);
     $labRPR = json_decode($this->labRequestJsonSimpleTestPayMentRequest);
     //Second request similar to first but with payment details
     Interfacer::retrieve($labRPR);
     // Was the data stored in the external dump?
     // There should only be one record. The second only updates the first
     $externalDumpPayment = ExternalDump::where('lab_no', '=', $labR->labNo)->get();
     $this->assertTrue(count($externalDumpPayment) == 1);
     $this->assertEquals($labRPR->receiptNumber, $externalDumpPayment->first()->receipt_number);
 }