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

Type null does not support undeclared extentions #299

Closed
am202 opened this issue Feb 19, 2016 · 1 comment
Closed

Type null does not support undeclared extentions #299

am202 opened this issue Feb 19, 2016 · 1 comment

Comments

@am202
Copy link

am202 commented Feb 19, 2016

I'm working on a Location matching project, similar to what's described in the "Patient Matching using an MPI" section here:
http://hl7.org/fhir/patient.html#match

Here's a simple provider that always returns the same Location:

public final class LocationProvider implements IResourceProvider {
    @Override
    public final Class<Location> getResourceType() {
        return Location.class;
    }

    @Search(queryName="match")
    public Bundle getMatches(final @RequiredParam(name = Location.SP_NAME) StringParam name, final @Count Integer count) {
        final Bundle bundle = new Bundle();
        final Location location = new Location();
        location.setId(new IdDt(1));
        location.setName("Sample Clinic");
        final Entry entry = new Entry();
        final EntrySearch search = new EntrySearch();
        search.setScore(new BigDecimal(0.8));
        search.addUndeclaredExtension(new ExtensionDt(false, "http://hl7.org/fhir/StructureDefinition/algorithmic-match", new CodeDt("probable")));
        entry.setSearch(search);
        entry.setResource(location);
        bundle.addEntry(entry);
        return bundle;
    }
}

Here's a response:

<Bundle xmlns="http://hl7.org/fhir"><id value="f61f6ddc-95e8-4ef9-a4cd-17c79bbb74f3"></id><meta><lastUpdated value="2016-02-19T12:04:02.616-05:00"></lastUpdated></meta><type value="searchset"></type><link><relation value="self"></relation><url value="http://localhost:8081/hapi-fhir/fhir/Location?name=Sample+Clinic&amp;_query=match"></url></link><entry><resource><Location xmlns="http://hl7.org/fhir"><id value="1"></id><name value="Sample Clinic"></name></Location></resource><search><extension url="http://hl7.org/fhir/StructureDefinition/algorithmic-match"><valueCode value="probable"></valueCode></extension><score value="0.8000000000000000444089209850062616169452667236328125"></score></search></entry></Bundle>SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

I tried running this code to invoke it:

    public interface LocationClient extends IRestfulClient {
        @Search(queryName="match")
        public List<Location> getMatches(final @RequiredParam(name = Location.SP_NAME) StringParam name, final @Count Integer count);
    }

    private void run(final String url) {
        final FhirContext ctx = FhirContext.forDstu2();
        final LocationClient client = ctx.newRestfulClient(LocationClient.class, url);
        client.getMatches(new StringParam("Sample Clinic"), Integer.valueOf("5"));
    }

I get this error:

Exception in thread "main" ca.uhn.fhir.parser.DataFormatException: DataFormatException at [Line number = 1
Column number = 562
System Id = null
Public Id = null
Location Uri= null
CharacterOffset = 561
]: Type null does not support undeclared extentions, and found an extension with URL: http://hl7.org/fhir/StructureDefinition/algorithmic-match
    at ca.uhn.fhir.parser.XmlParser.doXmlLoop(XmlParser.java:250)
    at ca.uhn.fhir.parser.XmlParser.parseBundle(XmlParser.java:1035)
    at ca.uhn.fhir.parser.XmlParser.parseBundle(XmlParser.java:1030)
    at ca.uhn.fhir.rest.method.BaseResourceReturningMethodBinding.invokeClient(BaseResourceReturningMethodBinding.java:162)
    at ca.uhn.fhir.rest.client.BaseClient.invokeClient(BaseClient.java:358)
    at ca.uhn.fhir.rest.client.BaseClient.invokeClient(BaseClient.java:185)
    at ca.uhn.fhir.rest.client.BaseClient.invokeClient(BaseClient.java:181)
    at ca.uhn.fhir.rest.client.ClientInvocationHandler.invoke(ClientInvocationHandler.java:63)
    at $Proxy12.getMatches(Unknown Source)
    at org.regenstrief.registry.fhir.RegistryFhirClient.run0(RegistryFhirClient.java:55)
    at org.regenstrief.registry.fhir.RegistryFhirClient.run(RegistryFhirClient.java:41)
    at org.regenstrief.registry.fhir.RegistryFhirClient.main(RegistryFhirClient.java:35)
Caused by: ca.uhn.fhir.parser.DataFormatException: Type null does not support undeclared extentions, and found an extension with URL: http://hl7.org/fhir/StructureDefinition/algorithmic-match
    at ca.uhn.fhir.parser.ParserState$BaseState.enteringNewElementExtension(ParserState.java:842)
    at ca.uhn.fhir.parser.ParserState.enteringNewElementExtension(ParserState.java:117)
    at ca.uhn.fhir.parser.XmlParser.doXmlLoop(XmlParser.java:213)
    ... 11 more

My response looks valid to me. It also looks consistent with the http://hl7.org/fhir/patient.html#match sample response.

Do you see anything wrong with the response? Is something wrong with my server code?

The "Type null does not support" error seems strange to me. It's like it finds the extension but loses track of which element contains the extension, causing it to say "Type null".

I tried running a response through FhirContext.forDstu2().newXmlParser().parseResource manually, and that worked with no error. So maybe there's something slightly different about how the RESTful client parses it.

I'm using HAPI FHIR 1.4.

@jamesagnew
Copy link
Collaborator

Hi @am202 - I had a look at this and you're right, extensions in that position seem to cause an issue with the client.

I'm checking in a fix now, so this should work as of the next 1.5-SNAPSHOT build. Are you in a position to use snapshots?

One other thing to note though, you'll probably want to adjust your search method to return Bundle instead of List<Location> so that you can actually get to the extensions. The following method signature works for me as of 1.5:

        @Search(queryName = "match", type=Location.class)
        public Bundle getMatchesReturnBundle(final @RequiredParam(name = Location.SP_NAME) StringParam name, final @Count Integer count);

jamesagnew added a commit that referenced this issue Feb 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants