Update Formularium

This commit is contained in:
2022-08-15 12:42:49 +07:00
parent 8319331d26
commit a3b53ea334
65 changed files with 3218 additions and 52 deletions

View File

@@ -59,9 +59,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -25,9 +25,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -25,9 +25,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -28,9 +28,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -32,9 +32,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -24,9 +24,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
$table->index(['policy_id', 'member_id']);
});

View File

@@ -24,9 +24,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
$table->index(['member_id', 'plan_id']);
});

View File

@@ -25,9 +25,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -23,9 +23,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -22,9 +22,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -22,9 +22,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
$table->index(['corporate_id', 'service_code']);
});

View File

@@ -22,9 +22,9 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}

View File

@@ -0,0 +1,52 @@
<?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('drugs', function (Blueprint $table) {
$table->id();
$table->string('code')->index();
$table->string('name')->index();
$table->string('generic_name')->nullable()->index();
$table->foreignId('unit_id')->nullable();
$table->foreignId('selling_unit_id')->index()->nullable();
$table->text('description')->nullable();
$table->foreignId('brand_id')->nullable();
$table->string('mims_class')->nullable();
$table->text('indications')->nullable();
$table->string('atc_code')->nullable()->index();
$table->string('segmentation')->nullable();
$table->string('type')->nullable();
$table->string('dosage')->nullable();
$table->text('remark')->nullable();
$table->string('status')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('drugs');
}
};

View File

@@ -0,0 +1,37 @@
<?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('brands', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('brands');
}
};

View File

@@ -0,0 +1,41 @@
<?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('categories', function (Blueprint $table) {
$table->id();
$table->foreignId('parent_id')->index()->nullable();
$table->string('code')->index()->nullable();
$table->string('name');
$table->string('type')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
};

View File

@@ -0,0 +1,39 @@
<?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('drug_categories', function (Blueprint $table) {
$table->id();
$table->foreignId('drug_id');
$table->foreignId('category_id');
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('drug_categories');
}
};

View File

@@ -0,0 +1,42 @@
<?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('organizations', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('type')->nullable();
$table->string('status')->nullable()->default('active');
$table->text('description')->nullable();
$table->foreignId('part_of')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('organizations');
}
};

View File

@@ -0,0 +1,41 @@
<?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('drug_compositions', function (Blueprint $table) {
$table->id();
$table->foreignId('drug_id');
$table->foreignId('ingredient_id');
$table->boolean('active')->default(true);
$table->string('strength')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('drug_compositions');
}
};

View File

@@ -0,0 +1,39 @@
<?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('drug_atcs', function (Blueprint $table) {
$table->id();
$table->string('code')->index();
$table->string('name')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('drug_atcs');
}
};

View File

@@ -0,0 +1,45 @@
<?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('identifiers', function (Blueprint $table) {
$table->id();
$table->morphs('identifiable');
$table->string('use')->nullable();
$table->string('type')->nullable();
$table->string('system')->nullable();
$table->string('value')->nullable();
$table->date('period_start')->nullable();
$table->date('period_end')->nullable();
$table->string('assigner')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('identifiers');
}
};

View File

@@ -0,0 +1,40 @@
<?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('ingredients', function (Blueprint $table) {
$table->id();
// $table->foreignId('drug_id');
$table->text('substance');
$table->string('snomed_code')->index()->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ingredients');
}
};

View File

@@ -0,0 +1,39 @@
<?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('drug_manufacturers', function (Blueprint $table) {
$table->id();
$table->foreignId('drug_id');
$table->foreignId('organization_id');
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('drug_manufacturers');
}
};

View File

@@ -0,0 +1,39 @@
<?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('units', function (Blueprint $table) {
$table->id();
$table->string('name')->index();
$table->string('metrics')->index()->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('units');
}
};

View File

@@ -0,0 +1,38 @@
<?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('formulariums', function (Blueprint $table) {
$table->id();
$table->string('code')->index();
$table->string('name')->index();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('formulariums');
}
};

View File

@@ -0,0 +1,38 @@
<?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('formularium_items', function (Blueprint $table) {
$table->id();
$table->foreignId('formularium_id');
$table->foreignId('item_id');
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('formularium_items');
}
};

View File

@@ -0,0 +1,39 @@
<?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('corporate_formulariums', function (Blueprint $table) {
$table->id();
$table->foreignId('corporate_id');
$table->foreignId('formularium_id');
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable();
$table->foreignId('updated_by')->nullable();
$table->foreignId('deleted_by')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('corporate_formulariums');
}
};

View File

@@ -0,0 +1,181 @@
<?php
namespace Database\Seeders;
use App\Models\Brand;
use App\Models\Category;
use App\Models\Drug;
use App\Models\DrugCategories;
use App\Models\DrugCategory;
use App\Models\DrugComposition;
use App\Models\DrugUnit;
use App\Models\Ingredient;
use App\Models\Organization;
use App\Models\Unit;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DrugSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$file_path = resource_path('files/daftar_masteritem_ccp_14-06-2022.xlsx');
$reader = ReaderEntityFactory::createReaderFromFile($file_path);
$reader->open($file_path);
$chunks = [];
$time = now();
$isData = false;
$cell_map = [ // Urutan kolom di excel
'no',
'code',
'name',
'group',
'kategori',
'satuan',
'nama_cetak',
'golongan',
'sub_golongan',
'komposisi',
'sediaan',
'brand',
'strength',
'satuan_strength',
'pabrikan',
'jenis',
'otc',
'resep',
'obat_terlarang',
'pemakaian',
'essential',
'live_saving'
];
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $index => $row) {
if ($index >= 6) {
$row_data = [];
foreach ($row->getCells() as $cell_index => $cell) {
$row_data[$cell_map[$cell_index]] = $cell->getValue();
}
$brand = !empty($row_data['golongan']) ? Brand::firstOrCreate([
'name' => $row_data['brand']
], [
'name' => $row_data['brand']
]) : null;
$manufacturer = Organization::firstOrCreate([
'name' => $row_data['pabrikan']
], [
'name' => $row_data['pabrikan'],
'type' => 'manufacturer'
]);
if (in_array($row_data['golongan'], ['VITAMINS & MINERALS', 'NUTRITIONS'])) {
$type = 'vitamin';
} else {
$type = 'drug';
}
if (!empty($row_data['komposisi'])) {
$ingredient = Ingredient::firstOrCreate([
'substance' => $row_data['komposisi']
], [
'substance' => $row_data['komposisi']
]);
} else {
$ingredient = null;
}
if (!empty($row_data['sediaan'])) {
$sediaan = Unit::firstOrCreate([
'name' => $row_data['sediaan']
], [
'name' => $row_data['sediaan']
]);
} else {
$sediaan = null;
}
$golongan = !empty($row_data['golongan']) ? Category::firstOrCreate([
'name' => $row_data['golongan']
], [
'name' => $row_data['golongan']
]) : null;
$sub_golongan = !empty($row_data['sub_golongan']) ? Category::firstOrCreate([
'name' => $row_data['sub_golongan']
], [
'name' => $row_data['sub_golongan']
]) : null;
$new_drug_data = [
'name' => $row_data['name'],
'generic_name' => $row_data['nama_cetak'],
'code' => $row_data['code'],
'description' => null,
'brand_id' => $brand->id ?? null,
// 'manufacturer_id' => $manufacturer->id ?? null,
'mims_class' => null,
'indications' => null,
'atc_code' => null,
'segmentation' => null,
'type' => $type,
'dosage' => '',
'remark' => '',
'selling_unit_id' => $sediaan->id ?? null,
'status' => 'active',
'unit_id' => $sediaan->id ?? null,
];
$drug = Drug::create($new_drug_data);
$drug->identifiers()->create([
'use' => 'usual',
'type' => 'CCP',
'value' => $row_data['code'],
]);
if ($ingredient) {
DrugComposition::create([
'drug_id' => $drug->id,
'ingredient_id' => $ingredient->id,
]);
}
if ($golongan) {
DrugCategory::create([
'drug_id' => $drug->id,
'category_id' => $golongan->id,
]);
}
if ($sub_golongan) {
DrugCategory::create([
'drug_id' => $drug->id,
'category_id' => $sub_golongan->id,
]);
}
if ($manufacturer) {
$drug->manufacturers()->attach($manufacturer->id);
}
// $chunks[] = $row_data;
}
// if ($chunks && count($chunks) == 1000) {
// Icd::insert($chunks);
// $chunks = [];
// }
}
}
// if ($chunks && count($chunks) > 0) {
// Icd::insert($chunks);
// $chunks = [];
// }
}
}