# \[ANN\] ODMXMLTools.jl: A simple tools for working with ODM-XML

**URL:** https://discourse.julialang.org/t/ann-odmxmltools-jl-a-simple-tools-for-working-with-odm-xml/76193
**Category:** Package Announcements
**Created:** [February 10, 2022, 9:26pm UTC](https://discourse.julialang.org/t/ann-odmxmltools-jl-a-simple-tools-for-working-with-odm-xml/76193 "2022-02-10T21:26:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [February 10, 2022, 9:26pm UTC](https://discourse.julialang.org/t/ann-odmxmltools-jl-a-simple-tools-for-working-with-odm-xml/76193/1 "2022-02-10T21:26:46Z")

</div>

[ODMXMLTools.jl](https://github.com/PharmCat/ODMXMLTools.jl) is a simple tool set for working with ODM-XML.

[ODM-XML](https://www.cdisc.org/standards/data-exchange/odm) is a vendor-neutral, platform-independent format for exchanging and archiving clinical and translational research data, along with their associated metadata, administrative data, reference data, and audit information. ODM-XML facilitates the regulatory-compliant acquisition, archival and exchange of metadata and data. It has become the language of choice for representing case report form content in many electronic data capture (EDC) tools.

The ODM has been designed to be compliant with guidance and regulations published by the FDA for computer systems used in clinical studies.

See [CDISK](https://www.cdisc.org/) site for more information.

Installation:

```julia
import Pkg; Pkg.add(url="https://github.com/PharmCat/ODMXMLTools.jl.git")

```

With ODMXMLTools.jl you can:

- Import ODM xml file;
- Get table of MetaDataVersion;
- Find study elements;
- Build MetaDataVersion (recursive resolve all includes in MetaDataVersion);
- Get study list;
- Get events table;
- Get forms table;
- Get ItemGroups table;
- Get items table;
- Get study subject information;
- Get study information;
- Get ClinicalData list;
- Get data from ClinicalData in “long” format;

This package currently is not registered because I don’t know would it be in demand.

This package does not validate odm.xml file, but a structure validation procedure may be developed in the future.

This package is not for changing odm.xml file and not writing it.

This program comes with absolutely no warranty. No liability is accepted for any loss and risk to public health resulting from use of this software.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [July 10, 2022, 7:20pm UTC](https://discourse.julialang.org/t/ann-odmxmltools-jl-a-simple-tools-for-working-with-odm-xml/76193/2 "2022-07-10T19:20:46Z")

</div>

Made documentation page with example. Improved API. Made some work on validation and OCL ([OpenClinica](https://www.openclinica.com/)) form details list.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [July 29, 2022, 7:40pm UTC](https://discourse.julialang.org/t/ann-odmxmltools-jl-a-simple-tools-for-working-with-odm-xml/76193/3 "2022-07-29T19:40:14Z")

</div>

New minor version released. More docs and minor changes. Some additional keywords.

See documents: [Home · ODMXMLTools.jl](https://pharmcat.github.io/ODMXMLTools.jl/dev/)

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [January 20, 2023, 11:24am UTC](https://discourse.julialang.org/t/ann-odmxmltools-jl-a-simple-tools-for-working-with-odm-xml/76193/4 "2023-01-20T11:24:16Z")

</div>

Version 0.4.0 released.

There was changes in API to provide more consistent interface.

New feature included: `checkdatavalues` can help to check data inside `ClinicalData` part.

ODMXMLTools.jl is still package that can help to get information about ODM-XML files that used as export, transfer and archiving format for data collected in clinical and pre-clinical trials.

It is simple to load xml file:

```julia
using ODMXMLTools, DataFrames, CSV
odm = importxml(".//data//some-odm-xml.xml")

```

You can build completed metadata (with recurcive including all `Include` tags) for MetaDataVersion by `StudyOID` and `MetaDataVersionOID`. And then you can get listings for events, forms, groups and items:

```julia
mdb = buildmetadata(odm, "S1", "v1.0.0")
forms = formlist(mdb)
items = itemlist(mdb; optional = true)

```

You can also to get all data from all `ClinicalData` sections or by `StudyOID` and `MetaDataVersionOID`.

```julia
datadf = ODMXMLTools.clinicaldatatable(odm)

```

After a simple data management with DataFrames you can make CSV tables for each form and get SPSS code for value labels.

```julia
leftjoin!(datadf, items[!, ["OID", "SASFieldName"]]; on = "ItemOID" => "OID")
for f = 1:size(forms, 1)
    formds = subset(datadf, :FormOID => x -> x .== forms[f, "OID"])[!, [:SubjectKey, :StudyEventOID, :ItemGroupOID, :ItemGroupRepeatKey, :Value, :SASFieldName]]
    replace!(formds[!, :ItemGroupRepeatKey], "" => "1")
    unstfds = unstack(formds, [:SubjectKey, :StudyEventOID, :ItemGroupRepeatKey], :SASFieldName, :Value)

    CSV.write(joinpath(path, "csv", forms[f, :Name]*".csv"), unstfds)

    open(joinpath(path, "csv", forms[f, :Name]*".sps"), "w+") do io
        spslab = ODMXMLTools.spss_form_variable_labels(mdb, forms[f, "OID"]; variable = :SASFieldName, labels = :Comment)
        spsval = ODMXMLTools.spss_form_value_labels(mdb, forms[f, "OID"]; variable = :SASFieldName)
        print(io,"\xEF\xBB\xBF") # BOM
        println(io, "* Encoding: UTF-8.")
        println(io, spslab) 
        if length(spsval.v) > 0 
            println(io, spsval)
        end
        println(io, "EXECUTE.")
    end
end

```

It is very **important** to check your xml files before importing with XSD schema provided by CDISK. There is plan to make more validation checks inside ODMXMLTools, but this is not replace checks with XSD schema. As ODMXMLTools build on EzXML.jl - unfortunatly EzXML not provide checking with XSD. Maybe check with DTD will be included in ODMXMLTools later.

To get full information see [Documentation](https://pharmcat.github.io/ODMXMLTools.jl/stable/). Also issues and PR wellcome!

**An official version of ODM specificatoion document is available on the ODM page of the CDISC website [http://www.cdisc.org/odm.](http://www.cdisc.org/odm.)**
