Skip to content

Polymorphic handling failures #3

@janetr1023

Description

@janetr1023

Happy new year :-)

We are using this very helpful utility and have run into issues with polymorphic elements. Please let us know if there is something we are not understanding about how this works or whether this is an issue with the code base.

Regards,
Janet

These examples are for the FHIR v4 MedicationStatement resource, which contains Medication[x] polymorphic element.

The two issues are:

(1) FhirbaseJsonWriter fails to write Medication[x] when it is CodeableConcept.

 The json is:
	{
	  "resourceType": "MedicationStatement",
	  "id": "example005",
	  "status": "entered-in-error",	  
	  "medicationCodeableConcept": {
		"coding": [
		  {
			"system": "http://snomed.info/sct",
			"code": "27658006",
			"display": "Amoxicillin (product)"
		  }
		]
	  },
	  "subject": {
		"reference": "Patient/4d5ed44d-ba1d-41b2-866e-5a9662278ae6",
		"display": "Donald Duck"
	  }
	}
	
   The error is: 
   Newtonsoft.Json.JsonWriterException: Token PropertyName in state Array would result in an invalid JSON object. Path 'medication.codeableconcept.coding'.
       at Newtonsoft.Json.JsonWriter.AutoComplete(JsonToken tokenBeingWritten)

   The failure also occurs just after writing system while the code is attempting to (prematurely)  "WriteEndObject:, but it also occurs without system and display (with just one contained field, the "code"). So there seems to be two issues: (a) the _isPolymorphic is causing the WriteEndObject to fire too soon instead of reading all contained fields, and (b) the WriteEndObject is confused (?) about the value to write for the Array state.

(2) FhirbaseJsonReader fails to read Medication[x] when it is a Resource.

The json is:
	{
	  "resourceType": "MedicationStatement",
	  "id": "example005",
	  "status": "entered-in-error",	  
	  "medicationCodeableConcept": {
		"coding": [
		  {
			"system": "http://snomed.info/sct",
			"code": "27658006",
			"display": "Amoxicillin (product)"
		  }
		]
	  },
	  "subject": {
		"reference": "Patient/4d5ed44d-ba1d-41b2-866e-5a9662278ae6",
		"display": "Donald Duck"
	  }
	}

The error is thrown by: result.Add(_parser.Parse<T>(reader));
The error is: System.ArgumentException: Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.

Lastly, since we cannot read Medication as CodeableConcept we do not know if the Read would fail, but we suspect it would.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions