export function updatePatient()

in pathology/viewer/src/services/dicomweb.service.ts [433:472]


export function updatePatient(dicomModel: DicomModel, patient: Patient) {
  const patientNameInstanceValue = dicomModel[DicomTag.PATIENT_NAME]?.Value;
  const personName: PersonName | undefined =
    patientNameInstanceValue?.constructor !== Array &&
      isPatients(patientNameInstanceValue) ?
      patientNameInstanceValue[0] :
      undefined;

  patient.name ??= formatName(personName);

  const patientIdInstanceValue = dicomModel[DicomTag.PATIENT_ID]?.Value;
  let patientId = '';
  if (patientIdInstanceValue?.constructor === Array &&
    patientIdInstanceValue[0].constructor === String) {
    patientId = patientIdInstanceValue[0];
  }
  patient.patientId ??= patientId;

  const accessionNumberInstanceValue =
    dicomModel[DicomTag.ACCESSION_NUMBER]?.Value;
  let accessionNumber = 'Unknown Case ID';
  if (accessionNumberInstanceValue?.constructor === Array &&
    accessionNumberInstanceValue[0].constructor === String) {
    accessionNumber = accessionNumberInstanceValue[0] ?? 'Unknown Case ID';
  }

  const studyDateInstanceValue = dicomModel[DicomTag.STUDY_DATE]?.Value;
  let studyDate = '';
  if (studyDateInstanceValue?.constructor === Array &&
    studyDateInstanceValue[0].constructor === String) {
    studyDate = studyDateInstanceValue[0];
  }

  // Don't replace an undefined date with a default until after we're done
  // using them to find the most recent case.
  if (!patient.latestCaseDate || studyDate > patient.latestCaseDate) {
    patient.latestCaseDate = studyDate;
    patient.latestCaseAccessionNumber = accessionNumber;
  }
}