78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ProntoAtendimento\PedidoExame;
|
|
use App\Models\ProntoAtendimento\PedidoExame\Laudo;
|
|
use App\Services\Service;
|
|
|
|
class LaudoService extends Service
|
|
{
|
|
public function storeFile($pedido, $files, $additionalsParams = [])
|
|
{
|
|
foreach (['pedido_exame_id', 'hash', 'nome'] as $field) {
|
|
|
|
if (array_key_exists($field, $additionalsParams)) {
|
|
|
|
unset($additionalsParams[$field]);
|
|
}
|
|
}
|
|
|
|
$path = storage_path( 'pronto-atendimento'
|
|
. DIRECTORY_SEPARATOR
|
|
. 'laudos'
|
|
. DIRECTORY_SEPARATOR
|
|
. app('config')->get('database.default')
|
|
. DIRECTORY_SEPARATOR
|
|
. $pedido->id
|
|
);
|
|
|
|
if($files)
|
|
{
|
|
foreach($files as $file)
|
|
{
|
|
$data = (new \DateTime)->getTimestamp();
|
|
$extensao = $file->extension();
|
|
$arquivo = encrypt($data) . '.' . $extensao;
|
|
$request['hash'] = $arquivo;
|
|
$request['nome'] = mb_strtoupper($file->getClientOriginalName());
|
|
$file->move($path, $arquivo);
|
|
|
|
Laudo::create(array_merge([
|
|
'pedido_exame_id' => $pedido->id,
|
|
'hash' => $request['hash'],
|
|
'nome' => $request['nome']
|
|
], $additionalsParams));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
return Laudo::findOrFail($id)->delete();
|
|
}
|
|
|
|
public function download($id, string $hash)
|
|
{
|
|
$laudo = Laudo::findOrFail($id);
|
|
|
|
$path = storage_path( 'pronto-atendimento'
|
|
. DIRECTORY_SEPARATOR
|
|
. 'laudos'
|
|
. DIRECTORY_SEPARATOR
|
|
. app('config')->get('database.default')
|
|
. DIRECTORY_SEPARATOR
|
|
. $laudo->pedido_exame_id
|
|
. DIRECTORY_SEPARATOR
|
|
) . $hash;
|
|
|
|
$headers = [
|
|
'Content-Type' => 'application/pdf',
|
|
];
|
|
|
|
return [
|
|
'path' => $path,
|
|
'nome' => $laudo->nome,
|
|
'headers' => $headers
|
|
];
|
|
}
|
|
}
|