Skip to content

Commit

Permalink
Merge pull request #19 from PharmCat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
PharmCat authored May 9, 2024
2 parents d5c48da + 9d51ff3 commit bd8e54e
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@latest
with:
version: '1.6.4'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Tier1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
matrix:
version:
- '1.6'
- '1.7'
- '1.8'
- '1'
os:
- ubuntu-latest
- macOS-latest
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
4 changes: 2 additions & 2 deletions 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.3"
version = "0.7.0"

[deps]

Expand All @@ -17,7 +17,7 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
AbstractTrees = "0.3, 0.4"
CategoricalArrays = "0.10"
DataFrames = "1"
EzXML = "1.1"
EzXML = "1.1, 1.2"
julia = "1"

[extras]
Expand Down
4 changes: 0 additions & 4 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ODMXMLTools = "2456a17b-6ca2-4f51-9342-f0287e829718"


[compat]
Documenter = "≥0.26"
ODMXMLTools = "0.6"
43 changes: 43 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ ODMXMLTools.itemquestion
ODMXMLTools.nodedesq
```

## Decode

### ODMXMLTools.codelistitemdecode
```@docs
ODMXMLTools.codelistitemdecode
```

## Delete

### ODMXMLTools.deletestudy!
Expand Down Expand Up @@ -236,4 +243,40 @@ ODMXMLTools.sortelements!
### ODMXMLTools.writenode
```@docs
ODMXMLTools.writenode
```

Other:

### ODMXMLTools.oclformdetailslist
```@docs
ODMXMLTools.oclformdetailslist
```

### ODMXMLTools.countelements
```@docs
ODMXMLTools.countelements
```

### ODMXMLTools.findelementbyattr
```@docs
ODMXMLTools.findelementbyattr
```

### ODMXMLTools.buildelementsdata
```@docs
ODMXMLTools.buildelementsdata
```



## Base

### Base.findall
```@docs
Base.findall
```

### Base.findfirst
```@docs
Base.findfirst
```
2 changes: 1 addition & 1 deletion src/ODMXMLTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ module ODMXMLTools
:UserType
:Value
:Version
:lang
Symbol("xml:lang")
:xmlns])

const ITEMDATATYPE = Set([:ItemDataAny
Expand Down
4 changes: 2 additions & 2 deletions src/nodeinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const NODEINFO = Dict{Symbol, NodeInfo}(
),
:TranslatedText => NodeInfo(:TranslatedText,
[:Decode, :ErrorMessage, :Question, :Symbol, :Description],
Tuple{Symbol, Symbol, Symbol}[(:lang, :?, :languageTag)],
Tuple{Symbol, Symbol, Symbol}[(Symbol("xml:lang"), :?, :languageTag)],
"text"
),
:MetaDataVersion => NodeInfo(:MetaDataVersion,
Expand Down Expand Up @@ -278,7 +278,7 @@ const NODEINFO = Dict{Symbol, NodeInfo}(
),
:Presentation => NodeInfo(:Presentation,
:MetaDataVersion,
[(:OID, :!, :oid), (:lang, :?, :languageTag)],
[(:OID, :!, :oid), (Symbol("xml:lang"), :?, :languageTag)],
"text"
),
:ConditionDef => NodeInfo(:ConditionDef,
Expand Down
57 changes: 44 additions & 13 deletions src/odmxml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,20 @@ function makenode(str, attr)
return ODMNode(Symbol(str), attr)
end
=#
function attributes_dict(n)
function attributes_dict(n, ns)
d = Dict{Symbol, String}()
for i in eachattribute(n)
d[Symbol(i.name)] = i.content
end
attributes_dict!(d, root, n)
d
end
function attributes_dict!(d, n)
for i in eachattribute(n)
d[Symbol(i.name)] = i.content
function attributes_dict!(d, ns, n)
for i in EzXML.attributes(n)
if EzXML.hasnamespace(i)
pref = ns[EzXML.namespace(i)]
k = Symbol(string(pref)*":"*i.name)
else
k = Symbol(i.name)
end
d[k] = i.content
end
d
end
Expand All @@ -109,11 +113,12 @@ function importxml(file::AbstractString)
nsv = namespaces(xodm)
if EzXML.hasnamespace(xodm)
nsv = namespaces(xodm)
push!(nsv, "xml" => "http://www.w3.org/XML/1998/namespace" )
else
nsv = ["" => ""]
nsv = ["xml" => "http://www.w3.org/XML/1998/namespace"]
end
ns = Dict([p[2] => Symbol(p[1]) for p in nsv]...)
odm = ODMRoot(attributes_dict(xodm), ns)
odm = ODMRoot(attributes_dict(xodm, ns), ns)
importxml_(odm, xodm, ns)
odm
end
Expand All @@ -125,7 +130,7 @@ function importxml_(parent, root, ns)
content = nothing
attr = Dict{Symbol, String}()
#if iselement(c)
attributes_dict!(attr, c)
attributes_dict!(attr, ns, c)
if !haselement(c)
tv = EzXML.eachnode(root)
for t in tv
Expand Down Expand Up @@ -1058,7 +1063,7 @@ function codelisttable(cd::AbstractODMNode; lang = "en")
text = content(first(tn))
if length(tn) > 1
for i = 2:length(tn)
if attribute(tn[i], :lang) == lang
if attribute(tn[i], Symbol("xml:lang")) == lang
text = content(tn[i])
break
end
Expand All @@ -1076,10 +1081,31 @@ function codelisttable(cd::AbstractODMNode; lang = "en")
df
end

"""
codelistitemdecode(cli; lang = nothing, nolangerr = true, nolangval = "")
Return TranslatedText content for Decode node.
"""
function codelistitemdecode(cli; lang = nothing, nolangerr = true, nolangval = "")
if name(cli) != :CodeListItem error("Wrong node name ($(name(cli)), not CodeListItem)") end
decodenode = findelement(cli, :Decode)
if isnothing(decodenode) error("No Decode node in CodeListItem") end
t = findelements(decodenode, :TranslatedText)
if length(t) == 0 error("No TranslatedText node in Decode") end
if isnothing(lang)
return content(first(t))
else
for tv in t
if attribute(tv, :lang) == lang return content(first(tv)) end
end
end
if nolangerr error("No TranslatedText for lang $lang found") end
return nolangval
end
"""
itemcodelisttable(cd::AbstractODMNode; lang = nothing) where T <: AbstractODMNode
Same as `codelisttable`, but return ItemDef.
Same as `codelisttable`, but return ItemDef (DataFrame).
"""
function itemcodelisttable(cd::AbstractODMNode; lang = nothing)
df = DataFrame(OID = String[], CodeListOID = String[], Name = String[], DataType = String[], Type = String[], CodedValue = String[], Rank = Union{Missing, String}[], OrderNumber = Union{Missing, String}[], Text = String[])
Expand All @@ -1096,7 +1122,7 @@ function itemcodelisttable(cd::AbstractODMNode; lang = nothing)
text = content(first(tn))
if length(tn) > 1
for i = 2:length(tn)
if attribute(tn[i], :lang) == lang
if attribute(tn[i], Symbol("xml:lang")) == lang
text = content(tn[i])
break
end
Expand All @@ -1117,6 +1143,11 @@ 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
6 changes: 5 additions & 1 deletion src/spss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ end
"""
spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name, source = :attr, lang = nothing)
SPSS command to set variable labels.
SPSS command to set variable labels:
```VARIABLE LABELS variable 'labels'.```
`variable` - varable names attribute, `OID` by default.
Expand All @@ -68,6 +70,8 @@ If `source` == `:Question` - try to get description from `TranslatedText` of `Qu
If `source` == `:Description` - try to get description from `TranslatedText` of `Description` element.
"""
function spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name, source = :attr, lang = nothing)
df = itemformdefcontent_(mdb, form; optional = true)
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,14 @@ using EzXML
doc = EzXML.readxml(joinpath(dirname(@__FILE__), "test.xml"))
dtdn = EzXML.readdtd(joinpath(dirname(@__FILE__), "test-schema.dtd"))
EzXML.validate(doc, dtdn)
=#


#=
txt = """<?xml version="1.0" encoding="UTF-8"?>
<t1>
<t2 xml:name="Homo"></t2>
<t2 b:name="Homo"></t2>
</t1>"""
root(EzXML.parsexml(txt));
=#
14 changes: 8 additions & 6 deletions test/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,26 @@
<CodeList OID="CL_1" Name="Race codelist" DataType="integer" SASFormatName="CL_1">
<CodeListItem CodedValue="1">
<Decode>
<TranslatedText>Asian</TranslatedText>
<TranslatedText xml:lang = "en-US">Asian</TranslatedText>
<TranslatedText xml:lang = "ru">Азиатская</TranslatedText>
</Decode>
</CodeListItem>
<CodeListItem CodedValue="2">
<Decode>
<TranslatedText>Caucasian</TranslatedText>
<TranslatedText xml:lang = "en-US">Caucasian</TranslatedText>
<TranslatedText xml:lang = "ru">Европеоидная</TranslatedText>
</Decode>
</CodeListItem>
</CodeList>
<CodeList OID="CL_2" Name="Sex codelist" DataType="string" SASFormatName="CL_2">
<CodeListItem CodedValue="M">
<Decode>
<TranslatedText>Male</TranslatedText>
<TranslatedText xml:lang = "en-US">Male</TranslatedText>
</Decode>
</CodeListItem>
<CodeListItem CodedValue="F">
<Decode>
<TranslatedText>Female</TranslatedText>
<TranslatedText xml:lang = "en-US">Female</TranslatedText>
</Decode>
</CodeListItem>
</CodeList>
Expand All @@ -154,12 +156,12 @@
<CodeList OID="CL_2" Name="Sex codelist" DataType="integer" SASFormatName="CL_2">
<CodeListItem CodedValue="1">
<Decode>
<TranslatedText>Male</TranslatedText>
<TranslatedText xml:lang = "en-US">Male</TranslatedText>
</Decode>
</CodeListItem>
<CodeListItem CodedValue="2">
<Decode>
<TranslatedText>Female</TranslatedText>
<TranslatedText xml:lang = "en-US">Female</TranslatedText>
</Decode>
</CodeListItem>
</CodeList>
Expand Down

2 comments on commit bd8e54e

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

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.7.0 -m "<description of version>" bd8e54e5f7c96f19c588a2a3c47d638c661d9d0d
git push origin v0.7.0

Please sign in to comment.