-
Notifications
You must be signed in to change notification settings - Fork 352
Description
Patient resource object with a Birthdate containing a Data Abscent reason extension results in a 'Object reference not set to an instance of an object' Exception when calling Patient.Validate(true);
To Reproduce
var patient = new Patient()
{
BirthDateElement = new Date()
{
Extension = new List<Extension>()
{
new Extension
{
Url = "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
Value = new Code
{
Value = "unknown"
}
}
}
}
};
patient.Validate(true); // results in a "Object reference not set to an instance of an object." Exception
patient.Validate(false); // succedes
or deserializing from the below json results in the same error:
{
"resourceType": "Patient",
"_birthDate": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
},
Stack trace:
at Hl7.Fhir.Model.Date.GetHashCode()
at System.ComponentModel.WeakHashtable.WeakKeyComparer.System.Collections.IEqualityComparer.GetHashCode(Object obj)
at System.Collections.Hashtable.GetHash(Object key)
at System.Collections.Hashtable.InitHash(Object key, Int32 hashsize, UInt32& seed, UInt32& incr)
at System.Collections.Hashtable.get_Item(Object key)
at System.ComponentModel.TypeDescriptor.NodeFor(Object instance, Boolean createDelegator)
at System.ComponentModel.TypeDescriptor.GetDescriptor(Object component, Boolean noCustomTypeDesc)
at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes)
at System.ComponentModel.DataAnnotations.Validator.GetPropertyValues(Object instance, ValidationContext validationContext)
at System.ComponentModel.DataAnnotations.Validator.GetObjectPropertyValidationErrors(Object instance, ValidationContext validationContext, Boolean validateAllProperties, Boolean breakOnFirstError)
at System.ComponentModel.DataAnnotations.Validator.GetObjectValidationErrors(Object instance, ValidationContext validationContext, Boolean validateAllProperties, Boolean breakOnFirstError)
at System.ComponentModel.DataAnnotations.Validator.TryValidateObject(Object instance, ValidationContext validationContext, ICollection`1 validationResults, Boolean validateAllProperties)
at Hl7.Fhir.Introspection.FhirElementAttribute.validateElement(Object value, ValidationContext validationContext, List`1 result)
at Hl7.Fhir.Introspection.FhirElementAttribute.IsValid(Object value, ValidationContext validationContext)
at System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext)
at System.ComponentModel.DataAnnotations.Validator.TryValidate(Object value, ValidationContext validationContext, ValidationAttribute attribute, ValidationError& validationError)
at System.ComponentModel.DataAnnotations.Validator.GetValidationErrors(Object value, ValidationContext validationContext, IEnumerable`1 attributes, Boolean breakOnFirstError)
at System.ComponentModel.DataAnnotations.Validator.GetObjectPropertyValidationErrors(Object instance, ValidationContext validationContext, Boolean validateAllProperties, Boolean breakOnFirstError)
at System.ComponentModel.DataAnnotations.Validator.GetObjectValidationErrors(Object instance, ValidationContext validationContext, Boolean validateAllProperties, Boolean breakOnFirstError)
at System.ComponentModel.DataAnnotations.Validator.ValidateObject(Object instance, ValidationContext validationContext, Boolean validateAllProperties)
at Hl7.Fhir.Validation.DotNetAttributeValidation.Validate(Base value, Boolean recurse, NarrativeValidationKind narrativeValidation)
This is a valid scenario in the AU Core Fhir spec.
https://hl7.org.au/fhir/core/general-requirements.html#missing-must-support-and-mandatory-data
Expected behavior
Throw Validation error if invalid, otherwise execute without issue.
Version used:
- FHIR Version: R4
- Version: 5.10.3
Copilot