cdisc-org / DataExchange-ODM

ODM repository
MIT License
7 stars 1 forks source link

error reading retrieval from FHIR in ODM example #58

Open DiTo97 opened 6 months ago

DiTo97 commented 6 months ago

Hello,

any idea why the following error pops up?

from odmlib import odm_loader, loader

def load_study_odm_v2_0(filepath: str):
    engine = loader.ODMLoader(odm_loader.XMLODMLoader(
        model_package="odm_2_0", ns_uri="http://www.cdisc.org/ns/odm/v2.0")
    )
    engine.open_odm_document(filepath)

    return engine.load_odm()

load_study_odm_v2_0("example.xml")

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
[<ipython-input-64-1a86b7ad92d6>](https://localhost:8080/#) in <cell line: 1>()
----> 1 load_study_odm_v2_0("example.xml")

10 frames
[<ipython-input-63-b0aedd3594d7>](https://localhost:8080/#) in load_study_odm_v2_0(filepath)
      1 def load_study_odm_v2_0(filepath: str):
----> 2     engine = loader.ODMLoader(odm_loader.XMLODMLoader(
      3         model_package="odm_2_0", ns_uri="http://www.cdisc.org/ns/odm/v2.0")
      4     )
      5     engine.open_odm_document(filepath)

[/usr/local/lib/python3.10/dist-packages/odmlib/odm_loader.py](https://localhost:8080/#) in __init__(self, model_package, ns_uri, local_model)
     75             self.ODM = importlib.import_module(f"{model_package}.model")
     76         else:
---> 77             self.ODM = importlib.import_module(f"odmlib.{model_package}.model")
     78         self.nsr = NS.NamespaceRegistry()
     79 

[/usr/lib/python3.10/importlib/__init__.py](https://localhost:8080/#) in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

/usr/lib/python3.10/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.10/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.10/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.10/importlib/_bootstrap.py in _load_unlocked(spec)

/usr/lib/python3.10/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.10/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

[/usr/local/lib/python3.10/dist-packages/odmlib/odm_2_0/model.py](https://localhost:8080/#) in <module>
     54 
     55 
---> 56 class StudyEventDef(OE.ODMElement):
     57     """ represents ODM v2.0 StudyEventDef and can serialize as JSON or XML """
     58     OID = T.OID(required=True)

[/usr/local/lib/python3.10/dist-packages/odmlib/odm_2_0/model.py](https://localhost:8080/#) in StudyEventDef()
     62     Category = T.String(required=False)
     63     Description = T.ODMObject(element_class=Description)
---> 64     ItemGroupRef = T.ODMListObject(element_class=ItemGroupRef)
     65     WorkflowRef = T.ODMListObject(element_class=WorkflowRef)
     66     Alias = T.ODMListObject(element_class=Alias)

NameError: name 'ItemGroupRef' is not defined

where example.xml is the provided example for retrieval from FHIR in ODM v2.0.

DiTo97 commented 6 months ago

Any pointers on the error?

swhume commented 6 months ago

odmlib does not yet support ODM v2.0. That said, I'll take a look at the example and will let you know what's causing the problem.

lexjansen commented 6 months ago

I had a quick look at the example. The code ran for me after I:

DiTo97 commented 6 months ago

I had a quick look at the example. The code ran for me after I:

  • moved the ItemGroupRef and WorkFlowRef classes before the StudyEventDef class in odmlib/odm_2_0/model.py
  • added "2.0" to ODM.ODMVersion in value_set.py

Thanks a lot, @lexjansen.

I will test it out with those modifications later and see if it works as expected; will report back!

DiTo97 commented 6 months ago

@lexjansen, error seems solved in terms of not raising an exception, but not in terms of content.

I am not sure if you have tried to read the content of the loaded ODM v2.0 study trial, but says it is empty (no studies), while the example XML definition clearly contains a study definition inside. I would say, we are still halfway there.

lexjansen commented 6 months ago

@DiTo97 That's good. But like Sam mentioned, the current odmlib is based on an early draft version of the ODM v2.0 schema. The example you took is based on the final schema. These changes just solved the error. I have not looked further,