예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(PatientRequest $request)
 {
     $patient = new Patient();
     $patient->patient_number = $request->patient_number;
     $patient->name = $request->name;
     $patient->gender = $request->gender;
     $patient->dob = $request->dob;
     $patient->email = $request->email;
     $patient->address = $request->address;
     $patient->phone_number = $request->phone_number;
     $patient->created_by = Auth::user()->id;
     $patient->save();
     $url = session('SOURCE_URL');
     return redirect()->to($url)->with('message', trans('messages.record-successfully-saved'))->with('active_patient', $patient->id);
 }
 public function createPatient($patientCode, $name, $lastname, $gender, $birthdate, $inhibitors, $jointDisease, $physiotherapy, $sickRelatives, $admissionDate)
 {
     $date = GeneralValues::getActualDate();
     $patient = new Patient();
     $patient->patientCode = $patientCode;
     $patient->name = $name;
     $patient->lastname = $lastname;
     $patient->gender = $gender;
     $patient->birthdate = $birthdate;
     $patient->inhibitors = $inhibitors;
     $patient->joint_disease = $jointDisease;
     $patient->physiotherapy = $physiotherapy;
     $patient->sick_relatives = $sickRelatives;
     $patient->admission_date = $admissionDate;
     $patient->created_at = $date;
     $patient->updated_at = $date;
     $patient->save();
     return $patient;
 }
예제 #3
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);
 }