Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jan 19, 2023
1 parent aed2d61 commit 790de0e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 198 deletions.
13 changes: 9 additions & 4 deletions src/nodeinfo.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
struct NodeInfo
val
parent
attrs
body
val::Symbol
parent::Symbol
attrs::Vector
body::Union{Vector, String}
end

function attps(s::Symbol)
Expand Down Expand Up @@ -52,6 +52,11 @@ const NODEINFO = Dict{Symbol, NodeInfo}(
:ODM,
[(:OID, :!, "OID")],
[(:GlobalVariables, :!), (:BasicDefinitions, :?), (:MetaDataVersion, :*)]
),
:GlobalVariables => NodeInfo(:GlobalVariables,
:Study,
[],
[(:StudyName, :!), (:StudyDescription, :!), (:ProtocolName, :!)]
)

)
123 changes: 3 additions & 120 deletions src/odmxml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ struct ODMRoot <: AbstractODMNode
end
end

#=
struct ODMTextNode <: AbstractODMNode
content::String
end
=#

struct StudyMetaData <: AbstractODMNode
metadata::ODMNode
el::Vector{AbstractODMNode}
Expand All @@ -53,30 +47,11 @@ end
function Base.show(io::IO, n::StudyMetaData)
print(io, "Completed Study MetaData ($(length(n.el)) elements), OID: $(attribute(n.metadata, :OID)), Name: $(attribute(n.metadata, :Name))")
end
#=
function Base.show(io::IO, n::ODMTextNode)
print(io, "Text Node")
end
=#

function AbstractTrees.children(x::T) where T <: AbstractODMNode
x.el
end
#=
function AbstractTrees.children(::ODMTextNode)
[]
end
=#
#=
function AbstractTrees.childtype(n::AbstractODMNode)
eltype(n.el)
end
=#
#=
function AbstractTrees.ischild(node1::AbstractODMNode, node2::AbstractODMNode; equiv=(===))
in(node1, node2.el)
end
=#

function AbstractTrees.isroot(x::ODMRoot)
true
end
Expand All @@ -90,11 +65,7 @@ function makenode(str, attr)
#symb = Symbol(str)
return ODMNode(Symbol(str), attr)
end
#=
function makenode(content::String)
return ODMTextNode(content)
end
=#

function attributes_dict(n)
d = Dict{Symbol, String}()
for i in eachattribute(n)
Expand Down Expand Up @@ -167,16 +138,7 @@ end
function name(n::ODMNode)
getfield(n, :name)
end
#=
function name(n::ODMTextNode)
nothing
end
=#
#=
function havename(node::AbstractODMNode)
!isa(node, ODMTextNode)
end
=#

isMetaDataVersion(node::AbstractODMNode) = name(node) == :MetaDataVersion
isStudy(node::AbstractODMNode) = name(node) == :Study

Expand All @@ -188,7 +150,6 @@ isItemGroupData(node::AbstractODMNode) = name(node) == :ItemGroupData
isItemData(node::AbstractODMNode) = name(node) == :ItemData
isItemDataType(node::AbstractODMNode) = name(node) in ITEMDATATYPE


function have_attr(n::AbstractODMNode, attr::Symbol)
if haskey(getfield(n, :attr), attr) return true else return false end
end
Expand All @@ -213,11 +174,6 @@ function appendelements!(inds::AbstractVector, n::AbstractODMNode, nname::Union{
inds
end

#=
function content(n::ODMTextNode)
getfield(n, :content)
end
=#
function content(n::AbstractODMNode)
n.content
end
Expand Down Expand Up @@ -545,14 +501,6 @@ function itemgrouplist(el::Vector{T}; optional = false, attrs = nothing, categ =
end
end
df = df_list(el, :ItemGroupDef, attrs)
#=
df = DataFrame(Matrix{Union{Missing, String}}(undef, 0, length(attrs)), t_collect(attrs))
for i in el
if name(i) == :ItemGroupDef
push!(df, attributes(i, attrs))
end
end
=#
if categ && :OID in attrs
transform!(df, :OID => categorical, renamecols=false)
end
Expand Down Expand Up @@ -726,19 +674,6 @@ function buildmetadata(odm::ODMRoot, moid::AbstractString)
fillstmd_(stmd.el, stmd.metadata, odm)
stmd
end
#=
"""
buildmetadata(mdat::AbstractODMNode)
Build MetaData from MetaDataVersion mdat.
"""
function buildmetadata(mdat::AbstractODMNode)
if name(cd) != :MetaDataVersion error("This is not MetaDataVersion") end
stmd = StudyMetaData(mdat, AbstractODMNode[])
fillstmd_(stmd.el, stmd.metadata, odm)
stmd
end
=#

"""
codelisttable(cd::AbstractODMNode; lang = nothing) where T <: AbstractODMNode
Expand Down Expand Up @@ -800,7 +735,6 @@ function itemcodelisttable(cd::AbstractODMNode; lang = nothing)
df
end


function dfpush!(df, s, e, f, g, i, null)
push!(df, (s,
attribute(e, :StudyEventOID),
Expand Down Expand Up @@ -850,11 +784,6 @@ function clinicaldatatable(cd::AbstractODMNode;
datatype = String
#df = DataFrame(SubjectKey = String[], StudyEventOID = CategoricalArray(String[]), FormOID = CategoricalArray(String[]), ItemGroupOID = CategoricalArray(String[]), ItemGroupRepeatKey = CategoricalArray(String[]), ItemOID = CategoricalArray(String[]), Value = String[])
df = DataFrame(SubjectKey = String[], StudyEventOID = String[], StudyEventRepeatKey = String[], FormOID = String[], FormRepeatKey = String[], ItemGroupOID = String[], ItemGroupRepeatKey = String[], ItemOID = String[], Value = datatype[])
#sdl = findelements(cd, :SubjectData)
#edl = ODMNode[]
#fdl = ODMNode[]
#gdl = ODMNode[]
#idl = ODMNode[]
if isnothing(idlnames)
idlnames = pushfirst!(collect(ITEMDATATYPE), :ItemData)
end
Expand Down Expand Up @@ -898,50 +827,6 @@ function clinicaldatatable(cd::AbstractODMNode;
end
end
end

#=
for s in sdl
if addstudyid
subjid = attribute(cd, :StudyOID)*"_"*attribute(s, :SubjectKey)
else
subjid = attribute(s, :SubjectKey)
end
resize!(edl, 0)
appendelements!(edl, s, :StudyEventData)
for e in edl
resize!(fdl, 0)
appendelements!(fdl, e, :FormData)
for f in fdl
resize!(gdl, 0)
appendelements!(gdl, f, :ItemGroupData)
for g in gdl
if !isnothing(itemgroup)
if attribute(g, :ItemGroupOID) != itemgroup continue end
end
if !isnothing(form)
if attribute(f, :FormOID) != form continue end
end
resize!(idl, 0)
appendelements!(idl, g, idlnames)
for i in idl
if !isnothing(item)
if !(attribute(i, :ItemOID) in item) continue end
end
push!(df, (subjid,
attribute(e, :StudyEventOID),
attribute(e, :StudyEventRepeatKey),
attribute(f, :FormOID),
attribute(f, :FormRepeatKey),
attribute(g, :ItemGroupOID),
attribute(g, :ItemGroupRepeatKey),
attribute(i, :ItemOID),
getitemdatavalue(i, null)))
end
end
end
end
end
=#
if categ
transform!(df, :StudyEventOID => categorical, renamecols=false)
transform!(df, :FormOID => categorical, renamecols=false)
Expand Down Expand Up @@ -993,7 +878,6 @@ function clinicaldatatable(odm::ODMRoot, inds::AbstractVector{Int}; kwargs...)
df
end


"""
clinicaldatatable(odm::ODMRoot, range::UnitRange{Int64}; kwargs...)
Expand Down Expand Up @@ -1042,7 +926,6 @@ end
clinicaldatatable(odm::ODMRoot, soid::AbstractString; kwargs...)
Return clinical data table in long formal.
"""
function clinicaldatatable(odm::ODMRoot, soid::AbstractString; kwargs...)
cld = findclinicaldata(odm, soid)
Expand Down
74 changes: 0 additions & 74 deletions src/spss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,78 +132,4 @@ function spss_events_value_labels(mdb; variable = "StudyEventOID", value::Symbol
end
SPSSValueLabels([variable => p])
end
#=
struct SPSSExport
df::DataFrame
code::String
end
function spssexportbyitemgroup(odm::ODMRoot, soid::AbstractString, moid::AbstractString)
cld = findclinicaldata(odm, soid, moid)
bmd = buildmetadata(odm, soid, moid)
cldtab = clinicaldatatable(cld)
evlist = eventlist(bmd)
iglist = itemgrouplist(bmd; optional = true)
items = itemlist(bmd; optional = true)
############################################################################
code = """GET
FILE='filename.sav'.
DATASET NAME main WINDOW=FRONT.
"""
uiglist = unique(cldtab[!, :ItemGroupOID])
leftjoin!(cldtab, items[!, ["OID", "SASFieldName"]]; on = "ItemOID" => "OID")
for ig in eachrow(iglist)
if ig[:OID] in uiglist
igc = itemgroupcontent(bmd, ig.OID; optional = true)
code *= """
DATASET ACTIVATE main.
DATASET COPY sample WINDOW=HIDDEN.
DATASET ACTIVATE sample.
SELECT IF (ItemGroupOID = '$(ig[:OID])').
EXECUTE.
RENAME VARIABLE (ItemOID = IOID).
SORT CASES BY SubjectKey StudyEventOID IOID.
CASESTOVARS
/ID=SubjectKey StudyEventOID
/INDEX=IOID
/GROUPBY=VARIABLE.

"""
for i in eachrow(igc)
code *= """RENAME VARIABLE (Value.$(i.OID) = $(i.SASFieldName)).\n"""
end
code *= """VARIABLE LABELS"""
for i in eachrow(igc)
code *= """\n $(i.SASFieldName) '$(i.Comment)'"""
end
code *= """.\n"""
for i in eachrow(igc)
itemdef = findelement(bmd, :ItemDef, i.OID)
if countelements(itemdef, :CodeListRef) > 0
codelist = findelements(itemdef, :CodeListRef)
code *= """VALUE LABELS $(i.SASFieldName)"""
for cl in codelist
cldef = findelement(bmd, :CodeList, attribute(cl, "CodeListOID"))
for clel in cldef.el
if name(clel) == :CodeListItem
code *= """\n '$(attribute(clel, "CodedValue"))' '$(findelement(findelement(clel, :Decode), :TranslatedText).el[1].content)'"""
end
end
end
code *= """.\n"""
end
end
code *= """SAVE OUTFILE=
'$(ig[:OID]).sav'
/COMPRESSED.
DATASET CLOSE sample. \n"""
end
end
SPSSExport(cldtab, code)
end
=#
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,5 @@ using Test
#@test ODMXMLTools.ischild(c[1], odm)

@test_nowarn show(io, ODMXMLTools.NODEINFO[:Study])
@test_nowarn show(io, ODMXMLTools.NODEINFO[:GlobalVariables])
end

0 comments on commit 790de0e

Please sign in to comment.