Validation of a FHIR Resource using .NET API

Hello,
I would like to validate a FHIR resource using .NET API and the resource has to confirm to US Core structure definition (profile). I looked at Furore.Fhir.Validation.Demo code, but I am not sure how to modify the code in order for the validation to be successful. I want be be able to input a resource such as https://www.hl7.org/fhir/us/core/AllergyIntolerance-example.json.html and have the validator return success.
var ctx = new ValidationSettings()
{

};

        var validator = new Validator(ctx);
        var result = validator.Validate(data);

Thanks.

The demo has the code you need.
What is missing is a resolver that will load the profiles from the US Core (which you need local to do)

1 Like

Thank you! I did see that the code is setting local resolver to specification.zip on the local machine. I don’t quite know how to download all US Core profiles or Argonaut profiles to my local machine such that I can set the path in the resolver. Thanks.

I see that the path to the profiles can be set in “Change Settings” dialog. The label says - “The validator will look for your profiles and other conformance resources in this directory”. However I don’t know how to download the profiles to my local folder. I downloaded this package https://www.hl7.org/fhir/us/core/package.tgz and extracted it to a local folder - C:\Users\xxx\Downloads\package\package\xml
The validate method does not seem to work as expected. Settings.ResourceResolver has 2 sources - one is the path above and the other to specification.zip. This doesn’t work as expected because my input json has an error in it, however the Validate method is returning a success.

This is the input json - It does not have the “Code” element which is mandatory in us core AllergyIntolerance Profile. I am expecting the validate method to return an error, instead it returns a success.
{
“resourceType” : “AllergyIntolerance”,
“id” : “example”,
“clinicalStatus” : {
“coding” : [
{
“system” : “http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical”,
“code” : “active”
}
]
},
“verificationStatus” : {
“coding” : [
{
“system” : “http://terminology.hl7.org/CodeSystem/allergyintolerance-verification”,
“code” : “confirmed”
}
]
},
“category” : [
“medication”
],
“criticality” : “high”,
“patient” : {
“reference” : “Patient/example”,
“display” : “Amy V. Shaw”
},
“reaction” : [
{
“manifestation” : [
{
“coding” : [
{
“system” : “http://snomed.info/sct”,
“code” : “271807003”,
“display” : “skin rash”
}
],
“text” : “skin rash”
}
],
“severity” : “mild”
}
]
}

Sorry, just 1 more comment…
When I run the java validator, I get an error (as expected)

java -jar “org.hl7.fhir.validator.jar” “C:\Users\xxx\Documents\AllergyIntoleranceWithError.json” -ig hl7.fhir.us.core#3.1.0 -profile “http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance

FAILURE validating C:\Users\lbhamidipati\Documents\AllergyIntoleranceWithError.json: error:1 warn:0 info:0
Error @ AllergyIntolerance (line 1, col2) : Profile http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance, Element ‘AllergyIntolerance.code’: minimum required = 1, but only found 0

For the .Net validator to know which profile to validate against, you will either have to provide the Validate method with the profile url, or add the meta.profile field containing that url to the resource json.

1 Like