Drug
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Models\Drug;
|
|||||||
use Illuminate\Contracts\Support\Renderable;
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
class DrugController extends Controller
|
class DrugController extends Controller
|
||||||
{
|
{
|
||||||
@@ -15,8 +17,11 @@ class DrugController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,9 @@ Route::prefix('internal')->group(function () {
|
|||||||
Route::put('master/diagnosis/{diagnosis_template_id}/activation', [DiagnosisController::class, 'activation']);
|
Route::put('master/diagnosis/{diagnosis_template_id}/activation', [DiagnosisController::class, 'activation']);
|
||||||
|
|
||||||
Route::get('master/drugs', [DrugController::class, 'index']);
|
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']);
|
Route::get('members', [MemberController::class, 'index']);
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ class Drug extends Model
|
|||||||
'dosage',
|
'dosage',
|
||||||
'remark',
|
'remark',
|
||||||
'selling_unit_id',
|
'selling_unit_id',
|
||||||
'status'
|
'status',
|
||||||
|
'active',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function categories()
|
public function categories()
|
||||||
|
|||||||
@@ -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::table('drugs', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -30,6 +30,7 @@ export type Hospital = {
|
|||||||
corporate_id: number;
|
corporate_id: number;
|
||||||
code: string;
|
code: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
|
active: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Employee = {
|
export type Employee = {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export type Drug = {
|
||||||
|
id: number;
|
||||||
|
type: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
version:string;
|
||||||
|
active: number;
|
||||||
|
}
|
||||||
@@ -42,6 +42,7 @@ const navConfig = [
|
|||||||
{
|
{
|
||||||
title: 'PHARMACY & DELIVERY MANAGEMENT',
|
title: 'PHARMACY & DELIVERY MANAGEMENT',
|
||||||
children: [
|
children: [
|
||||||
|
{ title: 'Drug', path: '/master/drugs'},
|
||||||
{ title: 'Inventory', path: '/inventory' },
|
{ title: 'Inventory', path: '/inventory' },
|
||||||
{ title: 'Delivery Services', path: '/delivery' },
|
{ title: 'Delivery Services', path: '/delivery' },
|
||||||
],
|
],
|
||||||
@@ -53,7 +54,6 @@ const navConfig = [
|
|||||||
{ title: 'Corporate', path: '/corporates' },
|
{ title: 'Corporate', path: '/corporates' },
|
||||||
// { title: 'Corporate Create', path: '/corporates/create' },
|
// { title: 'Corporate Create', path: '/corporates/create' },
|
||||||
{ title: 'Formularium', path: '/master/formularium-template' },
|
{ title: 'Formularium', path: '/master/formularium-template' },
|
||||||
{ title: 'Obat', path: '/master/drugs' },
|
|
||||||
{ title: 'Master ICD-10 Diagnosis', path: '/master/diagnosis-template' },
|
{ title: 'Master ICD-10 Diagnosis', path: '/master/diagnosis-template' },
|
||||||
{ title: 'Hospitals', path: '/hospitals' },
|
{ title: 'Hospitals', path: '/hospitals' },
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import React, { ChangeEvent, useEffect, useRef, useState } from 'react';
|
|||||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||||
// components
|
// components
|
||||||
import axios from '../../../utils/axios';
|
import axios from '../../../utils/axios';
|
||||||
import { CorporatePlan } from '../../../@types/corporates';
|
import { Hospital } from '../../../@types/corporates';
|
||||||
import { LaravelPaginatedData } from '../../../@types/paginated-data';
|
import { LaravelPaginatedData } from '../../../@types/paginated-data';
|
||||||
import BasePagination from '../../../components/BasePagination';
|
import BasePagination from '../../../components/BasePagination';
|
||||||
import TableMoreMenu from '@/components/table/TableMoreMenu';
|
import TableMoreMenu from '@/components/table/TableMoreMenu';
|
||||||
@@ -40,7 +40,7 @@ import CloseIcon from '@mui/icons-material/Close';
|
|||||||
import { enqueueSnackbar } from 'notistack';
|
import { enqueueSnackbar } from 'notistack';
|
||||||
import Label from '../../../components/Label';
|
import Label from '../../../components/Label';
|
||||||
|
|
||||||
export default function PlanList() {
|
export default function HospitalList() {
|
||||||
const { corporate_id } = useParams();
|
const { corporate_id } = useParams();
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -80,9 +80,9 @@ export default function PlanList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Called on every row to map the data to the columns
|
// Called on every row to map the data to the columns
|
||||||
function createData(plan: CorporatePlan): CorporatePlan {
|
function createData(hospital: Hospital): Hospital {
|
||||||
return {
|
return {
|
||||||
...plan,
|
...hospital,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ import FindInPageOutlinedIcon from '@mui/icons-material/FindInPageOutlined';
|
|||||||
import CachedOutlinedIcon from '@mui/icons-material/CachedOutlined';
|
import CachedOutlinedIcon from '@mui/icons-material/CachedOutlined';
|
||||||
import { Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
|
import { Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material';
|
||||||
import CloseIcon from '@mui/icons-material/Close';
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
|
import Label from '../../../components/Label';
|
||||||
|
|
||||||
export default function CorporatePlanList({handleSubmitSuccess}) {
|
export default function CorporatePlanList({handleSubmitSuccess}) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -424,12 +425,14 @@ export default function CorporatePlanList({handleSubmitSuccess}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [columns, setColumns] = React.useState([
|
const [columns, setColumns] = React.useState([
|
||||||
{ id: 'member_id', label: 'Member ID', minWidth: 100, align: 'left', width: '10%' },
|
{ id: 'member_id', label: 'Member ID', minWidth: 100, align: 'left', width: '15%' },
|
||||||
{ id: 'effective_date', label: 'Effective Date', minWidth: 100, align: 'left', width: '20%' },
|
{ id: 'effective_date', label: 'Effective Date', minWidth: 100, align: 'left', width: '15%' },
|
||||||
{ id: 'name', label: 'Name', minWidth: 100, align: 'left', width: '20%' },
|
{ id: 'name', label: 'Name', minWidth: 100, align: 'left', width: '20%' },
|
||||||
{ id: 'plan_id', label: 'Plan ID', minWidth: 100, align: 'left', width: '10%' },
|
{ id: 'plan_id', label: 'Plan', minWidth: 100, align: 'left', width: '10%' },
|
||||||
{ id: 'activation_date', label: 'Activation Date', minWidth: 100, align: 'left', width: '20%' },
|
{ id: 'activation_date', label: 'Activation Date', minWidth: 100, align: 'left', width: '15%' },
|
||||||
{ id: 'termination_date', label: 'Termination Date', minWidth: 100, align: 'left', width: '20%' },
|
{ 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
|
// Generate the every row of the table
|
||||||
@@ -489,6 +492,19 @@ export default function CorporatePlanList({handleSubmitSuccess}) {
|
|||||||
<TableCell align="left">
|
<TableCell align="left">
|
||||||
<Typography variant='body2'>{row.terminated_date ? row.terminated_date : '-'}</Typography>
|
<Typography variant='body2'>{row.terminated_date ? row.terminated_date : '-'}</Typography>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
<TableCell align="left">
|
||||||
|
<Typography variant='body2'>
|
||||||
|
{row.active === 1 ? (
|
||||||
|
<Label color='success' >
|
||||||
|
Active
|
||||||
|
</Label>
|
||||||
|
) : (
|
||||||
|
<Label color='error'>
|
||||||
|
Inactive
|
||||||
|
</Label>
|
||||||
|
)}
|
||||||
|
</Typography>
|
||||||
|
</TableCell>
|
||||||
<TableCell align='left'>
|
<TableCell align='left'>
|
||||||
<TableMoreMenu actions={
|
<TableMoreMenu actions={
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
import { Card, Grid } from "@mui/material";
|
import { Card } from "@mui/material";
|
||||||
import { useParams } from "react-router-dom";
|
|
||||||
import HeaderBreadcrumbs from "../../../components/HeaderBreadcrumbs";
|
import HeaderBreadcrumbs from "../../../components/HeaderBreadcrumbs";
|
||||||
import Page from "../../../components/Page";
|
import Page from "../../../components/Page";
|
||||||
import useSettings from "../../../hooks/useSettings";
|
import List from "./List2";
|
||||||
import List from "./List";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function Drugs() {
|
export default function Drugs() {
|
||||||
const { themeStretch } = useSettings();
|
|
||||||
|
|
||||||
const { corporate_id } = useParams();
|
|
||||||
|
|
||||||
const pageTitle = 'Drug';
|
const pageTitle = 'Drug';
|
||||||
return (
|
return (
|
||||||
@@ -20,8 +15,8 @@ export default function Drugs() {
|
|||||||
heading={ pageTitle }
|
heading={ pageTitle }
|
||||||
links={[
|
links={[
|
||||||
{
|
{
|
||||||
name: 'Master',
|
name: 'Pharmacy & Delivery Management',
|
||||||
href: '/master',
|
href: '/',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Drug',
|
name: 'Drug',
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import axios from '../../../utils/axios';
|
|||||||
import { LaravelPaginatedData } from '../../../@types/paginated-data';
|
import { LaravelPaginatedData } from '../../../@types/paginated-data';
|
||||||
import { Icd } from '../../../@types/diagnosis';
|
import { Icd } from '../../../@types/diagnosis';
|
||||||
import BasePagination from '../../../components/BasePagination';
|
import BasePagination from '../../../components/BasePagination';
|
||||||
|
import { enqueueSnackbar } from 'notistack';
|
||||||
|
|
||||||
export default function List() {
|
export default function List() {
|
||||||
const { themeStretch } = useSettings();
|
const { themeStretch } = useSettings();
|
||||||
@@ -42,7 +43,7 @@ export default function List() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSearchSubmit} style={{ width: '100%' }}>
|
<form onSubmit={handleSearchSubmit} style={{ width: '100%' }}>
|
||||||
<TextField id="search-input" ref={searchInput} label="Search" variant="outlined" fullWidth onChange={handleSearchChange} value={searchText}/>
|
<TextField id="search-input" ref={searchInput} label="Search Code or Name" variant="outlined" fullWidth onChange={handleSearchChange} value={searchText}/>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -109,7 +110,6 @@ export default function List() {
|
|||||||
<input type='file' id='file' ref={importForm} style={{ display: 'none' }} onChange={handleImportChange} accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain" />
|
<input type='file' id='file' ref={importForm} style={{ display: 'none' }} onChange={handleImportChange} accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/plain" />
|
||||||
{( !currentImportFileName && <Stack direction={'row'} spacing={2} sx={{ p: 2 }}>
|
{( !currentImportFileName && <Stack direction={'row'} spacing={2} sx={{ p: 2 }}>
|
||||||
<SearchInput onSearch={applyFilter}/>
|
<SearchInput onSearch={applyFilter}/>
|
||||||
{/* <h1>kjasndkjandskjasndkjansdkjansd</h1> */}
|
|
||||||
<Button
|
<Button
|
||||||
id="import-button"
|
id="import-button"
|
||||||
variant='outlined'
|
variant='outlined'
|
||||||
|
|||||||
BIN
public/files/Template - Drugs.xlsx
Normal file
BIN
public/files/Template - Drugs.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user