main_44.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. def _modify_dataset(
  2. self,
  3. anonymizer: Anonymizer,
  4. pseudonym: str,
  5. ds: Dataset,
  6. ) -> None:
  7. """Optionally pseudonymize an incoming dataset with the given pseudonym
  8. and add the trial ID and name to the DICOM header if specified."""
  9. if pseudonym:
  10. # All dates get pseudonymized, but we want to retain the study date.
  11. study_date = ds.StudyDate
  12. anonymizer.anonymize(ds)
  13. ds.StudyDate = study_date
  14. ds.PatientID = pseudonym
  15. ds.PatientName = pseudonym
  16. trial_protocol_id = (self.transfer_task.job.trial_protocol_id,)
  17. trial_protocol_name = self.transfer_task.job.trial_protocol_name
  18. if trial_protocol_id:
  19. ds.ClinicalTrialProtocolID = trial_protocol_id
  20. if trial_protocol_name:
  21. ds.ClinicalTrialProtocolName = trial_protocol_name
  22. if pseudonym and trial_protocol_id:
  23. session_id = f"{ds.StudyDate}-{ds.StudyTime}"
  24. ds.PatientComments = f"Project:{trial_protocol_id} Subject:{pseudonym} Session:{pseudonym}_{session_id}"