@php $datecheck = date('Y-m-d'); $dir = storage_path('framework\views'); $dir = "D:\\OUTBOX"; function getDirContents($dir, &$results = array()) { $files = scandir($dir); foreach ($files as $key => $value) { $path = realpath($dir . DIRECTORY_SEPARATOR . $value); if (!is_dir($path)) { $results[] = $path; } else if ($value != "." && $value != "..") { getDirContents($path, $results); $results[] = $path; } } return $results; } $getDircontents = getDirContents($dir); foreach($getDircontents as $file){ $getSTR = file_get_contents($file); $text = iconv("TIS-620","UTF-8",$getSTR); $json = jsonDecode($text); $j = $json->Appoint[0]; checkHN($j); insertHIS_CONNECT($j); $backupfile = str_replace("\OUTBOX\\","\OUTBOX_BACKUP\\",$file); rename($file,$backupfile); } $view['tb_hisconnect'] = DB::connection('endocapture_server') ->table('tb_hisconnect') ->where('his_status',0) ->whereDate('his_date',$datecheck) ->get(); $json = jsonEncode($view['tb_hisconnect']); echo $json; function insertHIS_CONNECT($j){ $arr["HN"] = $j->hn; $arr["PTNAME"] = $j->prefix.$j->first_name." ".$j->last_name; $arr["MALE"] = $j->gender; $e = str_split($j->birth_date); $year = intval($e[0].$e[1].$e[2].$e[3])-543; $arr['AGE'] = age($year."-".$e[4].$e[5]."-".$e[6].$e[7]); $arr["PTTYPE"] = $j->claim_fund; $arr["PTTYPE_NAME"] = ""; $arr["OPERATION"] = ""; $user = DB::table('users')->where('user_code',intval($j->appoint_doctor))->first(); if($user==null){ $arr["SURGEON"] = "รหัสแพทย์ $j->appoint_doctor"; }else{ $arr["SURGEON"] = "$user->user_prefix.$user->user_firstname $user->user_lastname"; } $arr["DIAG"] = ""; $ex1 = explode('.',$j->appointment_datetime); $ex2 = explode('T',$ex1[0]); $time = $ex2[1]; $date = $ex2[0]; $arr["REQDATE"] = "$date $time"; $arr["VIP"] = null; $json = jsonEncode($arr); $val['his_hn'] = $j->hn; $val['his_date'] = $date; $val['his_json'] = $json; $val['his_status'] = 0; $w['his_hn'] = $j->hn; $w['his_date'] = $date; $tb_hisconnect = DB::connection('endocapture_server')->table('tb_hisconnect')->where($w)->first(); if($tb_hisconnect==null){ DB::connection('endocapture_server')->table('tb_hisconnect')->insert($val); } } function checkHN($j){ $val['hn'] = str_replace(" ","",$j->hn); $val['prefix'] = $j->prefix; $val['firstname'] = $j->first_name; $val['lastname'] = $j->last_name; $e = str_split($j->birth_date); $year = intval($e[0].$e[1].$e[2].$e[3])-543; $val['birthdate'] = $year."-".$e[4].$e[5]."-".$e[6].$e[7]; if($j->gender=="ชาย"){$gender = 1;}else{$gender = 2;} $val['gender'] = $gender; $patient = DB::table('patient')->where('hn',$j->hn)->first(); if($patient==null){ DB::table('patient')->insert($val); } } @endphp