Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function konfirmasiAntrian(Request $request){
- Log::info("Konfirm Android Starter");
- $hariIni = date('Y-m-d');
- if(!isset($request->kode_booking) && !isset($request->token)){
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Ada Data Yang Tidak Terkirim, Silahkan Coba Lagi'];
- }
- //data request
- $kodeBooking = $request->kode_booking;
- $token = $request->token;
- //mencocokan data
- $dataBooking = DB::connection('mysql')->table('pasien_baru_temporary')
- ->where('kodeUnik',$kodeBooking)
- ->where('masukMaster',"belum")
- ->where('tanggalPeriksa', date('Y-m-d'))
- ->orderBy('id_pas', 'DESC')
- ->first();
- $dataToken = DB::connection('mysql')->table('token_konfirmasi')
- ->where('token',$token)
- ->where('status',0)
- ->first();
- if(!empty($dataBooking) && !empty($dataToken)){
- //validasi antrian
- if($dataBooking->tanggalPeriksa > $hariIni){
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Antrian Harus Dikonfirmasi Sesuai Tanggal('. $dataBooking->tanggalPeriksa .')'];
- }elseif($dataBooking->tanggalPeriksa < $hariIni){
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Antrian Sudah Kadaluarsa Silahkan Ambil Ulang'];
- }
- //setup data BPJS
- $noKodeBooking = $this->generateNoKodeBooking($dataBooking->isPasienBaru, $dataBooking->tanggalPeriksa);
- $generateReqAntreanBPJS = $this->generateReqAntrean($dataBooking, $noKodeBooking["kode_booking"], $noKodeBooking['nomor_antrian'], "toBpjs");
- // $generateReqUpdateWaktuBPJS = $this->generateReqUpdateWaktuBpjs($dataBooking, $noKodeBooking["kode_booking"]);
- //setup data local
- $generateReqAntreanLocal = $this->generateReqAntrean($dataBooking, $noKodeBooking["kode_booking"], $noKodeBooking['nomor_antrian']);
- //validasi agar pasien tidak bisa mengambil 2x nomor
- $cekDataAntrian = DB::connection('mysql')->table('antrian')
- ->where('nik',$dataBooking->nik)
- ->where('tgl_periksa', date('Y-m-d'))
- ->first();
- if(!empty($cekDataAntrian)){
- return ['status'=> 'error', 'code'=>500 , 'message'=>'NIK Telah Mengambil Antrian dengan Nomor Antrian '.$cekDataAntrian->no_antrian];
- }
- $validasiBpjs = 0;
- //hit to BPJS antreanAdd and updateWaktu
- try {
- $antreanBpjs = new BridgBpjsController();
- $postAntreanBpjs = $antreanBpjs->antreanAdd(new Request($generateReqAntreanBPJS));
- if ($postAntreanBpjs['metaData']->code != 200 ){
- if($postAntreanBpjs['metaData']->message != "Terdapat duplikasi Kode Booking"){
- //hit to table antrian dan antrian_tracer
- $postAntrian = DB::connection('mysql')->table('antrian')->insertGetId($generateReqAntreanLocal);
- $generateReqAntreanTracer = $this->generateReqAntreanTracer($postAntrian, $dataBooking);
- $postAntrianTracer = DB::connection('mysql')->table('antrian_tracer')->insert($generateReqAntreanTracer);
- $validasiBpjs = 1;
- }else{
- throw new \Exception($postAntreanBpjs['metaData']->message, (int)$postAntreanBpjs['metaData']->code);
- }
- }
- Log::info("POST BPJS SUCESS (SIMAPAN : ", [
- 'data' => $generateReqAntreanBPJS,
- 'response' => $postAntreanBpjs
- ]);
- } catch (\Exception $e) {
- Log::info("POST BPJS ERROR (SIMAPAN) : ", [
- 'data' => $generateReqAntreanBPJS,
- 'messageErr' => $e->getMessage()
- ]);
- return ['status'=> 'error', 'code'=>$e->getCode() , 'message'=>$e->getMessage()];
- }
- //hit to table antrian dan antrian_tracer
- if($validasiBpjs == 0){
- try {
- $postAntrian = DB::connection('mysql')->table('antrian')->insertGetId($generateReqAntreanLocal);
- $generateReqAntreanTracer = $this->generateReqAntreanTracer($postAntrian, $dataBooking);
- $postAntrianTracer = DB::connection('mysql')->table('antrian_tracer')->insert($generateReqAntreanTracer);
- } catch (\Exception $th) {
- Log::info("konfirmasiAntrian - Error - ", $th->getMessage());
- return ['status'=> 'error', 'code'=>500 , 'message'=>$th->getMessage()];
- }
- }
- // if($postAntreanBpjs && $postUpdateWaktuBpjs && $postAntrianTracer){
- if($postAntreanBpjs && $postAntrianTracer){
- //menempatkan pasien_baru_temporary ke table token_konfirmasi dan memasukan pasien temporary ke master
- try {
- //update pasien ke token_konfirmasi
- DB::connection('mysql')->table('token_konfirmasi')->where('token',$token)->update([
- 'pasien_baru_temporary_id' => $dataBooking->id_pas,
- 'status' => 1
- ]);
- //update status pasien
- DB::connection('mysql')->table('pasien_baru_temporary')
- ->where('id_pas', $dataBooking->id_pas)
- ->update(['masukMaster'=>'sudah']);
- //generate newToken
- $generateNewQr = $this->generateQrCode();
- //delete old svg token
- unlink(public_path('aset/images/tokenQR/'.$generateNewQr['data']->token.'.svg'));
- } catch (\Exception $e) {
- Log::info("konfirmasiAntrian - Error - ", $e->getMessage());
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Kesalahan Konfirmasi, Silahkan Coba Lagi'];
- }
- //log untuk jaga2 data
- $logs = [
- "data" => [
- "dataBpjs" => [
- "antreanAdd" => $generateReqAntreanBPJS,
- ],
- "dataLocal" => [
- "antrian" => $generateReqAntreanLocal,
- "antrian_tracer" => $generateReqAntreanTracer
- ]
- ],
- "responseBpjs" => [
- "antreanAdd" => $postAntreanBpjs,
- ],
- "metodeKonfirmasi" => "SCAN"
- ];
- Log::info("konfirmasiAntrian - Success - ", $logs);
- //return success
- return ['status' => 'success', 'code'=>200, 'message'=> 'Berhasil Konfirmasi Antrian '. $noKodeBooking['nomor_antrian'] .', Silahkan Ambil Nomor Antrian'];
- }
- }elseif(empty($dataBooking)){
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Data Pasien Tidak Ditemukan, Silahkan Cek Kembali / Ambi Ulang Antrian'];
- }elseif(empty($dataToken)){
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Token QR Sudah Digunakan, Silahkan Refresh Halaman QR'];
- }
- return ['status'=> 'error', 'code'=>500 , 'message'=>'Data Tidak Ditemukan, Silahkan Coba Lagi'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement