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\UserDetail;
|
||||||
use App\Models\OLDLMS\Prescription;
|
use App\Models\OLDLMS\Prescription;
|
||||||
use App\Models\OLDLMS\PrescriptionItem;
|
use App\Models\OLDLMS\PrescriptionItem;
|
||||||
|
|
||||||
|
use App\Models\Prescription as PrescriptionAso;
|
||||||
|
use App\Models\PrescriptionItem as PrescriptionItemAso;
|
||||||
use App\Models\Icd;
|
use App\Models\Icd;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Drug;
|
use App\Models\Drug;
|
||||||
@@ -79,6 +82,17 @@ class PrescriptionController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
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();
|
$livechat = Livechat::where('nID', $request->id)->first();
|
||||||
$livechatSummary = LivechatSummary::where('nIDLivechat', $request->id)->first();
|
$livechatSummary = LivechatSummary::where('nIDLivechat', $request->id)->first();
|
||||||
|
|
||||||
@@ -117,7 +131,9 @@ class PrescriptionController extends Controller
|
|||||||
'sKodeRS' => $hospital,
|
'sKodeRS' => $hospital,
|
||||||
];
|
];
|
||||||
|
|
||||||
$prescription = Prescription::create($data);
|
$prescription = Prescription::updateOrCreate([
|
||||||
|
'nIDLivechat' => $request->id
|
||||||
|
],$data);
|
||||||
|
|
||||||
$medicine = $request->medicine;
|
$medicine = $request->medicine;
|
||||||
$customMessages = [
|
$customMessages = [
|
||||||
@@ -134,7 +150,10 @@ class PrescriptionController extends Controller
|
|||||||
return Helper::responseJson([$request->all()],'error', 400, $validator->errors());
|
return Helper::responseJson([$request->all()],'error', 400, $validator->errors());
|
||||||
} else {
|
} else {
|
||||||
// BeginTransaction
|
// BeginTransaction
|
||||||
|
// delete item
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
PrescriptionItemAso::where('prescription_id', $prescriptionAso->id)->delete();
|
||||||
|
PrescriptionItem::where('nIDPrescription', $prescriptionAso->id)->delete();
|
||||||
foreach($medicine as $key => $value){
|
foreach($medicine as $key => $value){
|
||||||
$drugData = Drug::where('id', $value['drug_id'])->first();
|
$drugData = Drug::where('id', $value['drug_id'])->first();
|
||||||
$drug = '';
|
$drug = '';
|
||||||
@@ -154,8 +173,20 @@ class PrescriptionController extends Controller
|
|||||||
'sSigna' => $value['signa'],
|
'sSigna' => $value['signa'],
|
||||||
'sNote' => $value['note'],
|
'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
|
// Insert Data
|
||||||
try {
|
try {
|
||||||
|
// Insert to ASO
|
||||||
|
PrescriptionItemAso::create($dataAso);
|
||||||
|
// Insert to Linksehat
|
||||||
PrescriptionItem::create($data);
|
PrescriptionItem::create($data);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace Modules\Internal\Transformers;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
use App\Models\Prescription;
|
||||||
|
use App\Models\PrescriptionItem;
|
||||||
|
|
||||||
class LivechatResource extends JsonResource
|
class LivechatResource extends JsonResource
|
||||||
{
|
{
|
||||||
@@ -16,6 +18,12 @@ class LivechatResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray($request)
|
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 = [
|
$livechat = [
|
||||||
'id' => $this->nID,
|
'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,
|
'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,
|
'appointment_media' => $this->appointment->sMedia ?? null,
|
||||||
'status_chat' => $this->status_name ?? null,
|
'status_chat' => $this->status_name ?? null,
|
||||||
'payment_method' => $this->appointment->payment_method ?? null,
|
'payment_method' => $this->appointment->payment_method ?? null,
|
||||||
|
'diagnosis' => $diagnosis,
|
||||||
|
'hospital' => $hospital,
|
||||||
|
'medicine' => $prescriptionItem
|
||||||
];
|
];
|
||||||
|
|
||||||
$start_time = $this->dStartTime;
|
$start_time = $this->dStartTime;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Modules\Linksehat\Transformers\Livechat\LivechatResource;
|
use Modules\Linksehat\Transformers\Livechat\LivechatResource;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use App\Http\Controllers\DuitkuController;
|
||||||
|
|
||||||
use DB;
|
use DB;
|
||||||
use Str;
|
use Str;
|
||||||
@@ -191,6 +192,7 @@ class LivechatController extends Controller
|
|||||||
];
|
];
|
||||||
return Helper::responseJson(data: $data);
|
return Helper::responseJson(data: $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function consultation_payment_choose($id){
|
public function consultation_payment_choose($id){
|
||||||
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
|
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
|
||||||
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
|
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
|
||||||
|
|||||||
@@ -70,4 +70,8 @@ class Livechat extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Healthcare::class, 'nIDHealthCare', 'nID');
|
return $this->belongsTo(Healthcare::class, 'nIDHealthCare', 'nID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function summary(){
|
||||||
|
return $this->belongsTo(LivechatSummary::class, 'nID', 'nIDLivechat');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ class Prescription extends Model
|
|||||||
|
|
||||||
protected $table = 'tx_prescriptions';
|
protected $table = 'tx_prescriptions';
|
||||||
|
|
||||||
|
protected $primaryKey = 'nID';
|
||||||
|
|
||||||
// protected $appends = [
|
// protected $appends = [
|
||||||
// 'status_name',
|
// 'status_name',
|
||||||
// ];
|
// ];
|
||||||
|
|||||||
@@ -48,4 +48,5 @@ class PrescriptionItem extends Model
|
|||||||
'dTanggalResep' => 'datetime',
|
'dTanggalResep' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $primaryKey = 'nID';
|
||||||
}
|
}
|
||||||
|
|||||||
18
app/Models/Prescription.php
Normal file
18
app/Models/Prescription.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Traits\Blameable;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class Prescription extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
protected $fillable = [
|
||||||
|
'livechat_id',
|
||||||
|
'organization_id',
|
||||||
|
'icd_code'
|
||||||
|
];
|
||||||
|
}
|
||||||
19
app/Models/PrescriptionItem.php
Normal file
19
app/Models/PrescriptionItem.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class PrescriptionItem extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
protected $fillable = [
|
||||||
|
'prescription_id',
|
||||||
|
'drug_id',
|
||||||
|
'qty',
|
||||||
|
'unit_id',
|
||||||
|
'note',
|
||||||
|
'signa'
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -27,7 +27,8 @@ return new class extends Migration
|
|||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::table('practitioners', function (Blueprint $table) {
|
Schema::table('practitioners', function (Blueprint $table) {
|
||||||
//
|
$table->dropColumn('str_number');
|
||||||
|
$table->dropColumn('exp_date_str');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ return new class extends Migration
|
|||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::table('practitioner_roles', function (Blueprint $table) {
|
Schema::table('practitioner_roles', function (Blueprint $table) {
|
||||||
//
|
$table->dropColumn('sip_number');
|
||||||
|
$table->dropColumn('exp_date_sip');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('prescriptions', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('livechat_id');
|
||||||
|
$table->foreignId('organization_id');
|
||||||
|
$table->string('icd_code');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('prescriptions');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('prescription_items', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('prescription_id');
|
||||||
|
$table->foreignId('drug_id');
|
||||||
|
$table->integer('qty');
|
||||||
|
$table->foreignId('unit_id');
|
||||||
|
$table->string('note');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('prescription_items');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('prescription_items', function (Blueprint $table) {
|
||||||
|
$table->string('signa');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('prescription_items', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('signa');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -83,7 +83,7 @@ export type Appointment = {
|
|||||||
doctor_id:number;
|
doctor_id:number;
|
||||||
organizations:Organizations[];
|
organizations:Organizations[];
|
||||||
specialities:Specialities[];
|
specialities:Specialities[];
|
||||||
diagonis:string;
|
diagnosis:string;
|
||||||
hospital:string;
|
hospital:string;
|
||||||
medicine: Medicine[];
|
medicine: Medicine[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,15 +124,16 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
organizations: currentAppointment?.organizations || [],
|
organizations: currentAppointment?.organizations || [],
|
||||||
specialities: currentAppointment?.specialities || [],
|
specialities: currentAppointment?.specialities || [],
|
||||||
diagnosis: currentAppointment?.diagnosis || '',
|
diagnosis: currentAppointment?.diagnosis || '',
|
||||||
hospital: currentAppointment?.hospital || '',
|
hospital: currentAppointment?.hospital || null,
|
||||||
medicine : [{
|
medicine : currentAppointment?.medicine || [
|
||||||
id: 0,
|
{
|
||||||
drug_id: 0,
|
drug_id: 0,
|
||||||
qty: 0,
|
qty: 0,
|
||||||
signa: '',
|
signa: '',
|
||||||
unit_id: 0,
|
unit_id: 0,
|
||||||
note: '', // input to database
|
note: '', // input to database
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
[currentAppointment]
|
[currentAppointment]
|
||||||
@@ -150,14 +151,17 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
const [icdOptions, setIcdOptions] = useState([
|
const [icdOptions, setIcdOptions] = useState([
|
||||||
{ value: '-', label: '-' }
|
{ value: '-', label: '-' }
|
||||||
]);
|
]);
|
||||||
|
const codes = defaultValues.diagnosis.split(',');
|
||||||
const [selectedIcdOptions, setSelectedIcdOptions] = useState([]);
|
const [selectedIcdOptions, setSelectedIcdOptions] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const selectedCodes = icdOptions.filter((icd) => {
|
const selectedCodes = icdOptions.filter((icd) => {
|
||||||
// Logika pemilihan sesuai kebutuhan
|
return codes.includes(icd.value);
|
||||||
});
|
});
|
||||||
setSelectedIcdOptions(selectedCodes);
|
setSelectedIcdOptions(selectedCodes);
|
||||||
}, [icdOptions]);
|
setValue('diagnosis', selectedCodes);
|
||||||
|
}, [icdOptions, defaultValues]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Ambil data dari API dan atur opsi ICD
|
// Ambil data dari API dan atur opsi ICD
|
||||||
@@ -189,10 +193,14 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
|
|
||||||
// Set default value saat hospitalOptions berubah
|
// Set default value saat hospitalOptions berubah
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hospitalOptions.length > 0 && !selectedHospitalOption) {
|
const selectedId = hospitalOptions.find((hospital) => {
|
||||||
setSelectedHospitalOption({value: '-', label: '-'});
|
|
||||||
}
|
return hospital.value == defaultValues.hospital
|
||||||
}, [hospitalOptions, selectedHospitalOption]);
|
});
|
||||||
|
setSelectedHospitalOption(selectedId);
|
||||||
|
setValue('hospital', defaultValues.hospital)
|
||||||
|
|
||||||
|
}, [hospitalOptions, defaultValues]);
|
||||||
|
|
||||||
// Autocomplite drugs
|
// Autocomplite drugs
|
||||||
const [drugOptions, setDrugsOptions] = useState([]);
|
const [drugOptions, setDrugsOptions] = useState([]);
|
||||||
@@ -240,6 +248,26 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
});
|
});
|
||||||
}, []); // useEffect dijalankan hanya sekali saat komponen dimount
|
}, []); // useEffect dijalankan hanya sekali saat komponen dimount
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (defaultValues.medicine.length > 0) {
|
||||||
|
defaultValues.medicine.map((med, index) => {
|
||||||
|
const selectedDrugId = drugOptions.find((drug) => {
|
||||||
|
return drug.value == med.drug_id
|
||||||
|
});
|
||||||
|
handleAutocompleteChange(selectedDrugId,index)
|
||||||
|
|
||||||
|
const selectedUnitId = unitOptions.find((unit) => {
|
||||||
|
return unit.value == med.unit_id
|
||||||
|
});
|
||||||
|
handleAutocompleteChangeUnit(selectedUnitId,index)
|
||||||
|
|
||||||
|
// Contoh: Lakukan tindakan lainnya sesuai kebutuhan Anda
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('Medicine is empty');
|
||||||
|
}
|
||||||
|
}, [defaultValues.medicine]);
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
reset,
|
reset,
|
||||||
@@ -265,40 +293,40 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isEdit, currentAppointment]);
|
}, [isEdit, currentAppointment]);
|
||||||
|
|
||||||
const onSubmit = async (data: FormValuesProps) => {
|
const onSubmit = async (data: FormValuesProps) => {
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('id', data.id);
|
formData.append('id', data.id);
|
||||||
formData.append('diagnosis', data.diagnosis);
|
formData.append('diagnosis', data.diagnosis);
|
||||||
formData.append('hospital', data.hospital);
|
formData.append('hospital', data.hospital);
|
||||||
|
|
||||||
// Iterasi melalui setiap objek dalam array medicine dan menambahkannya ke FormData
|
// Iterasi melalui setiap objek dalam array medicine dan menambahkannya ke FormData
|
||||||
data.medicine.forEach((medicineObj, index) => {
|
data.medicine.forEach((medicineObj, index) => {
|
||||||
// Anda dapat menambahkan setiap properti dari objek medicine ke FormData
|
// Anda dapat menambahkan setiap properti dari objek medicine ke FormData
|
||||||
formData.append(`medicine[${index}][drug_id]`, medicineObj.drug_id);
|
formData.append(`medicine[${index}][drug_id]`, medicineObj.drug_id);
|
||||||
formData.append(`medicine[${index}][qty]`, medicineObj.qty);
|
formData.append(`medicine[${index}][qty]`, medicineObj.qty);
|
||||||
formData.append(`medicine[${index}][unit_id]`, medicineObj.unit_id);
|
formData.append(`medicine[${index}][unit_id]`, medicineObj.unit_id);
|
||||||
formData.append(`medicine[${index}][signa]`, medicineObj.signa);
|
formData.append(`medicine[${index}][signa]`, medicineObj.signa);
|
||||||
formData.append(`medicine[${index}][note]`, medicineObj.note);
|
formData.append(`medicine[${index}][note]`, medicineObj.note);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const response = await axios.post('/prescription', formData);
|
const response = await axios.post('/prescription', formData);
|
||||||
reset();
|
reset();
|
||||||
enqueueSnackbar('Berhasil menambahkan resep', {
|
enqueueSnackbar('Berhasil menambahkan resep', {
|
||||||
variant: 'success',
|
variant: 'success',
|
||||||
});
|
});
|
||||||
navigate('/e-prescription/live-chat');
|
navigate('/e-prescription/live-chat');
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error, 'submit')
|
console.log(error, 'submit')
|
||||||
enqueueSnackbar(error.message ?? 'Failed Processing Request', { variant: 'error' });
|
enqueueSnackbar(error.message ?? 'Failed Processing Request', { variant: 'error' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const ascent = document?.querySelector('ascent');
|
const ascent = document?.querySelector('ascent');
|
||||||
if (ascent != null) {
|
if (ascent != null) {
|
||||||
ascent.innerHTML = '';
|
ascent.innerHTML = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
|
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
@@ -508,9 +536,6 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
<Grid item xs={12} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
|
<Grid item xs={12} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
|
||||||
<Stack direction="row" alignItems="center" sx={{marginBottom: 4}}>
|
<Stack direction="row" alignItems="center" sx={{marginBottom: 4}}>
|
||||||
<Typography variant='subtitle1' gutterBottom>Obat</Typography>
|
<Typography variant='subtitle1' gutterBottom>Obat</Typography>
|
||||||
<Button color="inherit" variant="outlined" startIcon={<AddIcon/>} sx={{marginLeft: 'auto'}} onClick={() => append({medicine_name: '', medicine_price: 0, request_log_id: 1 })}>
|
|
||||||
<Typography variant="button" display="block">Obat</Typography>
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@@ -582,14 +607,29 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{
|
||||||
{index !== fields.length - 1 && (
|
index === 0 ? (
|
||||||
<Grid item xs={1} sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
<Grid item xs={1} sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
<IconButton size='large' color='error' onClick={() => remove(index)}>
|
<IconButton size='large' color='primary' onClick={() => append({medicine_name: '', medicine_price: 0, request_log_id: 1 })}>
|
||||||
<RemoveIcon />
|
<AddIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
) : (
|
||||||
|
index == (fields.length-1) ? (
|
||||||
|
<Grid item xs={1} sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<IconButton size='large' color='error' onClick={() => remove(index)}>
|
||||||
|
<RemoveIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Grid>
|
||||||
|
) : (
|
||||||
|
<Grid item xs={1} sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<IconButton size='large' color='primary' onClick={() => append({medicine_name: '', medicine_price: 0, request_log_id: 1 })}>
|
||||||
|
<AddIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Grid>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -601,7 +641,7 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
|||||||
size="large"
|
size="large"
|
||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
>
|
>
|
||||||
{!isEdit ? 'Save' : 'Save'}
|
{!isEdit ? 'Save' : 'Update'}
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user