# VAI-B pseudonymization recipe. It can be described in the following ways:
# •	Patient ID, Accession Number, Admission ID, Interpretation ID,
#     Performed Procedure Step ID, Performing Physician's Name, Requested Procedure ID,
#     Results ID, and Study ID are hashed using "salted" SHA512/256 instead of blanked.
#     Only the data controller has access to the salt.
# •	Retain Patient Characteristics Option. The patient characteristics are binned to
#     enhance privacy. Day is removed from day of birth (DOB) and only month and year
#     stored. Weight is rounded to intervals of 5 kg. Length is rounded to intervals of
#     5 cm. Age is rounded to intervals of 5 years.
# •	Acquisition times are preserved.
# •	Study and series descriptions are preserved.
# •	Retain Institution Identity Option is followed.
# •	Retain Device Identity Option is followed.
# •	Retain Longitudinal Temporal Information with Full Dates Option is followed.
# •	UIDs are kept.

FORMAT dicom

%header

ADD PatientIdentityRemoved Yes
ADD DeidentificationMethod vaib_deid_v1.0.1

# Replacements with custom functions. Those can be found in cobra_db.deid

REPLACE PatientName func:replace_name
REPLACE AccessionNumber func:hash_func
REPLACE AdmissionID func:hash_func
REPLACE InterpretationID func:hash_func
REPLACE PatientBirthDate func:remove_day
REPLACE PatientID func:hash_func
REPLACE PerformedProcedureStepID func:hash_func
REPLACE PerformingPhysicianName func:hash_func
REPLACE RequestedProcedureID func:hash_func
REPLACE ResultsID func:hash_func
REPLACE StudyID func:hash_func
REPLACE PatientWeight func:round_DS_to_nearest_5
REPLACE PatientSize func:round_DS_to_nearest_0_05
REPLACE PatientAge func:round_AS_to_nearest_5y

# Tags that require custom treatment
# Curve Data"(50xx,xxxx)"
REMOVE contains:^50.{6}$
# Overlay comments and data (60xx[34]000)
REMOVE contains:^60.{2}[34]000$
# Private tags ggggeeee where gggg is odd
REMOVE contains:^.{3}[13579].{4}$

# Tags not found in pydicom._data_dict
BLANK contains:001811BB
BLANK contains:006A0003
BLANK contains:006A0005
KEEP contains:00080017
KEEP contains:00181203
KEEP contains:0040A033
KEEP contains:300A0785
KEEP contains:300C0127
REMOVE contains:006A0006
REMOVE contains:300A078E
REMOVE contains:300A0792
REMOVE contains:300A0794
REMOVE contains:300A079A

# Everything else in Table E1 of the dicom standard (In alphabetical order).
# pydicom.datadict.keyword_for_tag and tag_for_keyword can be used to convert these names to tags
BLANK AcquisitionContextSequence
BLANK AcquisitionDeviceProcessingDescription
BLANK Allergies
BLANK BarcodeValue
BLANK ClinicalTrialProtocolID
BLANK ClinicalTrialProtocolName
BLANK ClinicalTrialSponsorName
BLANK ClinicalTrialSubjectID
BLANK ClinicalTrialSubjectReadingID
BLANK ClinicalTrialTimePointID
BLANK ConceptualVolumeCombinationDescription
BLANK ConceptualVolumeDescription
BLANK ConsultingPhysicianName
BLANK ContainerIdentifier
BLANK ContentCreatorName
BLANK ContentSequence
BLANK ContrastBolusAgent
BLANK DeviceAlternateIdentifier
BLANK EntityLabel
BLANK EntityLongLabel
BLANK FillerOrderNumberImagingServiceRequest
BLANK FlowIdentifier
BLANK FlowIdentifierSequence
BLANK FractionationNotes
BLANK GraphicAnnotationSequence
BLANK InterlockDescription
BLANK InterlockOriginDescription
BLANK IssuerOfTheContainerIdentifierSequence
BLANK IssuerOfTheSpecimenIdentifierSequence
BLANK LabelText
BLANK OperatorIdentificationSequence
BLANK PatientState
BLANK PersonIdentificationCodeSequence
BLANK PersonName
BLANK PlacerOrderNumberImagingServiceRequest
BLANK PreMedication
BLANK PrescriptionNotes
BLANK PrescriptionNotesSequence
BLANK ProtocolName
BLANK ROIInterpreter
BLANK ROIName
BLANK RTAccessoryDeviceSlotID
BLANK RTAccessoryHolderSlotID
BLANK RTPhysicianIntentNarrative
BLANK RTPlanLabel
BLANK RTPrescriptionLabel
BLANK RTToleranceSetLabel
BLANK RTTreatmentApproachLabel
BLANK RadiationDoseIdentificationLabel
BLANK RadiationDoseInVivoMeasurementLabel
BLANK RadiationGenerationModeDescription
BLANK RadiationGenerationModeLabel
BLANK ReasonForSuperseding
BLANK ReasonForTheAttributeModification
BLANK ReferencedStudySequence
BLANK RequestedProcedureDescription
BLANK ReviewerName
BLANK SelectorLOValue
BLANK SelectorLTValue
BLANK SelectorOBValue
BLANK SelectorPNValue
BLANK SelectorSHValue
BLANK SelectorSTValue
BLANK SelectorUNValue
BLANK SelectorURValue
BLANK SelectorUTValue
BLANK SourceIdentifier
BLANK SpecialNeeds
BLANK SpecimenIdentifier
BLANK SpecimenPreparationSequence
BLANK StructureSetLabel
BLANK TreatmentPositionGroupLabel
BLANK TreatmentTechniqueNotes
BLANK TreatmentToleranceViolationDescription
BLANK UserContentLabel
BLANK UserContentLongLabel
BLANK VerifyingObserverIdentificationCodeSequence
BLANK VerifyingObserverName
BLANK VerifyingObserverSequence
BLANK VerifyingOrganization
KEEP AcquisitionDate
KEEP AcquisitionDateTime
KEEP AcquisitionTime
KEEP AdmittingDate
KEEP AdmittingTime
KEEP ApprovalStatusDateTime
KEEP AssertionDateTime
KEEP AssertionExpirationDateTime
KEEP AttributeModificationDateTime
KEEP CalibrationDate
KEEP CalibrationTime
KEEP CassetteID
KEEP CertifiedTimestamp
KEEP ClinicalTrialCoordinatingCenterName
KEEP ClinicalTrialProtocolEthicsCommitteeName
KEEP ClinicalTrialSiteID
KEEP ClinicalTrialSiteName
KEEP ConcatenationUID
KEEP ConceptualVolumeUID
KEEP ConstituentConceptualVolumeUID
KEEP ContentDate
KEEP ContentTime
KEEP ContextGroupLocalVersion
KEEP ContextGroupVersion
KEEP ContrastBolusStartTime
KEEP ContrastBolusStopTime
KEEP ContributionDateTime
KEEP CreationDate
KEEP CreationTime
KEEP CurveDate
KEEP CurveTime
KEEP Date
KEEP DateOfDocumentOrVerbalTransactionTrial
KEEP DateOfLastCalibration
KEEP DateOfLastDetectorCalibration
KEEP DateOfSecondaryCapture
KEEP DateTime
KEEP DateTimeOfLastCalibration
KEEP DecayCorrectionDateTime
KEEP DetectorID
KEEP DeviceDescription
KEEP DeviceLabel
KEEP DeviceSerialNumber
KEEP DeviceUID
KEEP DigitalSignatureDateTime
KEEP DigitalSignatureUID
KEEP DimensionOrganizationUID
KEEP DischargeDate
KEEP DischargeTime
KEEP DoseReferenceUID
KEEP DosimetricObjectiveUID
KEEP EffectiveDateTime
KEEP EndAcquisitionDateTime
KEEP EthicsCommitteeApprovalEffectivenessEndDate
KEEP EthicsCommitteeApprovalEffectivenessStartDate
KEEP EthnicGroup
KEEP ExclusionStartDateTime
KEEP ExpectedCompletionDateTime
KEEP FailedSOPInstanceUIDList
KEEP FiducialUID
KEEP FindingsGroupRecordingDateTrial
KEEP FindingsGroupRecordingTimeTrial
KEEP FirstTreatmentDate
KEEP FrameAcquisitionDateTime
KEEP FrameOfReferenceUID
KEEP FrameOriginTimestamp
KEEP FrameReferenceDateTime
KEEP FunctionalSyncPulse
KEEP GPSDateStamp
KEEP GantryID
KEEP GeneratorID
KEEP HL7DocumentEffectiveTime
KEEP HangingProtocolCreationDateTime
KEEP ImpedanceMeasurementDateTime
KEEP InformationIssueDateTime
KEEP InstanceCoercionDateTime
KEEP InstanceCreationDate
KEEP InstanceCreationTime
KEEP InstanceCreatorUID
KEEP InstitutionAddress
KEEP InstitutionCodeSequence
KEEP InstitutionName
KEEP InstitutionalDepartmentName
KEEP InstitutionalDepartmentTypeCodeSequence
KEEP InstructionPerformedDateTime
KEEP IntendedFractionStartTime
KEEP IntendedPhaseEndDate
KEEP IntendedPhaseStartDate
KEEP InterlockDateTime
KEEP InterpretationApprovalDate
KEEP InterpretationApprovalTime
KEEP InterpretationRecordedDate
KEEP InterpretationRecordedTime
KEEP InterpretationTranscriptionDate
KEEP InterpretationTranscriptionTime
KEEP InterventionDrugStartTime
KEEP InterventionDrugStopTime
KEEP IrradiationEventUID
KEEP IssueDateOfImagingServiceRequest
KEEP IssueTimeOfImagingServiceRequest
KEEP LargePaletteColorLookupTableUID
KEEP LastMenstrualDate
KEEP LensMake
KEEP LensModel
KEEP LensSerialNumber
KEEP LensSpecification
KEEP ManufacturerDeviceClassUID
KEEP ManufacturerDeviceIdentifier
KEEP MediaStorageSOPInstanceUID
KEEP ModifiedImageDate
KEEP ModifiedImageTime
KEEP ModifyingDeviceID
KEEP ModifyingSystem
KEEP MostRecentTreatmentDate
KEEP MultiplexGroupUID
KEEP ObservationDateTime
KEEP ObservationDateTrial
KEEP ObservationSubjectUIDTrial
KEEP ObservationTimeTrial
KEEP ObservationUID
KEEP OverlayDate
KEEP OverlayTime
KEEP OverrideDateTime
KEEP PaletteColorLookupTableUID
KEEP ParticipationDateTime
KEEP PatientSetupUID
KEEP PatientSex
KEEP PatientSexNeutered
KEEP PerformedProcedureStepEndDate
KEEP PerformedProcedureStepEndDateTime
KEEP PerformedProcedureStepEndTime
KEEP PerformedProcedureStepStartDate
KEEP PerformedProcedureStepStartDateTime
KEEP PerformedProcedureStepStartTime
KEEP PerformedStationAETitle
KEEP PerformedStationGeographicLocationCodeSequence
KEEP PerformedStationName
KEEP PerformedStationNameCodeSequence
KEEP PlateID
KEEP PregnancyStatus
KEEP PresentationCreationDate
KEEP PresentationCreationTime
KEEP PresentationDisplayCollectionUID
KEEP PresentationSequenceCollectionUID
KEEP ProcedureStepCancellationDateTime
KEEP ProductExpirationDateTime
KEEP RTPlanDate
KEEP RTPlanTime
KEEP RTTreatmentPhaseUID
KEEP RadiopharmaceuticalStartDateTime
KEEP RadiopharmaceuticalStartTime
KEEP RadiopharmaceuticalStopDateTime
KEEP RadiopharmaceuticalStopTime
KEEP RecordedRTControlPointDateTime
KEEP ReferencedConceptualVolumeUID
KEEP ReferencedDateTime
KEEP ReferencedDoseReferenceUID
KEEP ReferencedDosimetricObjectiveUID
KEEP ReferencedFiducialsUID
KEEP ReferencedFrameOfReferenceUID
KEEP ReferencedGeneralPurposeScheduledProcedureStepTransactionUID
KEEP ReferencedObservationUIDTrial
KEEP ReferencedSOPInstanceUID
KEEP ReferencedSOPInstanceUIDInFile
KEEP RelatedFrameOfReferenceUID
KEEP RequestedSOPInstanceUID
KEEP ReviewDate
KEEP ReviewTime
KEEP SOPAuthorizationDateTime
KEEP SOPInstanceUID
KEEP SafePositionExitDate
KEEP SafePositionExitTime
KEEP SafePositionReturnDate
KEEP SafePositionReturnTime
KEEP ScheduledAdmissionDate
KEEP ScheduledAdmissionTime
KEEP ScheduledDischargeDate
KEEP ScheduledDischargeTime
KEEP ScheduledProcedureStepEndDate
KEEP ScheduledProcedureStepEndTime
KEEP ScheduledProcedureStepExpirationDateTime
KEEP ScheduledProcedureStepLocation
KEEP ScheduledProcedureStepModificationDateTime
KEEP ScheduledProcedureStepStartDate
KEEP ScheduledProcedureStepStartDateTime
KEEP ScheduledProcedureStepStartTime
KEEP ScheduledStationAETitle
KEEP ScheduledStationGeographicLocationCodeSequence
KEEP ScheduledStationName
KEEP ScheduledStationNameCodeSequence
KEEP ScheduledStudyLocation
KEEP ScheduledStudyLocationAETitle
KEEP ScheduledStudyStartDate
KEEP ScheduledStudyStartTime
KEEP ScheduledStudyStopDate
KEEP ScheduledStudyStopTime
KEEP SelectorASValue
KEEP SelectorDAValue
KEEP SelectorDTValue
KEEP SelectorTMValue
KEEP SeriesDate
KEEP SeriesDescription
KEEP SeriesInstanceUID
KEEP SeriesTime
KEEP SmokingStatus
KEEP SourceConceptualVolumeUID
KEEP SourceEndDateTime
KEEP SourceManufacturer
KEEP SourceOfPreviousValues
KEEP SourceSerialNumber
KEEP SourceStartDateTime
KEEP SourceStrengthReferenceDate
KEEP SourceStrengthReferenceTime
KEEP SpecimenUID
KEEP StartAcquisitionDateTime
KEEP StationName
KEEP StorageMediaFileSetUID
KEEP StructureSetDate
KEEP StructureSetTime
KEEP StudyArrivalDate
KEEP StudyArrivalTime
KEEP StudyCompletionDate
KEEP StudyCompletionTime
KEEP StudyDate
KEEP StudyDescription
KEEP StudyInstanceUID
KEEP StudyReadDate
KEEP StudyReadTime
KEEP StudyTime
KEEP StudyVerifiedDate
KEEP StudyVerifiedTime
KEEP SubstanceAdministrationDateTime
KEEP SynchronizationFrameOfReferenceUID
KEEP TargetUID
KEEP TemplateExtensionCreatorUID
KEEP TemplateExtensionOrganizationUID
KEEP TemplateLocalVersion
KEEP TemplateVersion
KEEP Time
KEEP TimeOfDocumentCreationOrVerbalTransactionTrial
KEEP TimeOfLastCalibration
KEEP TimeOfLastDetectorCalibration
KEEP TimeOfSecondaryCapture
KEEP TimezoneOffsetFromUTC
KEEP TrackingUID
KEEP TransactionUID
KEEP TransducerIdentificationSequence
KEEP TreatmentControlPointDate
KEEP TreatmentControlPointTime
KEEP TreatmentDate
KEEP TreatmentMachineName
KEEP TreatmentPositionGroupUID
KEEP TreatmentSessionUID
KEEP TreatmentTime
KEEP TreatmentToleranceViolationDateTime
KEEP UDISequence
KEEP UID
KEEP UniqueDeviceIdentifier
KEEP VerificationDateTime
KEEP XRayDetectorID
KEEP XRayDetectorLabel
KEEP XRaySourceID
REMOVE AcquisitionComments
REMOVE AcquisitionProtocolDescription
REMOVE ActualHumanPerformersSequence
REMOVE AdditionalPatientHistory
REMOVE AddressTrial
REMOVE AdmittingDiagnosesCodeSequence
REMOVE AdmittingDiagnosesDescription
REMOVE AffectedSOPInstanceUID
REMOVE Arbitrary
REMOVE AuthorObserverSequence
REMOVE BeamDescription
REMOVE BolusDescription
REMOVE BranchOfService
REMOVE CameraOwnerName
REMOVE ClinicalTrialProtocolEthicsCommitteeApprovalNumber
REMOVE ClinicalTrialSeriesDescription
REMOVE ClinicalTrialSeriesID
REMOVE ClinicalTrialTimePointDescription
REMOVE CommentsOnRadiationDose
REMOVE CommentsOnThePerformedProcedureStep
REMOVE CompensatorDescription
REMOVE ConfidentialityConstraintOnPatientDataDescription
REMOVE ConsultingPhysicianIdentificationSequence
REMOVE ContainerComponentID
REMOVE ContainerDescription
REMOVE ContentCreatorIdentificationCodeSequence
REMOVE ContributionDescription
REMOVE CountryOfResidence
REMOVE CurrentObserverTrial
REMOVE CurrentPatientLocation
REMOVE CustodialOrganizationSequence
REMOVE DataSetTrailingPadding
REMOVE DecompositionDescription
REMOVE DerivationDescription
REMOVE DeviceSettingDescription
REMOVE DigitalSignaturesSequence
REMOVE DischargeDiagnosisDescription
REMOVE DistributionAddress
REMOVE DistributionName
REMOVE DoseReferenceDescription
REMOVE EntityDescription
REMOVE EntityName
REMOVE EquipmentFrameOfReferenceDescription
REMOVE FixationDeviceDescription
REMOVE FractionGroupDescription
REMOVE FrameComments
REMOVE GPSAltitude
REMOVE GPSAltitudeRef
REMOVE GPSAreaInformation
REMOVE GPSDOP
REMOVE GPSDestBearing
REMOVE GPSDestBearingRef
REMOVE GPSDestDistance
REMOVE GPSDestDistanceRef
REMOVE GPSDestLatitude
REMOVE GPSDestLatitudeRef
REMOVE GPSDestLongitude
REMOVE GPSDestLongitudeRef
REMOVE GPSDifferential
REMOVE GPSImgDirection
REMOVE GPSImgDirectionRef
REMOVE GPSLatitude
REMOVE GPSLatitudeRef
REMOVE GPSLongitude
REMOVE GPSLongitudeRef
REMOVE GPSMapDatum
REMOVE GPSMeasureMode
REMOVE GPSProcessingMethod
REMOVE GPSSatellites
REMOVE GPSSpeed
REMOVE GPSSpeedRef
REMOVE GPSStatus
REMOVE GPSTimeStamp
REMOVE GPSTrack
REMOVE GPSTrackRef
REMOVE GPSVersionID
REMOVE HumanPerformerName
REMOVE HumanPerformerOrganization
REMOVE IconImageSequence
REMOVE IdentifyingComments
REMOVE ImageComments
REMOVE ImagePresentationComments
REMOVE ImagingServiceRequestComments
REMOVE Impressions
REMOVE InstanceOriginStatus
REMOVE InsurancePlanIdentification
REMOVE IntendedRecipientsOfResultsIdentificationSequence
REMOVE InterpretationApproverSequence
REMOVE InterpretationAuthor
REMOVE InterpretationDiagnosisDescription
REMOVE InterpretationIDIssuer
REMOVE InterpretationRecorder
REMOVE InterpretationText
REMOVE InterpretationTranscriber
REMOVE IssuerOfAdmissionID
REMOVE IssuerOfAdmissionIDSequence
REMOVE IssuerOfPatientID
REMOVE IssuerOfServiceEpisodeID
REMOVE IssuerOfServiceEpisodeIDSequence
REMOVE LongDeviceDescription
REMOVE MAC
REMOVE MakerNote
REMOVE MedicalAlerts
REMOVE MedicalRecordLocator
REMOVE MilitaryRank
REMOVE ModifiedAttributesSequence
REMOVE ModifiedImageDescription
REMOVE MultienergyAcquisitionDescription
REMOVE NameOfPhysiciansReadingStudy
REMOVE NamesOfIntendedRecipientsOfResults
REMOVE NonconformingDataElementValue
REMOVE NonconformingModifiedAttributesSequence
REMOVE Occupation
REMOVE OperatorsName
REMOVE OrderCallbackPhoneNumber
REMOVE OrderCallbackTelecomInformation
REMOVE OrderEnteredBy
REMOVE OrderEntererLocation
REMOVE OriginalAttributesSequence
REMOVE OtherPatientIDs
REMOVE OtherPatientIDsSequence
REMOVE OtherPatientNames
REMOVE ParticipantSequence
REMOVE PatientAddress
REMOVE PatientBirthName
REMOVE PatientBirthTime
REMOVE PatientComments
REMOVE PatientInstitutionResidence
REMOVE PatientInsurancePlanCodeSequence
REMOVE PatientMotherBirthName
REMOVE PatientPrimaryLanguageCodeSequence
REMOVE PatientPrimaryLanguageModifierCodeSequence
REMOVE PatientReligiousPreference
REMOVE PatientTelecomInformation
REMOVE PatientTelephoneNumbers
REMOVE PatientTransportArrangements
REMOVE PerformedLocation
REMOVE PerformedProcedureStepDescription
REMOVE PerformingPhysicianIdentificationSequence
REMOVE PersonAddress
REMOVE PersonTelecomInformation
REMOVE PersonTelephoneNumbers
REMOVE PhysicianApprovingInterpretation
REMOVE PhysiciansOfRecord
REMOVE PhysiciansOfRecordIdentificationSequence
REMOVE PhysiciansReadingStudyIdentificationSequence
REMOVE PrescriptionDescription
REMOVE PriorTreatmentDoseDescription
REMOVE ROIDescription
REMOVE ROIGenerationDescription
REMOVE ROIObservationDescription
REMOVE ROIObservationLabel
REMOVE RTPlanDescription
REMOVE RTPlanName
REMOVE ReasonForOmissionDescription
REMOVE ReasonForRequestedProcedureCodeSequence
REMOVE ReasonForStudy
REMOVE ReasonForTheImagingServiceRequest
REMOVE ReasonForTheRequestedProcedure
REMOVE ReasonForVisit
REMOVE ReasonForVisitCodeSequence
REMOVE ReferencedDigitalSignatureSequence
REMOVE ReferencedImageSequence
REMOVE ReferencedPatientAliasSequence
REMOVE ReferencedPatientPhotoSequence
REMOVE ReferencedPatientSequence
REMOVE ReferencedPerformedProcedureStepSequence
REMOVE ReferencedSOPInstanceMACSequence
REMOVE ReferringPhysicianName
REMOVE ReferringPhysicianAddress
REMOVE ReferringPhysicianIdentificationSequence
REMOVE ReferringPhysicianTelephoneNumbers
REMOVE RegionOfResidence
REMOVE RequestAttributesSequence
REMOVE RequestedContrastAgent
REMOVE RequestedProcedureComments
REMOVE RequestedProcedureLocation
REMOVE RequestedSeriesDescription
REMOVE RequestingPhysician
REMOVE RequestingService
REMOVE RespiratoryMotionCompensationTechniqueDescription
REMOVE ResponsibleOrganization
REMOVE ResponsiblePerson
REMOVE ResultsComments
REMOVE ResultsDistributionListSequence
REMOVE ResultsIDIssuer
REMOVE ScheduledHumanPerformersSequence
REMOVE ScheduledPatientInstitutionResidence
REMOVE ScheduledPerformingPhysicianIdentificationSequence
REMOVE ScheduledPerformingPhysicianName
REMOVE ScheduledProcedureStepDescription
REMOVE ScheduledProcedureStepID
REMOVE ServiceEpisodeDescription
REMOVE ServiceEpisodeID
REMOVE SetupTechniqueDescription
REMOVE ShieldingDeviceDescription
REMOVE SlideIdentifier
REMOVE SourceImageSequence
REMOVE SpecimenAccessionNumber
REMOVE SpecimenDetailedDescription
REMOVE SpecimenShortDescription
REMOVE StructureSetDescription
REMOVE StructureSetName
REMOVE StudyComments
REMOVE StudyIDIssuer
REMOVE TelephoneNumberTrial
REMOVE TextComments
REMOVE TextString
REMOVE TopicAuthor
REMOVE TopicKeywords
REMOVE TopicSubject
REMOVE TopicTitle
REMOVE TreatmentSite
REMOVE TreatmentSites
REMOVE VerbalSourceIdentifierCodeSequenceTrial
REMOVE VerbalSourceTrial
REMOVE VisitComments
