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

[FhirContext.newXmlParser] Potential Parsing Error when parsing previously generated xml/JSON string way back to resource #720

Closed
mosaic-hgw opened this Issue Aug 25, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@mosaic-hgw

mosaic-hgw commented Aug 25, 2017

Hello,

right now we are running first implementational tests using and developing FHIR ressources. Therefore the provided FHIR-HAPI (version 2.5, DTSU3) massivly simplifies necessary work. Thank you.

Based on your documentation we designed a new FHIR-Type "ConsentTemplate" containing a existing FHIR resource "Person" to store contact information. Including this FHIR-Type in a new resource "ImportFormatDefinition" was no problem.

(Resource ImportFormatDefinition-> Type ConsentTemplate-> Person contact)

Parsing it directly in JAVA to XML and/or JSON using FHIR-HAPI, the FHIRcontext and provided ParsingFunctionalities (encodeResourceToString) generated the expected XML/JSON output.

{"resourceType":"ImportFormatDefinition","meta":{"profile":["http://example.com/StructureDefinition/dontuse#ImportFormatDefinition"]},"supportedVersion":"2.5.x","templatesConsentTemplate":[{"domainName":"name","Name":"template_01","version":"1.0","title":"title","comment":"comment","contact":{"resourceType":"Person","name":[{"family":"Mustermann","given":["Max"]}],"telecom":[{"system":"email","value":"max.mustermann@mail.de"},{"system":"phone","value":"+49 1234 23232"}],"address":[{"text":"street 1-2","city":"city","postalCode":"12345","country":"Germany"}]}}]}

But, parsing this generated and obviuously correct String back to a resource (parseResource) fails , when the string contains Person-Information. A java.lang.ClassCastException occurs in both cases (XML and JSON) when trying to parse the Person-info.

Exception in thread "main" java.lang.ClassCastException: org.hl7.fhir.dstu3.model.Person cannot be cast to ca.uhn.fhir.model.api.IResource
	at ca.uhn.fhir.parser.ParserState$PreResourceStateHapi.wereBack(ParserState.java:2259)
	at ca.uhn.fhir.parser.ParserState.pop(ParserState.java:124)
	at ca.uhn.fhir.parser.ParserState.access$100(ParserState.java:54)
	at ca.uhn.fhir.parser.ParserState$ElementCompositeState.endingElement(ParserState.java:1562)
	at ca.uhn.fhir.parser.ParserState.endingElement(ParserState.java:96)
	at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1415)
	at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1330)
	at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1413)
	at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1394)
	at ca.uhn.fhir.parser.JsonParser.parseChildren(JsonParser.java:1330)
	at ca.uhn.fhir.parser.JsonParser.doParseResource(JsonParser.java:265)
	at ca.uhn.fhir.parser.JsonParser.doParseResource(JsonParser.java:247)
	at ca.uhn.fhir.parser.BaseParser.parseResource(BaseParser.java:656)
	at ca.uhn.fhir.parser.BaseParser.parseResource(BaseParser.java:705)

This problem only occurs if the Person-Information is set. Leaving it blank, parsing from resource to xml string and way back is not a problem.

Here is how we are including the Person-Resource into the Datatype

@DatatypeDef(name = "ConsentTemplate")
public class ConsentTemplate  extends Type implements ICompositeType {	
	[...]
	@Child(name = "contact", order = 8, min = 0, max = 1)
	@Description(shortDefinition = "responsible contact for this consent template")
	private Person contact= new Person();	


Here is how we are including the datatype in our Resource

@ResourceDef(name="ImportFormatDefinition", profile = "http://example.com/StructureDefinition/dontuse#ImportFormatDefinition")
public class ImportFormatDefinition extends DomainResource{
[...]
	@Child(name = "templates", order = 4, min = 1, max = Child.MAX_UNLIMITED)
	@Description(shortDefinition = "import information for 1-n consent templates")	
	private List<Type> templates = new ArrayList<Type>();	
[...]

Any recommendations or might it be an error in the FHIR-HAPI?

Thanks in advance!

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Aug 25, 2017

Owner

The fact that it's going into PreResourceStateHapi means that at some point in the parsing it's getting conmfused and thinking that this is a DSTU2 structure, which used a different interface (IResource) from all of the later structures (IAnyResource).

Can you put a breakpoint in the two constructors of ParserState.PreResourceStateHapi and see what is leading it to go there? Given that you are using a DSTU3 structure if should be going into PreResourceStateHl7Org

Owner

jamesagnew commented Aug 25, 2017

The fact that it's going into PreResourceStateHapi means that at some point in the parsing it's getting conmfused and thinking that this is a DSTU2 structure, which used a different interface (IResource) from all of the later structures (IAnyResource).

Can you put a breakpoint in the two constructors of ParserState.PreResourceStateHapi and see what is leading it to go there? Given that you are using a DSTU3 structure if should be going into PreResourceStateHl7Org

@mosaic-hgw

This comment has been minimized.

Show comment
Hide comment
@mosaic-hgw

mosaic-hgw Aug 29, 2017

Hello,

I made a break point in ParserState.class at Line 1664 and 2259. Parsing of ConsentTemplate-Class goes into PreResourceStateHapi instead of PreResourceStateHl7Org, but it is noticed as DSTU3. (see picture 1). Parsing seems no problem at this point.

screenshot_debugging_consent_template

A few lines later, when trying to cast the Person.class as IResource (getCurrentElement) the processing fails with the stated exception (see picture 2). Hope this info helps.

screenshot_debugging_parser class

mosaic-hgw commented Aug 29, 2017

Hello,

I made a break point in ParserState.class at Line 1664 and 2259. Parsing of ConsentTemplate-Class goes into PreResourceStateHapi instead of PreResourceStateHl7Org, but it is noticed as DSTU3. (see picture 1). Parsing seems no problem at this point.

screenshot_debugging_consent_template

A few lines later, when trying to cast the Person.class as IResource (getCurrentElement) the processing fails with the stated exception (see picture 2). Hope this info helps.

screenshot_debugging_parser class

@mosaic-hgw

This comment has been minimized.

Show comment
Hide comment
@mosaic-hgw

mosaic-hgw Oct 19, 2017

Any Suggestions?

mosaic-hgw commented Oct 19, 2017

Any Suggestions?

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Oct 20, 2017

Owner

Hi @mosaic-hgw - I've just given it a shot, and after some tweaking I was able to reproduce your issue.

Will keep you posted, but this should be fixable.

Owner

jamesagnew commented Oct 20, 2017

Hi @mosaic-hgw - I've just given it a shot, and after some tweaking I was able to reproduce your issue.

Will keep you posted, but this should be fixable.

@jamesagnew

This comment has been minimized.

Show comment
Hide comment
@jamesagnew

jamesagnew Oct 21, 2017

Owner

Ok, fix incoming. Thanks for reporting! :)

Owner

jamesagnew commented Oct 21, 2017

Ok, fix incoming. Thanks for reporting! :)

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