This commit is contained in:
ivan-sim
2023-10-24 16:10:47 +07:00
parent 33d3bdab37
commit 134cdb072d
12 changed files with 193 additions and 24 deletions

View File

@@ -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;
}
}

View File

@@ -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']);

View File

@@ -25,7 +25,8 @@ class Drug extends Model
'dosage',
'remark',
'selling_unit_id',
'status'
'status',
'active',
];
public function categories()

View File

@@ -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');
});
}
};

View File

@@ -30,6 +30,7 @@ export type Hospital = {
corporate_id: number;
code: string;
name?: string;
active: number;
}
export type Employee = {

View File

@@ -0,0 +1,8 @@
export type Drug = {
id: number;
type: string;
code: string;
name: string;
version:string;
active: number;
}

View File

@@ -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' },
],

View File

@@ -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,
};
}

View File

@@ -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}) {
<TableCell align="left">
<Typography variant='body2'>{row.terminated_date ? row.terminated_date : '-'}</Typography>
</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'>
<TableMoreMenu actions={
<>

View File

@@ -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',

View File

@@ -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 (
<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>
);
}
@@ -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" />
{( !currentImportFileName && <Stack direction={'row'} spacing={2} sx={{ p: 2 }}>
<SearchInput onSearch={applyFilter}/>
{/* <h1>kjasndkjandskjasndkjansdkjansd</h1> */}
<Button
id="import-button"
variant='outlined'

Binary file not shown.