Skip to content

Commit

Permalink
Ignore non-DICOM files in a directory (#83)
Browse files Browse the repository at this point in the history
* fixed `isdicom`

added `try` and `catch` statements which should get around the fact that not all directories are pure DICOM files

* update

* update

* update

* finalize

* finalize

* Update src/DICOM.jl

Co-authored-by: Dilum Aluthge <[email protected]>

* Create invalid dicom file for testing isdicom()

* Update version

* Make temporary test file even smaller

Co-authored-by: Dilum Aluthge <[email protected]>
Co-authored-by: Zaki A <[email protected]>
Co-authored-by: Zaki A <[email protected]>
  • Loading branch information
4 people authored Dec 13, 2021
1 parent d1e5567 commit cfee5eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DICOM"
uuid = "a26e6606-dd52-5f6a-a97f-4f611373d757"
version = "0.10.0"
version = "0.10.1"

[compat]
julia = "0.7, 1"
Expand Down
8 changes: 6 additions & 2 deletions src/DICOM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ function find_dicom_files(dir)
end

function isdicom(file)
bytes = read(file, 132)[end-3:end]
String(bytes) == "DICM"
all_bytes = read(file, 132)
if length(all_bytes) < 132
return false
end
my_bytes = all_bytes[end-3:end]
return String(my_bytes) == "DICM"
end

function dcmdir_parse(dir; kwargs...)
Expand Down
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,21 @@ end
@testset "Parse entire folder" begin
# Following files have missing preamble and won't be parsed
# ["OT_Implicit_Little_Headless.dcm", "CT_Implicit_Little_Headless_Retired.dcm"]
# along with an invalid notdicom.dcm file which we will first create
notdicomfile = joinpath(data_folder, "notdicom.dcm")
open(notdicomfile, "w") do io
print(io, "!")
end

# First, test the isdicom() function
fileDX = download_dicom("DX_Implicit_Little_Interleaved.dcm")
@test DICOM.isdicom(fileDX) == true
@test DICOM.isdicom(notdicomfile) == false

# Second, test if all valid dicom file can be parsed
dcms = dcmdir_parse(data_folder)
@test issorted([dcm[tag"Instance Number"] for dcm in dcms])
@test length(dcms) == length(readdir(data_folder)) - 2 # -2 because of note above
@test length(dcms) == length(readdir(data_folder)) - 3 # -3 because of note above
end

@testset "Test tag macro" begin
Expand Down

2 comments on commit cfee5eb

@notZaki
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/50497

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.1 -m "<description of version>" cfee5eb9803244d03d49bccdcbb6e61622d242da
git push origin v0.10.1

Please sign in to comment.