age - dob calculation
This commit is contained in:
parent
9e969df68b
commit
d4c6e58e30
@ -149,15 +149,27 @@ public function transformData(mixed $orthanc_src): array
|
||||
$patient_name = data_get($orthanc_src, 'PatientMainDicomTags.PatientName');
|
||||
$name_parts = tokenizeString($patient_name);
|
||||
$patient_age = data_get($orthanc_src, 'RequestedTags.PatientAge');
|
||||
if (blank($patient_age)) {
|
||||
if (blank($patient_age) && ! empty($name_parts)) {
|
||||
// try to get age from last part of patient name
|
||||
if (! empty($name_parts)) {
|
||||
$last = end($name_parts);
|
||||
if (preg_match('/\d+Y/i', $last)) {
|
||||
$patient_age = strtoupper($last);
|
||||
if (preg_match('/^\d+[YMD]$/i', $last)) {
|
||||
$patient_age = $last;
|
||||
/*
|
||||
// sanitize patient name
|
||||
array_pop($name_parts);
|
||||
$patient_name = implode(' ', $name_parts);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if ($patient_age !== null) {
|
||||
$age = strtoupper(ltrim($patient_age, '0'));
|
||||
if (strlen($age) > 1) {
|
||||
$patient_age = $age;
|
||||
}
|
||||
}
|
||||
|
||||
// $patient_name = trim($patient_name, '.^ ');
|
||||
|
||||
$descr = $this->getStudyDescription($orthanc_src);
|
||||
$study = [
|
||||
@ -193,27 +205,40 @@ public function transformData(mixed $orthanc_src): array
|
||||
$study['workflow_level'] = $stable_study
|
||||
? WorkflowLevel::Unassigned->value
|
||||
: WorkflowLevel::Received->value;
|
||||
$study['patient_birthdate'] = null;
|
||||
|
||||
$patient_birthdate = null;
|
||||
$dob = data_get($orthanc_src, 'PatientMainDicomTags.PatientBirthDate');
|
||||
if (filled($dob)) {
|
||||
try {
|
||||
$study['patient_birthdate'] = Carbon::parse($dob);
|
||||
$patient_birthdate = Carbon::parse($dob);
|
||||
} catch (Exception $e) {
|
||||
Log::error('Failed to parse PatientMainDicomTags.PatientBirthDate: {dob}', ['dob' => $dob, 'exception' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
if (($study['patient_birthdate'] == null) && $patient_age !== null) {
|
||||
if ($patient_birthdate == null && $patient_age !== null) {
|
||||
try {
|
||||
// $age = (int) preg_replace('/[^0-9]/', '', $patient_age);
|
||||
$age = (int) filter_var($patient_age, FILTER_SANITIZE_NUMBER_INT);
|
||||
$study['patient_birthdate'] = Carbon::now()->subYears($age);
|
||||
|
||||
$age_num = (int) filter_var($patient_age, FILTER_SANITIZE_NUMBER_INT);
|
||||
$now = now();
|
||||
switch (strtoupper(substr($patient_age, -1))) {
|
||||
case 'Y':
|
||||
$patient_birthdate = $now->subYears($age_num);
|
||||
break;
|
||||
case 'M':
|
||||
$patient_birthdate = $now->subMonths($age_num);
|
||||
break;
|
||||
case 'D':
|
||||
$patient_birthdate = $now->subDays($age_num);
|
||||
break;
|
||||
}
|
||||
} catch (Exception) {
|
||||
Log::error('Failed to parse patient_age: {age}', ['age' => $patient_age]);
|
||||
}
|
||||
}
|
||||
|
||||
$study['patient_birthdate'] = $patient_birthdate;
|
||||
|
||||
// check for priority in patient name or description
|
||||
if (preg_match('/\b(urgent|stat)\b/i', implode(' ', [$descr, $patient_name]))) {
|
||||
$this->setValue($study, 'priority', Priority::Stat->value);
|
||||
@ -307,7 +332,7 @@ private function getStudyDicomTags(string $study_uuid): array
|
||||
// randomly sample few instances for tags collection
|
||||
$selectedInstances = count($instances) <= $this->maxInstances
|
||||
? $instances
|
||||
: array_rand(array_flip($instances), $this->maxInstances);
|
||||
: array_intersect_key($instances, array_flip(array_rand($instances, $this->maxInstances)));
|
||||
|
||||
$tags = collect();
|
||||
foreach ($selectedInstances as $instance) {
|
||||
|
Loading…
Reference in New Issue
Block a user