Skip to content
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

Binary resource loses extensions when encoding #504

Closed
TomasSBerg opened this issue Nov 16, 2016 · 1 comment
Closed

Binary resource loses extensions when encoding #504

TomasSBerg opened this issue Nov 16, 2016 · 1 comment

Comments

@TomasSBerg
Copy link

@TomasSBerg TomasSBerg commented Nov 16, 2016

Hey James and friends :o)

As we discussed today in Amsterdam, the Binary resource loses all extensions when it is being encoded by the Parser (only on DSTU2). Have written a test to demonstrate both declared and undeclared extension:

@Test
public void testBinaryEncodingWithKnownExtension() {
    LetterTemplate template = new LetterTemplate();
    template.setName(new StringDt("Testname"));
    template.setContentType(new CodeDt("test-type"));

    IParser parser = FhirContext.forDstu2().newJsonParser();
    String resourceToString = parser.encodeResourceToString(template);
    LetterTemplate resource = parser.parseResource(LetterTemplate.class, resourceToString);
    assertNotNull(resource.getContentType());
    assertNotNull(resource.getName());
}

@Test
public void testBinaryEncodingWithUnknownExtension() {
    Binary template = new Binary();
    String extensionURL = "http://www.something.org/StructureDefinition/letter-template";
    ExtensionDt e = new ExtensionDt(false, extensionURL, new StringDt("Testname"));
    template.getUndeclaredExtensions().add(e);
    template.setContentType(new CodeDt("test-type"));

    IParser parser = FhirContext.forDstu2().newJsonParser();
    String resourceToString = parser.encodeResourceToString(template);
    Binary resource = parser.parseResource(Binary.class, resourceToString);
    assertNotNull(resource.getContentType());
    assertFalse((resource.getUndeclaredExtensionsByUrl(extensionURL).isEmpty()));
    assertNotNull(resource.getUndeclaredExtensionsByUrl(extensionURL).get(0));
}

@ResourceDef(name = "Binary", id = "letter-template", profile = "http://www.something.org/StructureDefinition/letter-template")
public static class LetterTemplate extends Binary {

    @Child(name="name")
    @Extension(url="http://example.com/dontuse#name", definedLocally=false, isModifier=false)
    @Description(shortDefinition="The name of the template")
    private StringDt myName;

    public LetterTemplate() {}

    public void setName(StringDt name) {
        myName = name;
    }

    public StringDt getName() {
        return myName;
    }
}
@jamesagnew
Copy link
Owner

@jamesagnew jamesagnew commented Jan 13, 2017

Hi Tomas,

I did some digging into this one today, and I realized why.. Binary is actually not allowed to have extensions, per FHIR's rules.

The parser should probably emit a warning, so I'll get it to do that though...

jamesagnew added a commit that referenced this issue Jan 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.