study importer
This commit is contained in:
parent
62f030a05b
commit
ec50e81d4d
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Enums\StudyLevelStatus;
|
||||
use App\Models\Study;
|
||||
use App\Models\StudyDetails;
|
||||
use Carbon\Carbon;
|
||||
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);
|
||||
|
||||
$data = [
|
||||
'orthanc_uid' => strtolower($study['ID']),
|
||||
$study = [
|
||||
'orthanc_uid' => strtolower($orthanc_src['ID']),
|
||||
'is_locked' => false,
|
||||
'is_active' => true,
|
||||
|
||||
'institution_name' => $inst_name,
|
||||
'institute_id' => $inst_id,
|
||||
|
||||
'patient_uid' => $study['ParentPatient'],
|
||||
'patient_id' => data_get($study, 'PatientMainDicomTags.PatientID'),
|
||||
'patient_name' => data_get($study, 'PatientMainDicomTags.PatientName'),
|
||||
'patient_sex' => data_get($study, 'PatientMainDicomTags.PatientSex'),
|
||||
'patient_uid' => $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'),
|
||||
|
||||
'accession_number' => data_get($study, 'MainDicomTags.AccessionNumber'),
|
||||
'referring_physician_name' => data_get($study, 'MainDicomTags.ReferringPhysicianName'),
|
||||
'study_id' => data_get($study, 'MainDicomTags.StudyID'),
|
||||
'study_instance_uid' => data_get($study, 'MainDicomTags.StudyInstanceUID'),
|
||||
'study_date' => DicomUtils::dateTimeToCarbon($study['MainDicomTags']['StudyDate'], $study['MainDicomTags']['StudyTime']),
|
||||
'receive_date' => Carbon::parse($study['LastUpdate'], 'UTC'),
|
||||
'accession_number' => data_get($orthanc_src, 'MainDicomTags.AccessionNumber'),
|
||||
'referring_physician_name' => data_get($orthanc_src, 'MainDicomTags.ReferringPhysicianName'),
|
||||
'study_id' => data_get($orthanc_src, 'MainDicomTags.StudyID'),
|
||||
'study_instance_uid' => data_get($orthanc_src, 'MainDicomTags.StudyInstanceUID'),
|
||||
'study_modality' => data_get($orthanc_src, 'RequestedTags.Modality'),
|
||||
'body_part_examined' => data_get($orthanc_src, 'RequestedTags.BodyPartExamined'),
|
||||
|
||||
'study_modality' => data_get($study, 'RequestedTags.Modality'),
|
||||
'body_part_examined' => data_get($study, 'RequestedTags.BodyPartExamined'),
|
||||
'study_date' => DicomUtils::dateTimeToCarbon($orthanc_src['MainDicomTags']['StudyDate'], $orthanc_src['MainDicomTags']['StudyTime']),
|
||||
'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'),
|
||||
'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'),
|
||||
|
||||
'image_count' => data_get($study, 'Statistics.CountInstances'),
|
||||
'series_count' => data_get($study, 'Statistics.CountSeries'),
|
||||
'disk_size' => data_get($study, 'Statistics.DiskSize'),
|
||||
];
|
||||
|
||||
if ($study['IsStable']) {
|
||||
$data['study_status'] = StudyLevelStatus::StudyArrived->value;
|
||||
} else {
|
||||
$data['study_status'] = StudyLevelStatus::Pending->value;
|
||||
}
|
||||
$study = array_filter($study, fn ($v) => filled($v));
|
||||
$details = array_filter($details, fn ($v) => filled($v));
|
||||
|
||||
$dob = data_get($study, 'PatientMainDicomTags.PatientBirthDate');
|
||||
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;
|
||||
return compact('study', 'details');
|
||||
}
|
||||
|
||||
public function updateStudy(int $row_id, mixed $study): void
|
||||
private function setValue(array &$array, string $key, mixed $value): void
|
||||
{
|
||||
$data = $this->prepareData($study);
|
||||
unset($data['orthanc_uid']);
|
||||
Study::where('id', $row_id)->update($data);
|
||||
if (filled($value)) {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function insertStudy(mixed $study): void
|
||||
private function updateStudy(int $row_id, mixed $study): void
|
||||
{
|
||||
$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