New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeDt parsing issue #350

Closed
ykovbtc opened this Issue Apr 26, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@ykovbtc

ykovbtc commented Apr 26, 2016

The DateTimeDt field is lost during parse operation.

WARN c.u.fhir.parser.LenientErrorHandler [LenientErrorHandler.java:56] - Unknown element 'abatement' found while parsing

There is a unit test for XmlParserDstu2Test.java:

@ResourceDef(name="Condition", profile="http://hl7.org/fhir/profiles/custom-condition", id="custom-condition")
    public static class CustomCondition extends Condition {
        @Child(name = "abatement", min = 0, max = 1, order = Child.REPLACE_PARENT, type = {DateTimeDt.class}, summary = true)
        private DateTimeDt ourAbatement;

        public DateTimeDt getOurAbatement() {
            return ourAbatement;
        }

        void setOurAbatement(DateTimeDt ourAbatement) {
            this.ourAbatement = ourAbatement;
        }
    }

    @Test
    public void testEncodeAndParseDateTimeDt() {
        FhirContext myCtx = FhirContext.forDstu2();
        myCtx.setDefaultTypeForProfile("http://hl7.org/fhir/profiles/custom-condition", CustomCondition.class);
        IParser parser = myCtx.newXmlParser();

        CustomCondition condition = new CustomCondition();
        condition.setOurAbatement(new DateTimeDt(new Date()));

        String conditionXml = parser.encodeResourceToString(condition);
        CustomCondition parsedCondition = (CustomCondition) parser.parseResource(conditionXml);
        assertNotNull(parsedCondition.getOurAbatement());
    }
@ykovbtc

This comment has been minimized.

ykovbtc commented Apr 27, 2016

works if I use IDatatype instead of DateTimeDt in field declaration section

@Child(name = "abatement", min = 0, max = 1, order = Child.REPLACE_PARENT, type = {DateTimeDt.class}, summary = true)
        private IDatatype ourAbatement;
@jamesagnew

This comment has been minimized.

Owner

jamesagnew commented Apr 28, 2016

Ahh interesting. If you use a more specific datatype (DateTimeDt) than the parent field (IDatatype) then HAPI "forgets" that this is a choice type and emits the wrong attribute name when serializing (abatement instead of abatementDateTime).

Thanks for reporting! This is an easy fix, should have something checked in within the next day or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment