Files
streamline-emr/docker/streamline-src/app/Console/Commands/ImportCsvPriceListsCommand.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

160 lines
5.6 KiB
PHP

<?php
namespace Streamline\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ImportCsvPriceListsCommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:price_list {id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Import items price lists';
/**
* 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));
$data_count = count($data);
$counter = 0;
$price_list_category = "";
foreach($data as $item) {
$split_item = explode(',', $item);
$item_id = 0;
// check if this is the first row and get ids
if ($counter == 0) {
$category_id_arr = [];
for ($i = 1; $i < count($split_item); $i++){
$category_id = get_name(get_name(trim($split_item[$i]), 'name', 'id', 'patient_categories'),
'patient_category_id', 'id', 'price_list_categories');
$category_id_arr[] = $category_id != 'N/A' ? $category_id : 0;
}
$price_list_category = implode(",", $category_id_arr);
$counter++;
continue;
} else {
$category_price = [];
// get the item id
if ($record->tag_id == 3) {
$item_id = get_name($split_item[0], 'name', 'id', 'drugs');
} else if ($record->tag_id == 2) {
$item_id = get_name($split_item[0], 'name', 'id', 'investigations');
} else if ($record->tag_id == 4) {
$item_id = get_name($split_item[0], 'name', 'id', 'procedures');
} else if ($record->tag_id == 5) {
$item_id = get_name($split_item[0], 'name', 'id', 'sundries');
} else if ($record->tag_id == 6) {
$item_id = get_name($split_item[0], 'name', 'id', 'services');
}
if (!is_numeric($item_id)) {
continue;
}
for ($i = 1; $i < count($split_item); $i++){
try {
// catch non numeric error for some cases
$category_price[] = +trim($split_item[$i]);
} catch (\Exception $exception) {
$category_price[] = 0;
}
}
$price_list_price = implode(",", $category_price);
}
if ($record->tag_id == 3) {
try {
DB::table('drugs')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 2) {
try {
DB::table('investigations')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 4) {
try {
DB::table('procedures')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 5) {
try {
DB::table('sundries')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"updated_at" => now()
]);
} catch (\Exception $exception) {}
} else if ($record->tag_id == 6) {
try {
DB::table('services')->where('id', $item_id)->update([
"price_list_category" => $price_list_category,
"price_list_price" => $price_list_price,
"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
]);
}
}
}