study importer
This commit is contained in:
parent
62f030a05b
commit
ec50e81d4d
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Models\Enums\StudyLevelStatus;
|
use App\Models\Enums\StudyLevelStatus;
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
|
use App\Models\StudyDetails;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
@ -82,74 +83,92 @@ public function importStudies()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareData(mixed $study): array
|
private function prepareData(mixed $orthanc_src): array
|
||||||
{
|
{
|
||||||
$inst_name = data_get($study, 'MainDicomTags.InstitutionName');
|
$inst_name = data_get($orthanc_src, 'MainDicomTags.InstitutionName');
|
||||||
$inst_id = InstituteMapper::map($inst_name);
|
$inst_id = InstituteMapper::map($inst_name);
|
||||||
|
|
||||||
$data = [
|
$study = [
|
||||||
'orthanc_uid' => strtolower($study['ID']),
|
'orthanc_uid' => strtolower($orthanc_src['ID']),
|
||||||
'is_locked' => false,
|
'is_locked' => false,
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
|
|
||||||
'institution_name' => $inst_name,
|
'institution_name' => $inst_name,
|
||||||
'institute_id' => $inst_id,
|
'institute_id' => $inst_id,
|
||||||
|
|
||||||
'patient_uid' => $study['ParentPatient'],
|
'patient_uid' => $orthanc_src['ParentPatient'],
|
||||||
'patient_id' => data_get($study, 'PatientMainDicomTags.PatientID'),
|
'patient_id' => data_get($orthanc_src, 'PatientMainDicomTags.PatientID'),
|
||||||
'patient_name' => data_get($study, 'PatientMainDicomTags.PatientName'),
|
'patient_name' => data_get($orthanc_src, 'PatientMainDicomTags.PatientName'),
|
||||||
'patient_sex' => data_get($study, 'PatientMainDicomTags.PatientSex'),
|
'patient_sex' => data_get($orthanc_src, 'PatientMainDicomTags.PatientSex'),
|
||||||
|
|
||||||
'accession_number' => data_get($study, 'MainDicomTags.AccessionNumber'),
|
'accession_number' => data_get($orthanc_src, 'MainDicomTags.AccessionNumber'),
|
||||||
'referring_physician_name' => data_get($study, 'MainDicomTags.ReferringPhysicianName'),
|
'referring_physician_name' => data_get($orthanc_src, 'MainDicomTags.ReferringPhysicianName'),
|
||||||
'study_id' => data_get($study, 'MainDicomTags.StudyID'),
|
'study_id' => data_get($orthanc_src, 'MainDicomTags.StudyID'),
|
||||||
'study_instance_uid' => data_get($study, 'MainDicomTags.StudyInstanceUID'),
|
'study_instance_uid' => data_get($orthanc_src, 'MainDicomTags.StudyInstanceUID'),
|
||||||
'study_date' => DicomUtils::dateTimeToCarbon($study['MainDicomTags']['StudyDate'], $study['MainDicomTags']['StudyTime']),
|
'study_modality' => data_get($orthanc_src, 'RequestedTags.Modality'),
|
||||||
'receive_date' => Carbon::parse($study['LastUpdate'], 'UTC'),
|
'body_part_examined' => data_get($orthanc_src, 'RequestedTags.BodyPartExamined'),
|
||||||
|
|
||||||
'study_modality' => data_get($study, 'RequestedTags.Modality'),
|
'study_date' => DicomUtils::dateTimeToCarbon($orthanc_src['MainDicomTags']['StudyDate'], $orthanc_src['MainDicomTags']['StudyTime']),
|
||||||
'body_part_examined' => data_get($study, 'RequestedTags.BodyPartExamined'),
|
'receive_date' => Carbon::parse($orthanc_src['LastUpdate'], 'UTC'),
|
||||||
|
|
||||||
|
'image_count' => data_get($orthanc_src, 'Statistics.CountInstances'),
|
||||||
|
'series_count' => data_get($orthanc_src, 'Statistics.CountSeries'),
|
||||||
|
'disk_size' => data_get($orthanc_src, 'Statistics.DiskSize'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ((bool) $orthanc_src['IsStable']) {
|
||||||
|
$study['study_status'] = StudyLevelStatus::StudyArrived->value;
|
||||||
|
} else {
|
||||||
|
$study['study_status'] = StudyLevelStatus::Pending->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dob = data_get($orthanc_src, 'PatientMainDicomTags.PatientBirthDate');
|
||||||
|
if (filled($dob)) {
|
||||||
|
$study['patient_birthdate'] = Carbon::parse($dob);
|
||||||
|
}
|
||||||
|
|
||||||
|
$descr = data_get($orthanc_src, 'MainDicomTags.StudyDescription');
|
||||||
|
if (blank($descr)) {
|
||||||
|
$descr = data_get($orthanc_src, 'RequestedTags.AcquisitionDeviceProcessingDescription');
|
||||||
|
}
|
||||||
|
$this->setValue($study, 'study_description', trim($descr));
|
||||||
|
|
||||||
|
$details = [
|
||||||
'software_versions' => data_get($study, 'RequestedTags.SoftwareVersions'),
|
'software_versions' => data_get($study, 'RequestedTags.SoftwareVersions'),
|
||||||
'station_name' => data_get($study, 'RequestedTags.StationName'),
|
'station_name' => data_get($study, 'RequestedTags.StationName'),
|
||||||
'operators_name' => data_get($study, 'RequestedTags.OperatorsName'),
|
'operators_name' => data_get($study, 'RequestedTags.OperatorsName'),
|
||||||
'manufacturer' => data_get($study, 'RequestedTags.Manufacturer'),
|
'manufacturer' => data_get($study, 'RequestedTags.Manufacturer'),
|
||||||
'manufacturer_model_name' => data_get($study, 'RequestedTags.ManufacturerModelName'),
|
'manufacturer_model_name' => data_get($study, 'RequestedTags.ManufacturerModelName'),
|
||||||
|
|
||||||
'image_count' => data_get($study, 'Statistics.CountInstances'),
|
|
||||||
'series_count' => data_get($study, 'Statistics.CountSeries'),
|
|
||||||
'disk_size' => data_get($study, 'Statistics.DiskSize'),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($study['IsStable']) {
|
$study = array_filter($study, fn ($v) => filled($v));
|
||||||
$data['study_status'] = StudyLevelStatus::StudyArrived->value;
|
$details = array_filter($details, fn ($v) => filled($v));
|
||||||
} else {
|
|
||||||
$data['study_status'] = StudyLevelStatus::Pending->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dob = data_get($study, 'PatientMainDicomTags.PatientBirthDate');
|
return compact('study', 'details');
|
||||||
if (trim($dob) != '') {
|
|
||||||
$data['patient_birthdate'] = Carbon::parse($dob);
|
|
||||||
}
|
|
||||||
|
|
||||||
$descr = data_get($study, 'MainDicomTags.StudyDescription');
|
|
||||||
if ($descr == null) {
|
|
||||||
$descr = data_get($study, 'RequestedTags.AcquisitionDeviceProcessingDescription');
|
|
||||||
}
|
|
||||||
$data['study_description'] = trim($descr);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateStudy(int $row_id, mixed $study): void
|
private function setValue(array &$array, string $key, mixed $value): void
|
||||||
{
|
{
|
||||||
$data = $this->prepareData($study);
|
if (filled($value)) {
|
||||||
unset($data['orthanc_uid']);
|
$array[$key] = $value;
|
||||||
Study::where('id', $row_id)->update($data);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insertStudy(mixed $study): void
|
private function updateStudy(int $row_id, mixed $study): void
|
||||||
{
|
{
|
||||||
$data = $this->prepareData($study);
|
$data = $this->prepareData($study);
|
||||||
Study::create($data);
|
unset($data['study']['orthanc_uid']);
|
||||||
|
DB::table('studies')->where('id', $row_id)->update($data['study']);
|
||||||
|
if (! empty($data['details'])) {
|
||||||
|
DB::table('study_details')->where('study_id', $row_id)->update($data['details']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function insertStudy(mixed $study): void
|
||||||
|
{
|
||||||
|
$data = $this->prepareData($study);
|
||||||
|
$study = Study::create($data['study']);
|
||||||
|
$data['details']['study_id'] = $study->id;
|
||||||
|
StudyDetails::create($data['details']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user