Skip to content

Repository files navigation

FhirParametersGenerator

FhirParametersGenerator Logo

Build StatusNuGet

A PoC .NET source generator for mapping model classes to HL7 FHIR® Parameters resources.

Useful when interacting with FHIR® server operation endpoints.

Getting Started

dotnet add package FhirParametersGenerator

This sample code...

usingFhirParametersGenerator;usingHl7.Fhir.Model;usingHl7.Fhir.Serialization;vart=newTestModel{Age=123,Name="Test",Code=new("http://snomed.info/sct","386661006","Fever"),};// the ToFhirParameters() extension method is code-generatedvarparameters=t.ToFhirParameters();Console.WriteLine(parameters.ToJson(new(){Pretty=true}));// the reverse direction is also code-generated, as a static FromFhirParameters() factory methodvarroundTripped=TestModel.FromFhirParameters(parameters);// apply this attribute to the desired model class// the class must be declared `partial` (and so must any enclosing type) so the generator// can add the FromFhirParameters() method to it[GenerateFhirParameters]publicpartialclassTestModel{publicstringName{get;init;}=string.Empty;publicintAge{get;init;}=0;publicCodeableConcept?Code{get;init;}}

...will output:

{
"resourceType": "Parameters",
"parameter": [
{
"name": "name",
"valueString": "Test"
},
{
"name": "age",
"valueInteger": 123
},
{
"name": "code",
"valueCodeableConcept": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "386661006"
}
],
"text": "Fever"
}
}
]
}

Limitations

This library is in a very early stage and many edge and not-so-edge cases that are not covered by the generated source. The list of open issues is a good starting point to see what isn't yet supported. Contributions are of course always welcome.

Benchmark

A benchmark project exists which measures the performance of generating the source code for a 1000-property class: https://github.com/chgl/FhirParametersGenerator/blob/master/src/FhirParametersGenerator.Benchmark/Program.cs.

Benchmarking results over time are available at https://chgl.github.io/FhirParametersGenerator/dev/bench/.

Credits

Source Code

Contains source code published under the terms of the MIT license originally from https://github.com/andrewlock/NetEscapades.EnumGenerators/ and from https://github.com/dotnet/runtime/blob/v6.0.2/src/libraries/System.Text.Json/Common/JsonCamelCaseNamingPolicy.cs.

Icon

The package icon is composed of

  • Fire by artworkbean from NounProject.com
  • Edit by Logan from NounProject.com

About

A .NET source generator for mapping model classes to HL7 FHIR® Parameters resources.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages