FHIR Chat · Validation · dotnet

Stream: dotnet

Topic: Validation


view this post on Zulip Angus Millar (Jun 19 2017 at 08:15):

Hi Guys, having a tough time with implementing validation. I thought I was there based on development but as soon as I move to IIS in dev or production my issue starts.
It comes down to the using the MultiResolver or more specifically the ZipSource as an IResourceResolver. When instantiating the ZipSource we provide a path to the ‘specification.zip’. In development I was simply doing this:
MultiResolver.AddSource(new ZipSource("specification.zip"));
That worked just fine when running outside of IIS. It located my specification.zip file in my bin directory and all worked flawlessly. Yet as soon as I run in IIS, either IIS Express on my dev machine or on the full IIS on a production server it complains that the file cannot be found. I get the error message: failed: Cannot prepare ZipArtifactSource: file 'specification.zip' was not found.
Looking at the FHIR .Net API source I can see this exception in thrown in the ZipSource class in the following code:
public static ZipSource CreateValidationSource() { var path = Path.Combine(DirectorySource.SpecificationDirectory, "specification.zip"); if(File.Exists(path)) return new ZipSource(path); throw new FileNotFoundException("Cannot create a ZipArtifactSource for the core specification: specification.zip was not found"); }
I have also looked into the method DirectorySource.SpecificationDirectory and can see it return the correct path.
So as this works outside of IIS and not within, I strongly feel this is an IIS issue and not a problem with the FHIR .net API. And yet I cannot work out how to resolve it.
I have played with IIS’s ‘Request Filtering’ with no avail, set the security permissions for my application pool’s Identity to allow access to the Bin folder, and specifically on the file ‘'specification.zip’, still no luck.
Has anyone encountered this problem?
Why can’t IIS allow my application to read the file located at ‘C:\inetpub\wwwroot\Pyro\bin\specification.zip’ when I know it's there?
Any help my appreciated.

view this post on Zulip Peter Jordan (Jun 19 2017 at 10:04):

Take a look at MIME type filtering which I believe is slightly different to request & extension filtering.

view this post on Zulip Angus Millar (Jun 19 2017 at 13:16):

Thanks Peter, will look into that

view this post on Zulip Brian Postlethwaite (Jun 20 2017 at 00:17):

I'll have a look at my code to see what I've done, pretty sure I've included the full path to the file.
The working folder may not be the bin folder, hence not finding it.
Likely I have the assembly codebase location included. Will find and share the code (p.s. the unit tests in the specification project have the same issue)

view this post on Zulip Angus Millar (Jun 21 2017 at 07:38):

It was a dumb pathing issue of my own doing! I was not calling CreateValidationSource() I was instantiating an instance of ZipSource("specification.zip"). So I focused on the wrong exception message which looked very similar. That lead me on a wild goose chase.

view this post on Zulip Theo Stolker (Jun 22 2017 at 08:33):

Guys, this runtime unpacking of speciation.zip I think is actually not a great idea. I am surprised that no other users have objected against it so far.

For DTSU1 I customized the API so that I would deliver the unpacked specification.zip content as part of the deployment of my server, and let the logic work on these files - within the control of my server, not somewhere in a temp directory.

Is there already work underway to allow managing this in a better way?

view this post on Zulip Christiaan Knaap (Jun 22 2017 at 10:35):

That's why we usually wrap it in a CachedResolver. Ease of deployment of a zip, but the speed of memory-access when it is cached. See the ResourceResolverTests.TestCacheInvalidation for an example.

view this post on Zulip Theo Stolker (Jun 22 2017 at 16:43):

Thanks, @Christiaan Knaap

view this post on Zulip Ewout Kramer (Jun 26 2017 at 07:15):

@Theo - as well, you can certainly unpack all the files in an application directory yourself, and then use the DirectorySource class. Or implement the pretty trivial IResourceResolver interface yourself (on top of -say- a database). They can be combined with the MultiResolver and CachedResolver to fit any deployment's need!

view this post on Zulip Theo Stolker (Jun 26 2017 at 07:57):

Thanks, @Ewout Kramer, I will try that!

view this post on Zulip Miguel Curi (Jun 27 2017 at 18:59):

Would it make sense to include the file as an embedded resource on your assembly? If the validation is strictly tied to your code and the specification files don't change for a particular assembly, it would make sense to me that the resource is deployed with the code as an embedded resource. I did something similar with validating CDA documents and it works pretty good specially since I don't have to worry about deployment.
Maybe I am off but just putting this out there just in case.

view this post on Zulip Ewout Kramer (Jun 29 2017 at 11:49):

No, you're completely on subject....I think many times the validation would be tied to your code, and you could deploy it as an embedded resource. I had imagined creating an implementation of IResourceResolver that does just that, say an "EmbeddedResourceResolver". If you'd do that, the .NET validator would be able to locate it and use it in validation.

view this post on Zulip Brian Postlethwaite (new) (Jun 30 2017 at 00:00):

That file is quite large too. So depends on usage. It you only need a few resources, lots of waste

view this post on Zulip Adeel Ahmed (Jul 14 2020 at 03:27):

Hi Everyone,
Can someone please guide me or share some C# code examples of implementation of Fhir validation (R4 version 4.0.1) against structural definitions / local profiles.

For example, I want to validate a Fhir (R4) Json patient object against the Fhir structural definition (Json Schema) at http://build.fhir.org/ig/HL7NZ/nzbase/branches/master/StructureDefinition-NzPatient.profile.json.html

I have found some examples online but they are all for STU3 (like https://github.com/FirelyTeam/Furore.Fhir.ValidationDemo)

Your help will be much appreciated.

Thanks,
Adeel

view this post on Zulip Ewout Kramer (Jul 14 2020 at 21:32):

That example github has a branch for R4 too. And anyway, there is no real difference in the way you would use it.

view this post on Zulip Adeel Ahmed (Jul 14 2020 at 23:30):

Ewout Kramer said:

That example github has a branch for R4 too. And anyway, there is no real difference in the way you would use it.

Hi Ewout,

             Thank you so much for your reply, can you please give me the link to the example that  you are referring too.?

Thanks,
Adeel

view this post on Zulip Ewout Kramer (Jul 15 2020 at 07:33):

Hi Adeel, I meant the Furore.Fhir.ValidationDemo - I wrote that just to show how to invoke the validator. There's an R4 and a STU3 branch for it - but there's not much difference since the API is the same!

view this post on Zulip Adeel Ahmed (Jul 20 2020 at 00:14):

Hi Ewout,

Thank you so much for your quick response - The R4 branch is not visible on Github for the validation example but I have managed to update an
older version of the project to use R4 dll and was able to get it working without any code changes.
But there seems to be an issue - Whenever I am trying to validate a Patient Fhir Json Object it shows me the following error:

Overall result: FAILURE

[ERROR] Resolution of profile at 'http://hl7.org/fhir/StructureDefinition/Patient' failed: Type checking the data: Encountered unknown element 'requirements' at location 'StructureDefinition.requirements[0]' while parsing (at Patient)

I have tried to understand this error and am not able to resolve it EVEN if I am providing with a valid Patient Fhir object / instance its coming back with the same error. Your help in this regard will be highly appreciated.

Thanks,
Adeel

view this post on Zulip Ewout Kramer (Jul 20 2020 at 09:59):

Hi Adeel....To validate any kind of resource (like Patient), the validator looks at the definitions of FHIR's resources, which are encoded in StructureDefinitions. In other words, the Validator is configured with these STructureDefinitions, so it knows what Patient looks like. The error you are getting are not so much because of an error in the Patient data, but an error in the StructureDefinitions that are used to read the metadata. As you can see here: http://hl7.org/fhir/structuredefinition.html#resource, there is no "requirements" member on StructureDefinition - so it seems this input data (not yours) is wrong. Do you remember where you got that data from?

view this post on Zulip Ewout Kramer (Jul 20 2020 at 10:00):

As for the repos, the "develop" and "master" hold the R4 version, whereas the "develop-st3" and "master-stu3" have the STU3 version.

view this post on Zulip Adeel Ahmed (Jul 22 2020 at 00:56):

Hi Ewout,
Well I tried the Patient output from my application (under development). The patient output is as below. Besides this I had tried a couple of other examples online and they came back with the same output/ error in the validation application. Please do note that I did NOT use any local references (custom structural definitions / custom profiles) Just the structural definations in "specification.zip" were used .
{
"resourceType": "Patient",
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "ECLR10518"
}
],
"text": "ECLAIRSYSTEM"
},
"value": "ECLR10518"
}
],
"name": [
{
"family": "Nash",
"given": [
"Wayne"
],
"suffix": [
""
]
}
],
"gender": "unknown",
"birthDate": "1949-03-27",
"deceasedBoolean": false,
"address": [
{
"line": [
"178 Tancreds Road"
],
"city": "TAITAPU",
"state": "",
"postalCode": "7672",
"country": ""
}
],
"maritalStatus": {
"coding": [
{
"system": "http://hl7.org/fhir/ValueSet/marital-status",
"code": "D"
}
],
"text": "Marriage contract has been declared dissolved and inactive"
},
"contact": [
{
"telecom": [
{
"system": "email",
"value": "",
"use": "work"
},
{
"system": "phone",
"value": "",
"use": "work"
},
{
"system": "phone",
"value": "329 6297",
"use": "home"
},
{
"system": "fax",
"use": "home"
},
{
"system": "phone",
"use": "home"
},
{
"system": "phone",
"value": "",
"use": "mobile"
}
]
}
]
}


More examples that I tried :
https://www.hl7.org/fhir/patient-example.json.html
http://fhir.hl7fundamentals.org/r4/Patient/3377/_history/1

view this post on Zulip Peter Jordan (Jul 22 2020 at 01:51):

@Adeel Ahmed - one obvious problem with that example Patient resource is in the use of the coding data type see http://hl7.org/fhir/datatypes.html#Coding.

view this post on Zulip Adeel Ahmed (Jul 22 2020 at 02:29):

Yes, thank you for pointing that but its not working for the rest of the examples online as well i.e. comes up with the same error.
Other Fhir patient Json examples:

https://www.hl7.org/fhir/patient-example.json.html
http://fhir.hl7fundamentals.org/r4/Patient/3377/_history/1

view this post on Zulip Mirjam Baltus (Jul 22 2020 at 07:22):

@Adeel Ahmed It looks like the specification definitions are not correct. Could you try to clear your FhirArtifactCache that should be somewhere in your temp folder? If you run your program after that, it should regenerate that FhirArtifactCache with the specification.zip that is in your project.

view this post on Zulip Adeel Ahmed (Jul 22 2020 at 23:15):

@Mirjam Baltus - Deleted FhirArtifactChache folder in the temp and ran the application again - Same error as before:

Overall result: FAILURE

[ERROR] Resolution of profile at 'http://hl7.org/fhir/StructureDefinition/Patient' failed: Type checking the data: Encountered unknown element 'requirements' at location 'StructureDefinition.requirements[0]' while parsing (at Patient)

I tried to validate the Fhir patient Json provided on the link: https://www.hl7.org/fhir/patient-example.json
Please see the screenshots below of the application and options that I have selected:

Validation-issue-screenshot.png

2020_07_23_11_11_28_.NET_Profile_Validation_Tool_1.5.2_DSTU2_.jpg

view this post on Zulip Adeel Ahmed (Jul 23 2020 at 04:18):

@Ewout Kramer and @Mirjam Baltus - This is a Structural definition issue? If so where can I find the updated structural definitions to replace the faulty structure def in the "specification.zip" folder? Your help in this regard is highly appreciated.

view this post on Zulip Ewout Kramer (Jul 23 2020 at 09:05):

StructureDefinition.requirements only existed in DSTU2 - it seems somehow you are using the DSTU2 definition zip. Have you been working with DSTU2 too? can unzip the specification.zip in your build directory, look for a file called profile-resources.xml, and check the <fhirVersion> element used on the StructureDefinitions inside that file?


Last updated: Apr 12 2022 at 19:14 UTC