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;
|
||||
|
||||
@@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Modules\Linksehat\Transformers\Livechat\LivechatResource;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Http\Controllers\DuitkuController;
|
||||
|
||||
use DB;
|
||||
use Str;
|
||||
@@ -191,6 +192,7 @@ class LivechatController extends Controller
|
||||
];
|
||||
return Helper::responseJson(data: $data);
|
||||
}
|
||||
|
||||
public function consultation_payment_choose($id){
|
||||
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
|
||||
$practitionerRole = PractitionerRole::where('id',$livechat->practitioner->id)->first();
|
||||
|
||||
@@ -70,4 +70,8 @@ class Livechat extends Model
|
||||
{
|
||||
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 $primaryKey = 'nID';
|
||||
|
||||
// protected $appends = [
|
||||
// 'status_name',
|
||||
// ];
|
||||
|
||||
@@ -48,4 +48,5 @@ class PrescriptionItem extends Model
|
||||
'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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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;
|
||||
organizations:Organizations[];
|
||||
specialities:Specialities[];
|
||||
diagonis:string;
|
||||
diagnosis:string;
|
||||
hospital:string;
|
||||
medicine: Medicine[];
|
||||
}
|
||||
|
||||
@@ -124,15 +124,16 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
||||
organizations: currentAppointment?.organizations || [],
|
||||
specialities: currentAppointment?.specialities || [],
|
||||
diagnosis: currentAppointment?.diagnosis || '',
|
||||
hospital: currentAppointment?.hospital || '',
|
||||
medicine : [{
|
||||
id: 0,
|
||||
drug_id: 0,
|
||||
qty: 0,
|
||||
signa: '',
|
||||
unit_id: 0,
|
||||
note: '', // input to database
|
||||
}],
|
||||
hospital: currentAppointment?.hospital || null,
|
||||
medicine : currentAppointment?.medicine || [
|
||||
{
|
||||
drug_id: 0,
|
||||
qty: 0,
|
||||
signa: '',
|
||||
unit_id: 0,
|
||||
note: '', // input to database
|
||||
}
|
||||
],
|
||||
}),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[currentAppointment]
|
||||
@@ -150,14 +151,17 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
||||
const [icdOptions, setIcdOptions] = useState([
|
||||
{ value: '-', label: '-' }
|
||||
]);
|
||||
const codes = defaultValues.diagnosis.split(',');
|
||||
const [selectedIcdOptions, setSelectedIcdOptions] = useState([]);
|
||||
useEffect(() => {
|
||||
const selectedCodes = icdOptions.filter((icd) => {
|
||||
// Logika pemilihan sesuai kebutuhan
|
||||
return codes.includes(icd.value);
|
||||
});
|
||||
setSelectedIcdOptions(selectedCodes);
|
||||
}, [icdOptions]);
|
||||
setValue('diagnosis', selectedCodes);
|
||||
}, [icdOptions, defaultValues]);
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
// 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
|
||||
useEffect(() => {
|
||||
if (hospitalOptions.length > 0 && !selectedHospitalOption) {
|
||||
setSelectedHospitalOption({value: '-', label: '-'});
|
||||
}
|
||||
}, [hospitalOptions, selectedHospitalOption]);
|
||||
const selectedId = hospitalOptions.find((hospital) => {
|
||||
|
||||
return hospital.value == defaultValues.hospital
|
||||
});
|
||||
setSelectedHospitalOption(selectedId);
|
||||
setValue('hospital', defaultValues.hospital)
|
||||
|
||||
}, [hospitalOptions, defaultValues]);
|
||||
|
||||
// Autocomplite drugs
|
||||
const [drugOptions, setDrugsOptions] = useState([]);
|
||||
@@ -240,6 +248,26 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
||||
});
|
||||
}, []); // 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 {
|
||||
reset,
|
||||
@@ -265,40 +293,40 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isEdit, currentAppointment]);
|
||||
|
||||
const onSubmit = async (data: FormValuesProps) => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('id', data.id);
|
||||
formData.append('diagnosis', data.diagnosis);
|
||||
formData.append('hospital', data.hospital);
|
||||
|
||||
// Iterasi melalui setiap objek dalam array medicine dan menambahkannya ke FormData
|
||||
data.medicine.forEach((medicineObj, index) => {
|
||||
// Anda dapat menambahkan setiap properti dari objek medicine ke FormData
|
||||
formData.append(`medicine[${index}][drug_id]`, medicineObj.drug_id);
|
||||
formData.append(`medicine[${index}][qty]`, medicineObj.qty);
|
||||
formData.append(`medicine[${index}][unit_id]`, medicineObj.unit_id);
|
||||
formData.append(`medicine[${index}][signa]`, medicineObj.signa);
|
||||
formData.append(`medicine[${index}][note]`, medicineObj.note);
|
||||
});
|
||||
const onSubmit = async (data: FormValuesProps) => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('id', data.id);
|
||||
formData.append('diagnosis', data.diagnosis);
|
||||
formData.append('hospital', data.hospital);
|
||||
|
||||
// Iterasi melalui setiap objek dalam array medicine dan menambahkannya ke FormData
|
||||
data.medicine.forEach((medicineObj, index) => {
|
||||
// Anda dapat menambahkan setiap properti dari objek medicine ke FormData
|
||||
formData.append(`medicine[${index}][drug_id]`, medicineObj.drug_id);
|
||||
formData.append(`medicine[${index}][qty]`, medicineObj.qty);
|
||||
formData.append(`medicine[${index}][unit_id]`, medicineObj.unit_id);
|
||||
formData.append(`medicine[${index}][signa]`, medicineObj.signa);
|
||||
formData.append(`medicine[${index}][note]`, medicineObj.note);
|
||||
});
|
||||
|
||||
|
||||
const response = await axios.post('/prescription', formData);
|
||||
reset();
|
||||
enqueueSnackbar('Berhasil menambahkan resep', {
|
||||
variant: 'success',
|
||||
});
|
||||
navigate('/e-prescription/live-chat');
|
||||
} catch (error: any) {
|
||||
console.log(error, 'submit')
|
||||
enqueueSnackbar(error.message ?? 'Failed Processing Request', { variant: 'error' });
|
||||
}
|
||||
const response = await axios.post('/prescription', formData);
|
||||
reset();
|
||||
enqueueSnackbar('Berhasil menambahkan resep', {
|
||||
variant: 'success',
|
||||
});
|
||||
navigate('/e-prescription/live-chat');
|
||||
} catch (error: any) {
|
||||
console.log(error, 'submit')
|
||||
enqueueSnackbar(error.message ?? 'Failed Processing Request', { variant: 'error' });
|
||||
}
|
||||
|
||||
const ascent = document?.querySelector('ascent');
|
||||
if (ascent != null) {
|
||||
ascent.innerHTML = '';
|
||||
}
|
||||
};
|
||||
const ascent = document?.querySelector('ascent');
|
||||
if (ascent != null) {
|
||||
ascent.innerHTML = '';
|
||||
}
|
||||
};
|
||||
return (
|
||||
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
|
||||
<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 }}>
|
||||
<Stack direction="row" alignItems="center" sx={{marginBottom: 4}}>
|
||||
<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>
|
||||
</Grid>
|
||||
|
||||
@@ -582,14 +607,29 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
||||
fullWidth
|
||||
/>
|
||||
</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>
|
||||
)}
|
||||
{
|
||||
index === 0 ? (
|
||||
<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>
|
||||
) : (
|
||||
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>
|
||||
@@ -601,7 +641,7 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
|
||||
size="large"
|
||||
loading={isSubmitting}
|
||||
>
|
||||
{!isEdit ? 'Save' : 'Save'}
|
||||
{!isEdit ? 'Save' : 'Update'}
|
||||
</LoadingButton>
|
||||
</Grid>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user