Files
streamline-emr/docker/streamline-src/app/Console/Commands/ImportCsvItemsCommand.php
T
alec.turner a424394109 Build modified streamline images
The official image from streamline does not currently work for the arm64
platform. As a temporary measure, the source code and docker build scripts
have been lifted from the official images and are used to build locally.

Some additional modifications are made to reduce overall image size, these
are documented in docker/README.md
2024-03-10 16:17:50 -07:00

145 lines
5.4 KiB
PHP
Executable File

<?php
namespace Streamline\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ImportCsvItemsCommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:csv {id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$id = $this->argument('id');
$record = DB::table('csv_imports_processes')->where('id', $id)->first();
$data = file(base_path('public/' . $record->csv_path));
$account_id = $record->account_id;
$inventory_account = $record->inventory_account;
$cost_of_goods_account = $record->cost_of_goods_account;
$data_count = count($data);
$counter = 0;
foreach($data as $item) {
$split_item = explode(',', $item);
if ($record->tag_id == 3) {
try {
DB::table('drugs')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"cost_price" => str_replace('"', '', $split_item[2]),
"non_insured_price" => str_replace('"', '', $split_item[3]),
"account_id" => $account_id,
"inventory_account" => $inventory_account,
"cost_of_goods_account" => $cost_of_goods_account,
"opening_cost_price" => str_replace('"', '', $split_item[2]),
"category_id" => 1,
"pack" => 1,
"strength" => $split_item[6],
"form_id" => $split_item[5],
"unit_id" => $split_item[4],
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 2) {
try {
DB::table('investigations')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"non_insured_price" => str_replace('"', '', $split_item[2]),
"category" => 2,
"account_id" => $account_id,
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 4) {
try {
DB::table('procedures')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"non_insured_price" => str_replace('"', '', $split_item[2]),
"category_id" => 1,
"account_id" => $account_id,
"created_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 5) {
try {
DB::table('sundries')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"cost_price" => str_replace('"', '', $split_item[2]),
"non_insured_price" => str_replace('"', '', $split_item[3]),
"account_id" => $account_id,
"inventory_account" => $inventory_account,
"cost_of_goods_account" => $cost_of_goods_account,
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 6) {
try {
DB::table('services')->insert([
"code" => str_replace('"', '', $split_item[0]),
"name" => str_replace('"', '', $split_item[1]),
"non_insured_price" => str_replace('"', '', $split_item[2]),
"account_id" => $account_id,
"created_at" => now(),
"updated_at" => now()
]);
} catch (\Exception $exception) {}
}
$counter++;
$percentage = round((($counter / $data_count) * 100));
$is_run_complete = 0;
if ($counter == $data_count) {
$is_run_complete = 1;
} elseif ($percentage == 100) {
// because of the round(), 100% is reached before completion
$percentage = 99;
}
DB::table('csv_imports_processes')
->where('id', $id)
->update([
"records_completed" => $percentage,
"is_complete" => $is_run_complete
]);
}
}
}