fixing add prescription
This commit is contained in:
@@ -10,6 +10,9 @@ use App\Models\OLDLMS\User;
|
||||
use App\Models\OLDLMS\UserDetail;
|
||||
use App\Models\OLDLMS\Prescription;
|
||||
use App\Models\OLDLMS\PrescriptionItem;
|
||||
|
||||
use App\Models\Prescription as PrescriptionAso;
|
||||
use App\Models\PrescriptionItem as PrescriptionItemAso;
|
||||
use App\Models\Icd;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Drug;
|
||||
@@ -79,6 +82,17 @@ class PrescriptionController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Insert atau Update ke table prescription di ASO
|
||||
$data = [
|
||||
'livechat_id' => $request->id,
|
||||
'organization_id' => $request->hospital,
|
||||
'icd_code' => $request->diagnosis,
|
||||
];
|
||||
$prescriptionAso = PrescriptionAso::updateOrCreate([
|
||||
'livechat_id' => $request->id
|
||||
], $data);
|
||||
|
||||
// Insert ke table tx_prescription di Linksehat
|
||||
$livechat = Livechat::where('nID', $request->id)->first();
|
||||
$livechatSummary = LivechatSummary::where('nIDLivechat', $request->id)->first();
|
||||
|
||||
@@ -117,7 +131,9 @@ class PrescriptionController extends Controller
|
||||
'sKodeRS' => $hospital,
|
||||
];
|
||||
|
||||
$prescription = Prescription::create($data);
|
||||
$prescription = Prescription::updateOrCreate([
|
||||
'nIDLivechat' => $request->id
|
||||
],$data);
|
||||
|
||||
$medicine = $request->medicine;
|
||||
$customMessages = [
|
||||
@@ -134,7 +150,10 @@ class PrescriptionController extends Controller
|
||||
return Helper::responseJson([$request->all()],'error', 400, $validator->errors());
|
||||
} else {
|
||||
// BeginTransaction
|
||||
// delete item
|
||||
DB::beginTransaction();
|
||||
PrescriptionItemAso::where('prescription_id', $prescriptionAso->id)->delete();
|
||||
PrescriptionItem::where('nIDPrescription', $prescriptionAso->id)->delete();
|
||||
foreach($medicine as $key => $value){
|
||||
$drugData = Drug::where('id', $value['drug_id'])->first();
|
||||
$drug = '';
|
||||
@@ -154,8 +173,20 @@ class PrescriptionController extends Controller
|
||||
'sSigna' => $value['signa'],
|
||||
'sNote' => $value['note'],
|
||||
];
|
||||
|
||||
$dataAso = [
|
||||
'prescription_id' => $prescriptionAso->id,
|
||||
'drug_id' => $value['drug_id'],
|
||||
'qty' => $value['qty'],
|
||||
'unit_id' => $value['unit_id'],
|
||||
'signa' => $value['signa'],
|
||||
'note' => $value['note']
|
||||
];
|
||||
// Insert Data
|
||||
try {
|
||||
// Insert to ASO
|
||||
PrescriptionItemAso::create($dataAso);
|
||||
// Insert to Linksehat
|
||||
PrescriptionItem::create($data);
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
|
||||
Reference in New Issue
Block a user