diff --git a/Modules/Internal/Http/Controllers/Api/DrugController.php b/Modules/Internal/Http/Controllers/Api/DrugController.php
index 1402699e..6c27a31f 100644
--- a/Modules/Internal/Http/Controllers/Api/DrugController.php
+++ b/Modules/Internal/Http/Controllers/Api/DrugController.php
@@ -6,6 +6,8 @@ use App\Models\Drug;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
+use App\Helpers\Helper;
+use Maatwebsite\Excel\Facades\Excel;
class DrugController extends Controller
{
@@ -15,8 +17,11 @@ class DrugController extends Controller
*/
public function index(Request $request)
{
- $drugs = Drug::withTrashed()->filter($request->toArray())->paginate();
-
+ $drugs = Drug::query()
+ ->filter($request->all())
+ ->orderBy('id', 'DESC')
+ ->paginate(0)
+ ->appends($request->all());
return $drugs;
}
@@ -79,4 +84,110 @@ class DrugController extends Controller
{
//
}
+
+ public function activation(Request $request, $drug_id)
+ {
+ $request->validate([
+ 'active' => 'required',
+ 'reason' => 'required',
+ ]);
+
+ $drug = Drug::findOrFail($drug_id);
+ $drug->active = $request->active;
+ $drug->reason = $request->reason;
+
+ if ($drug->save()) {
+ return response()->json([
+ 'hostpital' => $drug,
+ 'message' => 'Status Updated Successfully'
+ ]);
+ }
+ }
+ public function downloadTemplate()
+ {
+ return Helper::responseJson([
+ 'file_name' => "Template - Drugs.xlsx",
+ "file_url" => url('files/Template - Drugs.xlsx')
+ ]);
+ }
+ public function import(Request $request, $corporate_id)
+ {
+ if ($request->hasFile('file')) {
+ $file = $request->file('file');
+ $data = Excel::toArray([], $file);
+
+ $processedData = $this->processCategoryNames($data);
+
+ $importedRows = 0;
+ $failedRows = [];
+
+ foreach ($processedData as $row) {
+ try {
+ Drug::create(
+ [
+ 'name' => $row['name'],
+ 'code' => $row['code'],
+ 'generic_name' => $row['generic_name'],
+ 'description' => $row['description'],
+ 'mims_class' => $row['mims_class'],
+ 'indications' => $row['indications'],
+ 'atc_code' => $row['atc_code'],
+ 'segmentation' => $row['segmentation'],
+ 'type' => $row['type'],
+ 'dosage' => $row['dosage'],
+ 'remark' => $row['remark'],
+ ]
+ );
+ $importedRows++;
+ } catch (\Exception $e) {
+ $failedRows[] = $row;
+ }
+ }
+
+ $response = [
+ 'message' => 'File uploaded and data saved to database!',
+ 'data' => [
+ 'total_success_row' => $importedRows,
+ 'total_failed_row' => count($failedRows),
+ 'failed_rows' => $failedRows,
+ ],
+ ];
+
+ return response()->json($response);
+ }
+
+ return response()->json(['error' => 'No file uploaded.']);
+ }
+
+ private function processCategoryNames($data)
+ {
+ $header = [];
+ $row = [];
+ for ($i = 1; $i < count($data[0]); $i++) {
+ $row[] = $data[0][$i];
+ $header[] = $data[0][0];
+ }
+
+ $filed = [];
+ foreach ($header[0] as $value)
+ {
+ $modelColumn = strtolower(preg_replace('/\s+/', '_', trim($value)));
+ $modelColumn = str_replace(['*', ' '], '', $modelColumn);
+ if($modelColumn)
+ {
+ $filed[] = $modelColumn;
+ }
+ }
+
+ $result = [];
+ foreach ($row as $subarray) {
+ $trimmedSubarray = [];
+ for ($i = 0; $i < count($filed); $i++) {
+ $trimmedSubarray[$filed[$i]] = $subarray[$i] ? $subarray[$i] : null;
+ }
+
+ $result[] = $trimmedSubarray;
+ }
+ return $result;
+ }
}
diff --git a/Modules/Internal/Routes/api.php b/Modules/Internal/Routes/api.php
index 3485ed3a..b867c0a1 100644
--- a/Modules/Internal/Routes/api.php
+++ b/Modules/Internal/Routes/api.php
@@ -173,6 +173,9 @@ Route::prefix('internal')->group(function () {
Route::put('master/diagnosis/{diagnosis_template_id}/activation', [DiagnosisController::class, 'activation']);
Route::get('master/drugs', [DrugController::class, 'index']);
+ Route::put('master/drugs/{drug_id}/activation', [DrugController::class, 'activation']);
+ Route::get('master/drugs/download-template', [DrugController::class, 'downloadTemplate']);
+ Route::post('master/drugs/{corporate_id}/import', [DrugController::class, 'import']);
Route::get('members', [MemberController::class, 'index']);
diff --git a/app/Models/Drug.php b/app/Models/Drug.php
index ad74b58a..a1fb9655 100644
--- a/app/Models/Drug.php
+++ b/app/Models/Drug.php
@@ -25,7 +25,8 @@ class Drug extends Model
'dosage',
'remark',
'selling_unit_id',
- 'status'
+ 'status',
+ 'active',
];
public function categories()
diff --git a/database/migrations/2023_10_23_114257_add_column_active_to_drugs.php b/database/migrations/2023_10_23_114257_add_column_active_to_drugs.php
new file mode 100644
index 00000000..04b9f3b0
--- /dev/null
+++ b/database/migrations/2023_10_23_114257_add_column_active_to_drugs.php
@@ -0,0 +1,34 @@
+text('reason')->nullable()->after('status');
+ $table->tinyInteger('active')->default(1)->after('reason');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('drugs', function (Blueprint $table) {
+ $table->dropColumn('reason');
+ $table->dropColumn('active');
+ });
+ }
+};
diff --git a/frontend/dashboard/src/@types/corporates.ts b/frontend/dashboard/src/@types/corporates.ts
index 61d35871..ff470d0f 100644
--- a/frontend/dashboard/src/@types/corporates.ts
+++ b/frontend/dashboard/src/@types/corporates.ts
@@ -30,6 +30,7 @@ export type Hospital = {
corporate_id: number;
code: string;
name?: string;
+ active: number;
}
export type Employee = {
diff --git a/frontend/dashboard/src/@types/pharmacy-and-delivery-managements.ts b/frontend/dashboard/src/@types/pharmacy-and-delivery-managements.ts
new file mode 100644
index 00000000..661f4a46
--- /dev/null
+++ b/frontend/dashboard/src/@types/pharmacy-and-delivery-managements.ts
@@ -0,0 +1,8 @@
+export type Drug = {
+ id: number;
+ type: string;
+ code: string;
+ name: string;
+ version:string;
+ active: number;
+}
\ No newline at end of file
diff --git a/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx b/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx
index 90ac94b9..6ecadc09 100644
--- a/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx
+++ b/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx
@@ -42,6 +42,7 @@ const navConfig = [
{
title: 'PHARMACY & DELIVERY MANAGEMENT',
children: [
+ { title: 'Drug', path: '/master/drugs'},
{ title: 'Inventory', path: '/inventory' },
{ title: 'Delivery Services', path: '/delivery' },
],
@@ -53,7 +54,6 @@ const navConfig = [
{ title: 'Corporate', path: '/corporates' },
// { title: 'Corporate Create', path: '/corporates/create' },
{ title: 'Formularium', path: '/master/formularium-template' },
- { title: 'Obat', path: '/master/drugs' },
{ title: 'Master ICD-10 Diagnosis', path: '/master/diagnosis-template' },
{ title: 'Hospitals', path: '/hospitals' },
],
diff --git a/frontend/dashboard/src/pages/Corporates/Hospital/List.tsx b/frontend/dashboard/src/pages/Corporates/Hospital/List.tsx
index 74f4bc94..1ad86b41 100644
--- a/frontend/dashboard/src/pages/Corporates/Hospital/List.tsx
+++ b/frontend/dashboard/src/pages/Corporates/Hospital/List.tsx
@@ -27,7 +27,7 @@ import React, { ChangeEvent, useEffect, useRef, useState } from 'react';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
// components
import axios from '../../../utils/axios';
-import { CorporatePlan } from '../../../@types/corporates';
+import { Hospital } from '../../../@types/corporates';
import { LaravelPaginatedData } from '../../../@types/paginated-data';
import BasePagination from '../../../components/BasePagination';
import TableMoreMenu from '@/components/table/TableMoreMenu';
@@ -40,7 +40,7 @@ import CloseIcon from '@mui/icons-material/Close';
import { enqueueSnackbar } from 'notistack';
import Label from '../../../components/Label';
-export default function PlanList() {
+export default function HospitalList() {
const { corporate_id } = useParams();
const [searchParams, setSearchParams] = useSearchParams();
const navigate = useNavigate();
@@ -80,9 +80,9 @@ export default function PlanList() {
}
// Called on every row to map the data to the columns
- function createData(plan: CorporatePlan): CorporatePlan {
+ function createData(hospital: Hospital): Hospital {
return {
- ...plan,
+ ...hospital,
};
}
diff --git a/frontend/dashboard/src/pages/Corporates/Member/List.tsx b/frontend/dashboard/src/pages/Corporates/Member/List.tsx
index 35e208ca..9b6114ec 100644
--- a/frontend/dashboard/src/pages/Corporates/Member/List.tsx
+++ b/frontend/dashboard/src/pages/Corporates/Member/List.tsx
@@ -61,6 +61,7 @@ import FindInPageOutlinedIcon from '@mui/icons-material/FindInPageOutlined';
import CachedOutlinedIcon from '@mui/icons-material/CachedOutlined';
import { Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
+import Label from '../../../components/Label';
export default function CorporatePlanList({handleSubmitSuccess}) {
const navigate = useNavigate();
@@ -424,12 +425,14 @@ export default function CorporatePlanList({handleSubmitSuccess}) {
}
const [columns, setColumns] = React.useState([
- { id: 'member_id', label: 'Member ID', minWidth: 100, align: 'left', width: '10%' },
- { id: 'effective_date', label: 'Effective Date', minWidth: 100, align: 'left', width: '20%' },
+ { id: 'member_id', label: 'Member ID', minWidth: 100, align: 'left', width: '15%' },
+ { id: 'effective_date', label: 'Effective Date', minWidth: 100, align: 'left', width: '15%' },
{ id: 'name', label: 'Name', minWidth: 100, align: 'left', width: '20%' },
- { id: 'plan_id', label: 'Plan ID', minWidth: 100, align: 'left', width: '10%' },
- { id: 'activation_date', label: 'Activation Date', minWidth: 100, align: 'left', width: '20%' },
- { id: 'termination_date', label: 'Termination Date', minWidth: 100, align: 'left', width: '20%' },
+ { id: 'plan_id', label: 'Plan', minWidth: 100, align: 'left', width: '10%' },
+ { id: 'activation_date', label: 'Activation Date', minWidth: 100, align: 'left', width: '15%' },
+ { id: 'termination_date', label: 'Termination Date', minWidth: 100, align: 'left', width: '15%' },
+ {id: 'status', label: 'Status', minWidth: 100, align: 'left', width: '5%' },
+ {id: 'action', label: '', minWidth: 100, align: 'left', width: '5%' },
]);
// Generate the every row of the table
@@ -489,6 +492,19 @@ export default function CorporatePlanList({handleSubmitSuccess}) {
{row.terminated_date ? row.terminated_date : '-'}
+
+
+ {row.active === 1 ? (
+
+ ) : (
+
+ )}
+
+
diff --git a/frontend/dashboard/src/pages/Master/Drug/Index.tsx b/frontend/dashboard/src/pages/Master/Drug/Index.tsx
index 0bdff569..0e0f9aba 100644
--- a/frontend/dashboard/src/pages/Master/Drug/Index.tsx
+++ b/frontend/dashboard/src/pages/Master/Drug/Index.tsx
@@ -1,16 +1,11 @@
-import { Card, Grid } from "@mui/material";
-import { useParams } from "react-router-dom";
+import { Card } from "@mui/material";
import HeaderBreadcrumbs from "../../../components/HeaderBreadcrumbs";
import Page from "../../../components/Page";
-import useSettings from "../../../hooks/useSettings";
-import List from "./List";
+import List from "./List2";
export default function Drugs() {
- const { themeStretch } = useSettings();
-
- const { corporate_id } = useParams();
const pageTitle = 'Drug';
return (
@@ -20,8 +15,8 @@ export default function Drugs() {
heading={ pageTitle }
links={[
{
- name: 'Master',
- href: '/master',
+ name: 'Pharmacy & Delivery Management',
+ href: '/',
},
{
name: 'Drug',
diff --git a/frontend/dashboard/src/pages/Master/Drug/List.tsx b/frontend/dashboard/src/pages/Master/Drug/List.tsx
index ae0a4abd..95eecc22 100644
--- a/frontend/dashboard/src/pages/Master/Drug/List.tsx
+++ b/frontend/dashboard/src/pages/Master/Drug/List.tsx
@@ -14,6 +14,7 @@ import axios from '../../../utils/axios';
import { LaravelPaginatedData } from '../../../@types/paginated-data';
import { Icd } from '../../../@types/diagnosis';
import BasePagination from '../../../components/BasePagination';
+import { enqueueSnackbar } from 'notistack';
export default function List() {
const { themeStretch } = useSettings();
@@ -42,7 +43,7 @@ export default function List() {
return (
);
}
@@ -109,7 +110,6 @@ export default function List() {
{( !currentImportFileName &&
- {/* kjasndkjandskjasndkjansdkjansd
*/}