mdht / mdht-models

This branch supports Rational Software components
24 stars 18 forks source link

Order of header templateIds matters though shouldn't #128

Open naXa777 opened 6 years ago

naXa777 commented 6 years ago

I'm not sure if this is a real issue. I just find it confusing.

Clinical document A

<ClinicalDocument ...>
   ...
   <templateId root="2.16.840.1.113883.10.20.22.1.1"/>
   <templateId root="2.16.840.1.113883.10.20.22.1.2"/>
   ...

Clinical document B

<ClinicalDocument ...>
   ...
   <templateId root="2.16.840.1.113883.10.20.22.1.2"/>
   <templateId root="2.16.840.1.113883.10.20.22.1.1"/>
   ...

Both clinical documents have identical content and declare conformance to the US Realm Header template and to the C-CDA CCD document template. But when loaded by MDHT they have different types:

import org.eclipse.mdht.uml.cda.ClinicalDocument;
import org.eclipse.mdht.uml.cda.util.CDAUtil;
import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
    ...
    CDAUtil.loadPackages();
    final ClinicalDocument doc_A = CDAUtil.load(new FileInputStream("A.xml"));
    final ClinicalDocument doc_B = CDAUtil.load(new FileInputStream("B.xml"));

    assertThat(doc_B, instanceOf(ContinuityOfCareDocument.class));   // ok
    assertThat(doc_A, instanceOf(ContinuityOfCareDocument.class));   // fail (AssertionError)

Error:

java.lang.AssertionError: 
Expected: an instance of org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument
     but: <org.openhealthtools.mdht.uml.cda.mu2consol.impl.GeneralHeaderConstraintsImpl@52231f30 (nullFlavor: <unset>, classCode: <unset>, moodCode: <unset>)> is a org.openhealthtools.mdht.uml.cda.mu2consol.impl.GeneralHeaderConstraintsImpl

I have consol2 and mu2consol dependencies in pom.xml.

    <dependency>
        <groupId>org.openhealthtools.mdht.cda</groupId>
        <artifactId>org.openhealthtools.mdht.uml.cda.consol2</artifactId>
    </dependency>

    <!-- Note: if I remove mu2consol then both docs are loaded as ContinuityOfCareDocument -->
    <dependency>
        <groupId>org.openhealthtools.mdht.cda</groupId>
        <artifactId>org.openhealthtools.mdht.uml.cda.mu2consol</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
drbgfc commented 6 years ago

This is a really interesting find. I have not verified it yet but thanks for letting us know and having it so well documented. Will look into it in time.

swmuir commented 6 years ago

This is where that logic happens

org.eclipse.mdht.uml.cda.internal.resource.CDAXSITypeProvider.getXSIType(Element)

  for (int i = 0; i < nodeList.getLength(); i++) {
      if (nodeList.item(i) instanceof Element) {
          Element e = (Element) nodeList.item(i);
          if ("templateId".equals(e.getLocalName())) {
              EClass eClass = getEClass(
                  e.getAttributeNS(null, "root"), e.getAttributeNS(null, "extension"), element);
              if ((eClass != null) && !eClass.isAbstract() && conformsTo(eClass, type) &&
                      (eClass.getEAllSuperTypes().size() > last)) {
                  result = eClass;
                  last = eClass.getEAllSuperTypes().size();
              }
          }
      }
  }

I have not debugged it but should the general header document template id be abstract within the cda runtime ?

On Jun 1, 2018, at 8:50 AM, Dan Brown notifications@github.com wrote:

This is a really interesting find. I have not verified it yet but thanks for letting us know and having it so well documented. Will look into it in time.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mdht/mdht-models/issues/128#issuecomment-393923030, or mute the thread https://github.com/notifications/unsubscribe-auth/AFGeFyrBbgcF0a_0UXPW49k2P7-KLkJcks5t4WLSgaJpZM4Tydf_.