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();
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Modules\Internal\Transformers;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Prescription;
|
||||
use App\Models\PrescriptionItem;
|
||||
|
||||
class LivechatResource extends JsonResource
|
||||
{
|
||||
@@ -16,6 +18,12 @@ class LivechatResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$prescription = Prescription::where('livechat_id', $this->nID)->first();
|
||||
$diagnosis = $prescription ? $prescription->icd_code : '';
|
||||
$hospital = $prescription ? $prescription->organization_id : '';
|
||||
|
||||
$prescriptionItem = $prescription ? PrescriptionItem::where('prescription_id', $prescription->id)->get() : [];
|
||||
|
||||
$livechat = [
|
||||
'id' => $this->nID,
|
||||
'doctor_name' => isset($this->doctor->user->sFirstName) ? $this->doctor->user->detail->sTitlePrefix . '. ' . $this->doctor->user->sFirstName . ' ' . $this->doctor->user->sLastName . ' ' . $this->doctor->user->detail->sTitleSuffix : null,
|
||||
@@ -36,6 +44,9 @@ class LivechatResource extends JsonResource
|
||||
'appointment_media' => $this->appointment->sMedia ?? null,
|
||||
'status_chat' => $this->status_name ?? null,
|
||||
'payment_method' => $this->appointment->payment_method ?? null,
|
||||
'diagnosis' => $diagnosis,
|
||||
'hospital' => $hospital,
|
||||
'medicine' => $prescriptionItem
|
||||
];
|
||||
|
||||
$start_time = $this->dStartTime;
|
||||
|
||||
Reference in New Issue
Block a user