This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user