modified assests

This commit is contained in:
2026-06-15 11:25:16 +07:00
parent 3f115866d9
commit e96d58dcb4
1218 changed files with 1162 additions and 339502 deletions

View File

@@ -7,7 +7,7 @@ use App\Models\BaseModel;
use App\Models\Comment;
use App\Models\Department;
use App\Models\LabConfigure;
use App\Models\Laboratory;
use App\Models\Organization;
use App\Models\Patient;
use App\Models\Physician;
use App\Models\SampleSource;
@@ -50,9 +50,9 @@ class ShareController extends Controller
public function index($id){
$sample = Sample::with(['patient','invoice'])->where(['id' => $id])->first();
$labSettings = Laboratory::query()->find($sample->lab_id);
$labSettings = Organization::query()->find($sample->organization_id);
$samplePhysician = Physician::query()->where('id', $sample->physician_id)->first();
$labConfigures = $this->laboratoryConfigures::query()->where(['lab_id' => $sample->lab_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get()->toArray();
$labConfigures = $this->laboratoryConfigures::query()->where(['organization_id' => $sample->organization_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get()->toArray();
$preview_form_id = ($labSettings->lab_category_id==0? 1:2);
@@ -126,23 +126,23 @@ class ShareController extends Controller
ifnull(pct.`partner_price`, 0.00) as partner_price,
ts.weight,
ts.is_bold,
ts.lab_id,
ts.organization_id,
tr.test_date,
tr.comment,
sd.sample_descr
FROM samples s
INNER JOIN patients p
ON p.id = s.patient_id AND p.lab_id = s.lab_id
ON p.id = s.patient_id AND p.organization_id = s.organization_id
INNER JOIN test_results tr
ON tr.`sample_id` = s.`id`
AND s.`lab_id` = tr.`lab_id`
AND s.`organization_id` = tr.`organization_id`
INNER JOIN test_samples ts
ON ts.id = tr.`test_sample_id`
and ts.lab_id = tr.lab_id
and ts.organization_id = tr.organization_id
INNER JOIN tests t
ON t.`id` = ts.`test_id`
/*AND t.`lab_id` = ts.`lab_id`*/
/*AND t.`organization_id` = ts.`organization_id`*/
INNER JOIN sample_types st
ON st.`id` = ts.`sample_type_id`
INNER JOIN departments d
@@ -226,7 +226,7 @@ class ShareController extends Controller
'str_comment' => (string) $row->comment,
'is_bold' => (int) $row->is_bold,
'ts' => $row->test_result,
'lab_id' => $row->lab_id,
'organization_id' => $row->organization_id,
'format' => (int)$row->format
);
//dd($testItemArray);
@@ -375,7 +375,7 @@ class ShareController extends Controller
*/
public function startAnonymousSession($hashLabId){
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
$this->base = Organization::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->where('allow_external_request', 1)
->whereRaw('MD5(id)="'.$hashLabId.'"')->first();
$provinces = Province::where('id','<>', 25)->orderBy('name_kh')->get();
@@ -387,8 +387,8 @@ class ShareController extends Controller
$patients = [];
if(!empty(trim($request->term))){
$patients = $this->patientModel::query()
->where(['record_status_id' => 1, 'lab_id' => $labId])
//->whereRaw('MD5(lab_id)="'.$hashLabId.'"')
->where(['record_status_id' => 1, 'organization_id' => $labId])
//->whereRaw('MD5(organization_id)="'.$hashLabId.'"')
->when(!empty(trim($request->term)), function ($patients) use($request){
$patients->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->term)."%'");
//->orWhereRaw("replace(phone_number, ' ','') like '%".str_replace(" ","",$request->term)."%'");
@@ -404,7 +404,7 @@ class ShareController extends Controller
$patients = [];
if(!empty(trim($request->term))){
$patients = $this->patientModel::query()
->where(['record_status_id' => 1, 'lab_id' => $labId])
->where(['record_status_id' => 1, 'organization_id' => $labId])
->when(!empty(trim($request->term)), function ($patients) use($request){
$patients->whereRaw("replace(phone_number, ' ','') like '%".str_replace(" ","",$request->term)."%'");
})->limit(3)->orderBy('phone_number', 'asc')->get();
@@ -438,13 +438,13 @@ class ShareController extends Controller
'name_en'=> $patient_name
]);
$patientNumber = $this->generateAutoId(date('Y-m-d'), $request->short_name, $request->lab_id);
$patientNumber = $this->generateAutoId(date('Y-m-d'), $request->short_name, $request->organization_id);
$requests = $requests->merge(['patient_uuid' => $patientNumber]);
$patient = $this->patientModel::query()->create($requests->all());
DB::commit();
$request->session()->put('anonymous_id', $patient->id);
$request->session()->put('base_lab_id', $patient->lab_id);
$request->session()->put('base_organization_id', $patient->organization_id);
if ($request->session()->has('anonymous_id')) {
return redirect(url('customer/'.$hashLabId.'?request-test'));
}
@@ -459,7 +459,7 @@ class ShareController extends Controller
public function generateAutoId($admissionDate, $labShortName, $labId){
$prefix = date('y',strtotime($admissionDate));
$patientCount = $this->patientModel::query()->where('lab_id', $labId)->whereRaw('year(created_at) ="'. date('Y',strtotime($admissionDate)).'"')->count();
$patientCount = $this->patientModel::query()->where('organization_id', $labId)->whereRaw('year(created_at) ="'. date('Y',strtotime($admissionDate)).'"')->count();
if($labId==34) $patientCount = $patientCount+5; // solve problem when delete patient
return 'P-'.$labShortName.'-'.$prefix.'-'.(str_pad(($patientCount+1),5,'0',STR_PAD_LEFT));
}
@@ -472,7 +472,7 @@ class ShareController extends Controller
$pattern = '/ /i';
$phoneNumber = $request->phone_number;// preg_replace($pattern, '', trim($request->phone_number));
$patient = $this->patientModel::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')
->whereRaw('MD5(organization_id)="'.$hashLabId.'"')
->when(!empty($request->phone_number) && empty($request->patient_id), function($patient) use($request){
$patient->whereRaw("replace(phone_number, ' ','') = '".str_replace(" ","",$request->phone_number)."'");
})->when(!empty($request->patient_id), function($patient) use($request){
@@ -485,7 +485,7 @@ class ShareController extends Controller
}
else{
$request->session()->put('anonymous_id', $patient->id);
$request->session()->put('base_lab_id', $patient->lab_id);
$request->session()->put('base_organization_id', $patient->organization_id);
if ($request->session()->has('anonymous_id')) {
return redirect(url('customer/'.$hashLabId));
}
@@ -495,7 +495,7 @@ class ShareController extends Controller
public function anonymousLogOut(Request $request, $hashLabId){
if ($request->session()->has('anonymous_id')) {
$request->session()->forget('anonymous_id');
$request->session()->forget('base_lab_id');
$request->session()->forget('base_organization_id');
return redirect(url('anonymous/'.$hashLabId));
}
}
@@ -507,16 +507,16 @@ class ShareController extends Controller
}
$patient = $this->patientModel::query()
->where(['id' => $request->session()->get('anonymous_id'), BaseModel::RECORD_STATUS_FIELD => BaseModel::RECORD_STATUS_ACTIVE])
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->first();
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(organization_id)="'.$hashLabId.'"')->first();
$this->base = Organization::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(id)="'.$hashLabId.'"')->first();
$samples = $this->sampleModel::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->where('patient_id', $request->session()->get('anonymous_id'))
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(5);
->whereRaw('MD5(organization_id)="'.$hashLabId.'"')->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(5);
$testGroups = $this->testGroupModel::with(['testGroupDetails'])->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->orderBy('created_at')->get();
->whereRaw('MD5(organization_id)="'.$hashLabId.'"')->orderBy('created_at')->get();
$physicians = $this->physicianModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->orderBy('name_en')->get();
->whereRaw('MD5(organization_id)="'.$hashLabId.'"')->orderBy('name_en')->get();
return view('shared.patient_profile',
[
'patient' => $patient,
@@ -537,8 +537,8 @@ class ShareController extends Controller
return redirect(url('anonymous/'.$hashLabId));
}
$sample = $this->sampleModel::with(['patient','invoice'])->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(lab_id)="'.$hashLabId.'" AND MD5(id)="'.$hashSampleId.'"')->first();
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(organization_id)="'.$hashLabId.'" AND MD5(id)="'.$hashSampleId.'"')->first();
$this->base = Organization::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(id)="'.$hashLabId.'"')->first();
$labConfigures = $this->laboratoryConfigures::query()
->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
@@ -564,20 +564,20 @@ class ShareController extends Controller
DB::beginTransaction();
try{
$sample = $this->sampleModel::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->whereRaw('MD5(lab_id)="'.$hashLabId.'" AND MD5(id)="'.$hashSampleId.'"')->first();
->whereRaw('MD5(organization_id)="'.$hashLabId.'" AND MD5(id)="'.$hashSampleId.'"')->first();
$requestedSample = [];
if(!empty($sample)){
$reSampleArray = array(
'patient_id' => $sample->patient_id,
'sample_number' => $this->generateSampleNumber($sample->lab_id, date('Y-m-d H:i:s')),
'sample_number' => $this->generateSampleNumber($sample->organization_id, date('Y-m-d H:i:s')),
'admission_date' => date('Y-m-d H:i:s'),
'sample_source_id' => $sample->sample_source_id,
'physician_id' => $sample->physician_id,
'requested_date' => date('Y-m-d H:i:s'),
'collected_date' => date('Y-m-d H:i:s'),
'is_accept_request' => 0,
'lab_id' => $sample->lab_id,
'organization_id' => $sample->organization_id,
'created_at' => date('Y-m-d H:i:s'),
'created_by' => $sample->patient_id,
);
@@ -586,7 +586,7 @@ class ShareController extends Controller
$previousTests = $this->testResultModel::query()->where([
BaseModel::RECORD_STATUS_FIELD => BaseModel::RECORD_STATUS_ACTIVE,
'sample_id' => $sample->id,
'lab_id' => $sample->lab_id
'organization_id' => $sample->organization_id
])->get();
if(!empty($requestedSample) && !empty($previousTests)){
$items = [];
@@ -597,7 +597,7 @@ class ShareController extends Controller
'test_result' => NULL,
'created_at' => date('Y-m-d H:i:s'),
'created_by' => $sample->patient_id,
'lab_id' => $previousItem->lab_id
'organization_id' => $previousItem->organization_id
);
}
$this->testResultModel::query()->insert($items);
@@ -612,11 +612,11 @@ class ShareController extends Controller
}
public function generateSampleNumber($labId, $admissionDate){
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
$this->base = Organization::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
->where('id', $labId)->first();
$prefix = date('ymd',strtotime($admissionDate));
$sample = Sample::query();
$sampleCount = $sample->where('lab_id', $labId)->whereRaw('date(admission_date) ="'. date('Y-m-d',strtotime($admissionDate)).'"')->count();
$sampleCount = $sample->where('organization_id', $labId)->whereRaw('date(admission_date) ="'. date('Y-m-d',strtotime($admissionDate)).'"')->count();
return 'S-'.$this->base['short_name'].'-'.$prefix.'-'.(str_pad(($sampleCount+1),3,'0',STR_PAD_LEFT));
}
@@ -624,7 +624,7 @@ class ShareController extends Controller
function getTestItem(Request $request){
try{
$departments = $this->departmentModel::with(['samples','samples.testSamples.test','samples.testSamples.childTest'])
->where(['lab_id' => $request->session()->get('base_lab_id'), BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
->where(['organization_id' => $request->session()->get('base_organization_id'), BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
->orderBy('weight', 'asc')->get();
return response()->json(['success'=> true , 'data' => SampleTestResource::collection($departments)]);
} catch (\Exception $e){
@@ -641,11 +641,11 @@ class ShareController extends Controller
DB::beginTransaction();
try{
$labId = $sampleCreateRequest->session()->get('base_lab_id');
$labId = $sampleCreateRequest->session()->get('base_organization_id');
$patientId = $sampleCreateRequest->session()->get('anonymous_id');
$sampleSourceId = SampleSource::where(['lab_id' => $labId, 'is_default' => 1, 'record_status_id' => 1])->get()->first();
//$physicianId = Physician::where(['lab_id' => $labId, 'is_default' => 1, 'record_status_id' => 1])->get()->first();
$sampleSourceId = SampleSource::where(['organization_id' => $labId, 'is_default' => 1, 'record_status_id' => 1])->get()->first();
//$physicianId = Physician::where(['organization_id' => $labId, 'is_default' => 1, 'record_status_id' => 1])->get()->first();
// create sample first
$sampleRequest = array(
@@ -658,17 +658,17 @@ class ShareController extends Controller
'received_date' => date('Y-m-d H:i:s'),
'collected_date' => date('Y-m-d H:i:s'),
'is_accept_request' => 0,
'lab_id' => $labId,
'organization_id' => $labId,
'created_at' => date('Y-m-d H:i:s'),
'created_by' => $patientId,
);
$requestedSample = $this->sampleModel::query()->create($sampleRequest);
//$this->sampleDetailModel::query()->where(['sample_id' => $requestedSample->id, 'lab_id' => $labId])->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
//$this->sampleDetailModel::query()->where(['sample_id' => $requestedSample->id, 'organization_id' => $labId])->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
if(!empty($requestedSample)) {
if (!empty($sampleCreateRequest->sample_tests)) {
/*$this->testResultModel::query()->where(['sample_id' => $requestedSample->id, 'lab_id' => $labId])
/*$this->testResultModel::query()->where(['sample_id' => $requestedSample->id, 'organization_id' => $labId])
->whereNotIn('test_sample_id', $sampleCreateRequest->sample_tests)
->delete();*/
foreach ($sampleCreateRequest->sample_tests as $test) {
@@ -677,12 +677,12 @@ class ShareController extends Controller
'test_sample_id' => $test,
'created_at' => date('Y-m-d H:i:s'),
'created_by' => $patientId,
'lab_id' => $labId,
'organization_id' => $labId,
]);
}
}
/*else {
$this->testResultModel::query()->where(['sample_id' => $sampleCreateRequest->sample_id, 'lab_id' => $this->baseLabId])->delete();
$this->testResultModel::query()->where(['sample_id' => $sampleCreateRequest->sample_id, 'organization_id' => $this->baseOrganizationId])->delete();
}*/
}
@@ -697,7 +697,7 @@ class ShareController extends Controller
public function getTestGroup($id, $labId){
try{
$testGroupItems = $this->testGroupDetailModel::query()->where(['test_group_id' => $id, 'lab_id' => $labId, 'record_status_id'=> 1])->get()->pluck('test_sample_id')->toArray();
$testGroupItems = $this->testGroupDetailModel::query()->where(['test_group_id' => $id, 'organization_id' => $labId, 'record_status_id'=> 1])->get()->pluck('test_sample_id')->toArray();
return response()->json(['success' => true, 'data' => $testGroupItems]);
} catch (\Exception $e)
{