diff --git a/Modules/Internal/Http/Controllers/Api/EprescriptionController.php b/Modules/Internal/Http/Controllers/Api/EprescriptionController.php
deleted file mode 100644
index 8aecafe6..00000000
--- a/Modules/Internal/Http/Controllers/Api/EprescriptionController.php
+++ /dev/null
@@ -1,216 +0,0 @@
-startDate;
- $endDate = $request->endDate;
-
- $livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare');
- // ->where('nIDAppointment', '!=', null)
- // ->where('nIDAppointment', '!=', '');
-
-
- if ($startDate) {
- $livechat = $livechat->where('dCreateOn', '>=', $startDate);
- }
-
- if ($endDate) {
- $endDate = date('Y-m-d', strtotime($endDate . ' +1 day'));
- $livechat = $livechat->where('dCreateOn', '<', $endDate);
- }
- $livechat = $livechat->latest()->paginate(15);
-
- return response()->json(Helper::paginateResources(LivechatResource::collection($livechat)));
- }
-
- /**
- * Show the specified resource.
- * @param int $id
- * @return Renderable
- */
- public function show($id)
- {
- $livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare')
- ->where('nIDAppointment', '!=', null)->where('nIDAppointment', '!=', '')
- ->where('nID', $id)
- ->first();
- return response()->json(new LivechatResource($livechat));
- }
-
- public function export(Request $request)
- {
- $startDate = $request->has('startDate') ? $request->input('startDate') : '';
- $endDate = $request->has('endDate') ? $request->input('endDate') : '';
-
- $liveChats = Livechat::with('user:nID,sFirstName,sLastName,sEmail,sPhone,nIDUser', 'doctor:nID,nIDSpesialis,nIDUser', 'doctor.user:nID,sFirstName,sLastName', 'appointment:nID,sPaymentStatus,sPaymentMethod', 'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment', 'healthCare:nID,sHealthCare')
- ->where(function (Builder $query) use ($startDate, $endDate) {
- // $query->where('nIDAppointment', '!=', null);
- // $query->where('nIDAppointment', '!=', '');
- if ($startDate) {
- $query->where('dCreateOn', '>=', $startDate);
- }
- if ($endDate) {
- $endDate = date('Y-m-d', strtotime($endDate . ' +1 day'));
- $query->where('dCreateOn', '<', $endDate);
- }
- })
- ->orderBy('nID', 'desc')
- ->get(['nID', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia', 'dCreateOn']);
-
- $headers = [
- ['value' => 'No', 'cell' => 'A1', 'mergeCell' => true, 'mergeToCell' => 'A2'],
- ['value' => 'Kode TC', 'cell' => 'B1', 'mergeCell' => true, 'mergeToCell' => 'B2'],
- ['value' => 'Tanggal', 'cell' => 'C1', 'mergeCell' => true, 'mergeToCell' => 'C2'],
- ['value' => 'Waktu', 'cell' => 'D1', 'mergeCell' => true, 'mergeToCell' => 'D2'],
- ['value' => 'Faskes', 'cell' => 'E1', 'mergeCell' => true, 'mergeToCell' => 'E2'],
- ['value' => 'Nama Dokter', 'cell' => 'F1', 'mergeCell' => true, 'mergeToCell' => 'F2'],
- ['value' => 'Spesialis', 'cell' => 'G1', 'mergeCell' => true, 'mergeToCell' => 'G2'],
- ['value' => 'Chat Via App/Website', 'cell' => 'H1', 'mergeCell' => true, 'mergeToCell' => 'I1'],
- ['value' => 'Pasien', 'cell' => 'H2', 'mergeCell' => false, 'mergeToCell' => ''],
- ['value' => 'Dokter', 'cell' => 'I2', 'mergeCell' => false, 'mergeToCell' => ''],
- ['value' => 'nIDUser', 'cell' => 'J1', 'mergeCell' => true, 'mergeToCell' => 'J2'],
- ['value' => 'Nama Pasien', 'cell' => 'K1', 'mergeCell' => true, 'mergeToCell' => 'K2'],
- ['value' => 'No Telepon Pasien', 'cell' => 'L1', 'mergeCell' => true, 'mergeToCell' => 'L2'],
- ['value' => 'Email Pasien', 'cell' => 'M1', 'mergeCell' => true, 'mergeToCell' => 'M2'],
- ['value' => 'Status', 'cell' => 'N1', 'mergeCell' => true, 'mergeToCell' => 'N2'],
- ['value' => 'Record Type', 'cell' => 'O1', 'mergeCell' => true, 'mergeToCell' => 'O2'],
- ['value' => 'nID Principal', 'cell' => 'P1', 'mergeCell' => true, 'mergeToCell' => 'P2'],
- ['value' => 'Metode Pembayaran', 'cell' => 'Q1', 'mergeCell' => true, 'mergeToCell' => 'Q2'],
- ];
-
- $spreadsheet = new Spreadsheet();
- $sheet = $spreadsheet->getActiveSheet();
-
- foreach ($headers as $header) {
- $sheet->setCellValue($header['cell'], $header['value']);
-
- if ($header['mergeCell'] === true) {
- $sheet->mergeCells($header['cell'] . ':' . $header['mergeToCell']);
- }
-
- $sheet->getStyle($header['cell'])->getFont()->setBold(true);
- $sheet->getStyle($header['cell'])->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
- }
-
- $startFrom = 3;
- foreach ($liveChats as $indexLiveChat => $liveChat) {
- $phone = $liveChat->user->sPhone ?? '-';
- $status = $liveChat->sStatus;
- $nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent
- $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A';
- $fullNameDoctor = '-';
- if ($liveChat->doctor->user !== null) {
- $fullNameDoctor = '';
-
- if ($liveChat->doctor->user->detail !== null) {
- if ($liveChat->doctor->user->detail->sTitlePrefix !== null) {
- $fullNameDoctor .= $liveChat->doctor->user->detail->sTitlePrefix . '. ';
- }
-
- if ($liveChat->doctor->user->full_name !== null) {
- $fullNameDoctor .= $liveChat->doctor->user->full_name . ' ';
- }
-
- if ($liveChat->doctor->user->detail->sTitleSuffix !== null) {
- $fullNameDoctor .= $liveChat->doctor->user->detail->sTitleSuffix;
- }
- }
- }
-
- $recordType = 'P';
- if ($nIDUser){
- $recordType = 'D';
- }
- switch ($status) {
- case 0:
- $statusLivechat = "Request TC";
- break;
- case 1:
- $statusLivechat = "Accepted by Doctor but User not Payment";
- break;
- case 2:
- $statusLivechat = "Payment Success";
- break;
- case 3:
- $statusLivechat = "Decline by Doctor";
- break;
- case 4:
- $statusLivechat = "Payment Expired";
- break;
- default:
- $statusLivechat = "Cancel by Patient";
- }
-
- $sheet->setCellValue('A' . $startFrom, $indexLiveChat + 1);
- $sheet->setCellValue('B' . $startFrom, $liveChat->nID ?? '-');
- $sheet->setCellValue('C' . $startFrom, Carbon::parse($liveChat->dCreateOn)->format('d-m-Y'));
- $sheet->setCellValue('D' . $startFrom, Carbon::parse($liveChat->dCreateOn)->format('H:i:s'));
- // $sheet->setCellValue('D' . $startFrom, Carbon::parse($liveChat->dRequestTime)->format('H:i:s'));
- $sheet->setCellValue('E' . $startFrom, $liveChat->healthCare->sHealthCare ?? '-');
- $sheet->setCellValue('F' . $startFrom, $fullNameDoctor);
- $sheet->setCellValue('G' . $startFrom, $liveChat->doctor->speciality->sSpesialis ?? '-');
- $sheet->setCellValue('H' . $startFrom, $liveChat->sMedia ?? '-');
- $sheet->setCellValue('I' . $startFrom, $liveChat->sMediaDokter ?? '-');
- $sheet->setCellValue('J' . $startFrom, $liveChat->user->nID ?? '-');
- $sheet->setCellValue('K' . $startFrom, $liveChat->user->full_name ?? '-');
- $sheet->setCellValue('L' . $startFrom, preg_replace('/(\d{3})(\d{4})(\d{3})/', '$1$2$3', $phone));
- $sheet->setCellValue('M' . $startFrom, $liveChat->user->sEmail ?? '-');
- $sheet->setCellValue('N' . $startFrom, $statusLivechat);
- $sheet->setCellValue('O' . $startFrom, $recordType);
- $sheet->setCellValue('P' . $startFrom, $nIDUser ?? '-');
- $sheet->setCellValue('Q' . $startFrom, $paymentMethod ?? '-');
- $startFrom++;
- }
-
- foreach (['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K', 'L', 'M', 'O', 'P'] as $header) {
- if ($header === 'A') {
- $spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(35, 'px');
- } elseif ($header === 'H' || $header === 'I') {
- $spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(100, 'px');
- } else {
- $spreadsheet->getActiveSheet()->getColumnDimension($header)->setAutoSize(true);
- }
- }
-
- $spreadsheet->getActiveSheet()->getStyle('A3:A' . $startFrom)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
-
- $sheet->getDefaultRowDimension()->setRowHeight(-1);
- $sheet->setTitle('Live Chat Report');
-
- $writer = new Xlsx($spreadsheet);
- ob_start();
- $writer->save('php://output');
- $content = ob_get_contents();
- ob_end_clean();
-
- $fileName = 'result-' . now()->getPreciseTimestamp(3) . '-livechat-report.xlsx';
- Storage::disk('public')->put('temp/' . $fileName, $content);
-
- $fileUrl = url('storage/temp/' . $fileName);
-
- return Helper::responseJson([
- "file_url" => $fileUrl
- ]);
- }
-}
diff --git a/Modules/Internal/Http/Controllers/Api/PrescriptionController.php b/Modules/Internal/Http/Controllers/Api/PrescriptionController.php
index 7b1ffb0f..75cad7a6 100644
--- a/Modules/Internal/Http/Controllers/Api/PrescriptionController.php
+++ b/Modules/Internal/Http/Controllers/Api/PrescriptionController.php
@@ -29,6 +29,8 @@ use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Validator;
+use Dompdf\Dompdf;
+use Dompdf\Options;
use DB;
class PrescriptionController extends Controller
@@ -247,4 +249,58 @@ class PrescriptionController extends Controller
{
//
}
+
+ public function downloadPrescription($id){
+ $pdf = new Dompdf();
+
+ $options = new Options();
+ $options->set('isHtml5ParserEnabled', true);
+ $options->set('isPhpEnabled', true);
+ $options->set(['isRemoteEnabled' => true]);
+ $pdf->setOptions($options);
+
+ $pdf->setPaper('A4', 'portrait');
+
+
+ $livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare')
+ ->where('nIDAppointment', '!=', null)->where('nIDAppointment', '!=', '')
+ ->where('nID', $id)
+ ->first();
+
+ $prescription = Prescription::where('nIDLivechat', $id)->first();
+ $valid_date = date('d-m-Y', strtotime($prescription->dTanggalResep . ' +3 days'));
+ $prescriptionItem = PrescriptionItem::where('nIDPrescription', $prescription->nID)->get();
+
+ $user = User::where('nID', $livechat->nIDUser)->first();
+ $doctor = Dokter::where('nIDUser', $livechat->nIDDokter)->first();
+
+ $patient = [
+ 'name' => $user->sFirstName. ' '. $user->sMiddleName. ' '. $user->sLastName,
+ 'tgl_lahir' => date('d-m-Y', strtotime($user->dTanggalLahir)),
+ 'kelamin' => $user->nIDJenisKelamin == 1 ? 'M' : 'F',
+ 'umur' => Helper::calculateAge($user->dTanggalLahir)
+ ];
+
+ // Memuat view pdf_view.php ke dalam variabel
+ $data = [
+ 'doctor' => $doctor,
+ 'items' => $prescriptionItem,
+ 'tanggal_resep' => date('d-m-Y', strtotime($prescription->dTanggalResep)),
+ 'pasien' => $patient,
+ 'valid_date' => $valid_date,
+ ];
+ // Halaman 1
+ $html1 = view('pdf.prescription', $data);
+ $htmlCombined = $html1 ;
+
+ $pdf->loadHtml($htmlCombined);
+ $pdf->render();
+
+ $headers = [
+ 'Content-Type' => 'application/pdf',
+ 'Content-Disposition' => 'inline; filename="file.pdf"',
+ ];
+
+ return response($pdf->output(), 200, $headers);
+ }
}
diff --git a/Modules/Internal/Routes/api.php b/Modules/Internal/Routes/api.php
index 93abbc6d..56fc9861 100644
--- a/Modules/Internal/Routes/api.php
+++ b/Modules/Internal/Routes/api.php
@@ -310,6 +310,7 @@ Route::prefix('internal')->group(function () {
Route::get('prescription', [PrescriptionController::class, 'index']);
Route::post('prescription', [PrescriptionController::class, 'store']);
+ Route::get('prescription-download/{id}', [PrescriptionController::class, 'downloadPrescription']);
Route::get('prescription/{id}', [PrescriptionController::class, 'index']);
diff --git a/frontend/dashboard/src/@types/doctor.tsx b/frontend/dashboard/src/@types/doctor.tsx
index d672f44e..4a1dd106 100644
--- a/frontend/dashboard/src/@types/doctor.tsx
+++ b/frontend/dashboard/src/@types/doctor.tsx
@@ -71,7 +71,7 @@ export type Medicine = {
}
export type Appointment = {
- id:number;
+ id:number|undefined;
name:string;
address:string;
birth_date:string;
diff --git a/frontend/dashboard/src/pages/EPrescription/Livechat/Show.tsx b/frontend/dashboard/src/pages/EPrescription/Livechat/Show.tsx
index 3d85a52b..25cb9c15 100644
--- a/frontend/dashboard/src/pages/EPrescription/Livechat/Show.tsx
+++ b/frontend/dashboard/src/pages/EPrescription/Livechat/Show.tsx
@@ -44,6 +44,7 @@ export default function Create() {
diff --git a/frontend/dashboard/src/pages/EPrescription/Livechat/View.tsx b/frontend/dashboard/src/pages/EPrescription/Livechat/View.tsx
index b3f3e4fa..14533ed0 100644
--- a/frontend/dashboard/src/pages/EPrescription/Livechat/View.tsx
+++ b/frontend/dashboard/src/pages/EPrescription/Livechat/View.tsx
@@ -84,6 +84,7 @@ interface FormValuesProps extends Partial {
type Props = {
isEdit: boolean;
+ id: number;
currentAppointment?: Appointment;
};
@@ -97,7 +98,7 @@ const Text = styled(Typography)(({ theme }) => ({
paddingBottom: theme.spacing(3),
}));
-export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
+export default function AppointmentForm({ isEdit, id, currentAppointment }: Props) {
const navigate = useNavigate();
// const [ errors, setErrors ] = useState<{ [key: string]: string }>({});
@@ -139,7 +140,8 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
[currentAppointment]
);
-
+ console.log()
+
const methods = useForm({
// resolver: yupResolver(NewCorporateSchema),
defaultValues,
@@ -159,7 +161,7 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
});
setSelectedIcdOptions(selectedCodes);
setValue('diagnosis', selectedCodes);
- }, [icdOptions, defaultValues]);
+ }, [defaultValues.diagnosis]);
@@ -327,6 +329,20 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
ascent.innerHTML = '';
}
};
+
+ const handleDownloadEPrescription = (id: number) => {
+ axios
+ .get(`prescription-download/${id}`, {
+ responseType: 'blob',
+ })
+ .then((response) => {
+ window.open(URL.createObjectURL(response.data));
+ })
+ .catch((response) => {
+ enqueueSnackbar(response.message, { variant: 'error' });
+ });
+}
+
return (
@@ -510,7 +526,7 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
/>
-
+ {/*
Rumah Sakit
-
+ */}
@@ -634,6 +650,14 @@ export default function AppointmentForm({ isEdit, currentAppointment }: Props) {
))}
+