JuliaHealth / DICOM.jl

Julia package for reading and writing DICOM (Digital Imaging and Communications in Medicine) files
MIT License
56 stars 21 forks source link

Overloading propertynames #73

Closed mateuszbaran closed 3 years ago

mateuszbaran commented 3 years ago

It would be convenient to overload Base.propertynames for DICOM.DICOMData. It makes interactive work with it easier by exposing properties in REPL tab-completion. I've prepared the following implementation and I can make a PR if you're interested:

function Base.propertynames(dcm::DICOM.DICOMData)
    basic_properties = invoke(propertynames, Tuple{Any}, dcm)
    dcm_keys = keys(dcm.meta)
    pnames = Symbol[basic_properties...]
    for (k, v) in DICOM.fieldname_dict
        if v in dcm_keys
            push!(pnames, k)
        end
    end
    return pnames
end

Now I can get a nice list:

julia> dcm_data.
AccessionNumber                FileMetaInformationGroupLength  InstanceCreationDate            OtherPatientIDs                 PositionReferenceIndicator      SeriesNumber                    StudyTime
BitsAllocated                  FileMetaInformationVersion      InstanceCreationTime            PatientBirthDate                ReferencedRTPlanSequence        SliceThickness                  TissueHeterogeneityCorrection
BitsStored                     FrameIncrementPointer           InstanceNumber                  PatientID                       ReferringPhysicianName          SoftwareVersions                TransferSyntaxUID
Columns                        FrameOfReferenceUID             Manufacturer                    PatientName                     Rows                            SpecificCharacterSet            endian
DeviceSerialNumber             GridFrameOffsetVector           ManufacturerModelName           PatientSex                      SOPClassUID                     StationName                     isexplicit
DoseGridScaling                HighBit                         MediaStorageSOPClassUID         PhotometricInterpretation       SOPInstanceUID                  StudyDate                       meta
DoseSummationType              ImageOrientationPatient         MediaStorageSOPInstanceUID      PixelData                       SamplesPerPixel                 StudyDescription                vr
DoseType                       ImagePositionPatient            Modality                        PixelRepresentation             SeriesDescription               StudyID
DoseUnits                      ImplementationClassUID          NumberOfFrames                  PixelSpacing                    SeriesInstanceUID               StudyInstanceUID
notZaki commented 3 years ago

That's brilliant! It would definitely be a nice a improvement, so a PR is welcome.