This commit is contained in:
Dr Masroor Ehsan 2024-12-31 08:33:28 +06:00
parent 7bd8f2277b
commit 6ba22397a4

View File

@ -7,6 +7,7 @@
use App\Models\StudyDetails;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
final class StudyImporter
{
@ -100,7 +101,7 @@ private function prepareData(mixed $orthanc_src): array
'institution_name' => $inst_name,
'institute_id' => $inst_id,
'patient_uid' => $orthanc_src['ParentPatient'],
'patient_uuid' => strtolower($orthanc_src['ParentPatient']),
'patient_id' => data_get($orthanc_src, 'PatientMainDicomTags.PatientID'),
'patient_name' => data_get($orthanc_src, 'PatientMainDicomTags.PatientName'),
'patient_sex' => data_get($orthanc_src, 'PatientMainDicomTags.PatientSex'),
@ -120,7 +121,7 @@ private function prepareData(mixed $orthanc_src): array
'disk_size' => data_get($orthanc_src, 'Statistics.DiskSize'),
];
if ((bool) $orthanc_src['IsStable']) {
if ((bool) data_get($orthanc_src, 'IsStable', false)) {
$study['study_status'] = StudyLevelStatus::StudyArrived->value;
} else {
$study['study_status'] = StudyLevelStatus::Pending->value;
@ -128,23 +129,46 @@ private function prepareData(mixed $orthanc_src): array
$dob = data_get($orthanc_src, 'PatientMainDicomTags.PatientBirthDate');
if (filled($dob)) {
$study['patient_birthdate'] = Carbon::parse($dob);
try {
$study['patient_birthdate'] = Carbon::parse($dob);
} catch (\Exception) {
Log::error('Failed to parse PatientMainDicomTags.PatientBirthDate: {dob}', ['dob' => $dob]);
}
}
$descr = data_get($orthanc_src, 'MainDicomTags.StudyDescription');
if (blank($descr)) {
$descr = data_get($orthanc_src, 'RequestedTags.AcquisitionDeviceProcessingDescription');
}
if (blank($descr)) {
$descr = data_get($orthanc_src, 'MainDicomTags.AcquisitionDeviceProcessingDescription');
}
$this->setValue($study, 'study_description', trim($descr));
$properties = [
'software_versions' => data_get($study, 'RequestedTags.SoftwareVersions'),
'station_name' => data_get($study, 'RequestedTags.StationName'),
'operators_name' => data_get($study, 'RequestedTags.OperatorsName'),
'manufacturer' => data_get($study, 'RequestedTags.Manufacturer'),
'manufacturer_model_name' => data_get($study, 'RequestedTags.ManufacturerModelName'),
'other_patient_names' => data_get($orthanc_src, 'RequestedTags.OtherPatientNames'),
'other_patient_ids' => data_get($orthanc_src, 'RequestedTags.OtherPatientIDs'),
'software_versions' => data_get($orthanc_src, 'RequestedTags.SoftwareVersions'),
'station_name' => data_get($orthanc_src, 'RequestedTags.StationName'),
'operators_name' => data_get($orthanc_src, 'RequestedTags.OperatorsName'),
'manufacturer' => data_get($orthanc_src, 'RequestedTags.Manufacturer'),
'manufacturer_model_name' => data_get($orthanc_src, 'RequestedTags.ManufacturerModelName'),
'acquisition_date' => DicomUtils::dateTimeToCarbon(data_get($orthanc_src, 'RequestedTags.AcquisitionDate'), data_get($orthanc_src, 'RequestedTags.AcquisitionTime')),
];
$properties = array_purge($properties);
if (empty($properties)) {
$properties = [
'other_patient_names' => data_get($orthanc_src, 'MainDicomTags.OtherPatientNames'),
'other_patient_ids' => data_get($orthanc_src, 'MainDicomTags.OtherPatientIDs'),
'software_versions' => data_get($orthanc_src, 'MainDicomTags.SoftwareVersions'),
'station_name' => data_get($orthanc_src, 'MainDicomTags.StationName'),
'operators_name' => data_get($orthanc_src, 'MainDicomTags.OperatorsName'),
'manufacturer' => data_get($orthanc_src, 'MainDicomTags.Manufacturer'),
'manufacturer_model_name' => data_get($orthanc_src, 'MainDicomTags.ManufacturerModelName'),
'acquisition_date' => DicomUtils::dateTimeToCarbon(data_get($orthanc_src, 'MainDicomTags.AcquisitionDate'), data_get($orthanc_src, 'MainDicomTags.AcquisitionTime')),
];
$properties = array_purge($properties);
}
$series = [];
foreach (data_get($orthanc_src, 'Series', []) as $ser) {
@ -153,6 +177,7 @@ private function prepareData(mixed $orthanc_src): array
'series_instance_uid' => data_get($ser, 'MainDicomTags.SeriesInstanceUID'),
'series_date' => DicomUtils::dateTimeToCarbon($ser['MainDicomTags']['SeriesDate'], $ser['MainDicomTags']['SeriesTime']),
'series_number' => data_get($ser, 'MainDicomTags.SeriesNumber'),
'series_description' => data_get($ser, 'MainDicomTags.SeriesDescription'),
'protocol_name' => data_get($ser, 'MainDicomTags.ProtocolName'),
'modality' => data_get($ser, 'MainDicomTags.Modality'),
'body_part_examined' => data_get($ser, 'MainDicomTags.BodyPartExamined'),