Skip to content

Commit

Permalink
Merge pull request #17 from PharmCat/dev
Browse files Browse the repository at this point in the history
makenode! + fix
  • Loading branch information
PharmCat committed Apr 13, 2023
2 parents a9b9a30 + 162df82 commit 3cc58cb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ODMXMLTools"
uuid = "2456a17b-6ca2-4f51-9342-f0287e829718"
authors = ["PharmCat <[email protected]>"]
version = "0.6.1"
version = "0.6.2"

[deps]

Expand Down
1 change: 1 addition & 0 deletions src/checknode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ function checkdatavalues(odm::ODMRoot)
end
if isnothing(pval)
pushlog!(log, :WARN, s, e, f, g, i, "DataType is $(itype), but value `$val` can't be parsed.")
continue
end
# CODE LIST CHECK
clr = findelement(idef, :CodeListRef)
Expand Down
51 changes: 50 additions & 1 deletion src/odmxml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,58 @@ function df_list(el::Vector{T}, nname::Symbol, attrs) where T <: AbstractODMNode
df
end

################################################################################
# MAKE NODE
################################################################################
function mekenode!(root::AbstractODMNode, nname::Symbol, attrs::Dict = Dict(); content = nothing, namespace = Symbol(""), checkname = false, checkni = false)
if checkname
if nname ODMNAMESPACE error("Name $nname not in ODMNAMESPACE!") end
end
if checkni
ni = NODEINFO[name(root)]
if isa(ni.body, AbstractString) || isnothing(ni.body) error("Node can not be added to $(name(root))!") end
nifail = true
for e in ni.body
if isa(e, NodeXOR)
for j in e.val
if j[1] == nname
nifail = false
break
end
end
else
if e[1] == nname nifail = false end
end
if !nifail break end
end
if nifail error("Node can not be added to $(name(root))! See `ODMXMLTools.NODEINFO[:$(name(root))]`") end
end
newnode = ODMNode(nname, attrs, content, namespace)
push!(root.el, newnode)
newnode
end

################################################################################
# BASIC FUNCTIONS
################################################################################
"""
findelementbyattr(el::AbstractVector{<:AbstractODMNode}, nname::Symbol, attr::Symbol, value::AbstractString)
Find first element by node name `nname` with attribute `attr` equal `value`.
"""
function findelementbyattr(el::AbstractVector{<:AbstractODMNode}, nname::Symbol, attr::Symbol, value::AbstractString)
for i in el
if i.name == nname
if hasattribute(i, attr)
if attribute(i, attr) == value return i end
end
end
end
end

function findelementbyattr(n::AbstractODMNode, nname::Symbol, attr::Symbol, value::AbstractString)
findelementbyattr(n.el, nname, attr, value)
end
# First element
"""
findelement(el::AbstractVector{AbstractODMNode}, nname::Symbol, oid::AbstractString)
Expand Down Expand Up @@ -1508,7 +1557,7 @@ function writenode(io::IO, node::AbstractODMNode, sp::Int)
end
println(io, "</$(name(node))>")
else
println(io, " />")
println(io, "/>")
end
end

Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ using Test
@test ODMXMLTools.isroot(odm) == true
@test ODMXMLTools.isroot(c[1]) == false

# Make node and add to root

cld = ODMXMLTools.mekenode!(odm, :ClinicalData, Dict(:StudyOID => "S1", :MetaDataVersionOID => "MD.1"))
@test ODMXMLTools.name(cld) == :ClinicalData
@test ODMXMLTools.attribute(cld, :StudyOID) == "S1"
@test ODMXMLTools.attribute(cld, :MetaDataVersionOID) == "MD.1"
@test ODMXMLTools.name(cld) == :ClinicalData
cdel = ODMXMLTools.findelements(odm, :ClinicalData)
@test length(cdel) == 2
#@test ODMXMLTools.ischild(c[1], odm)
# Node information

Expand Down

2 comments on commit 3cc58cb

@PharmCat
Copy link
Owner Author

Choose a reason for hiding this comment

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

@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/81538

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.6.2 -m "<description of version>" 3cc58cb76222f7f41775232d5469b1f149062580
git push origin v0.6.2

Please sign in to comment.