├── .gitattributes ├── .github └── dependabot.yml ├── .gitignore ├── Hl7.Fhir.Common.sln ├── LICENSE ├── README.md ├── build ├── RetrieveVersion.ps1 ├── UpdateVersion.ps1 ├── azure-pipelines.yml ├── build-variables.yml ├── pipeline-variables.yml ├── templates │ ├── apply-versioning-steps-template.yml │ ├── sign-dlls-template.yml │ └── test-job-template.yml └── tools │ └── sn.exe ├── clean.bat ├── contributors.md ├── icon-firely-sdk-128.png ├── lib └── Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll ├── pack.bat ├── src ├── Benchmarks │ ├── Benchmarks.csproj │ ├── DeserializationBenchmark.cs │ ├── Program.cs │ ├── SerializationBenchmarks.cs │ └── TestData │ │ ├── fp-test-patient.json │ │ └── fp-test-patient.xml ├── FhirNetApi.publickey ├── Hl7.Fhir.ElementModel │ ├── Adapters │ │ ├── SourceNodeToTypedElementAdapter.cs │ │ └── TypedElementToSourceNodeAdapter.cs │ ├── BaseTypedElement.cs │ ├── DomNode.cs │ ├── DomNodeList.cs │ ├── ElementNode.cs │ ├── ElementNodeComparator.cs │ ├── ElementNodeExtensions.cs │ ├── Hl7.Fhir.ElementModel.csproj │ ├── ICdaInfoSupplier.cs │ ├── IResourceTypeSupplier.cs │ ├── IShortPathGenerator.cs │ ├── ISourceNode.cs │ ├── ITypedElement.cs │ ├── Language │ │ └── TypeSpecifier.cs │ ├── MaskingNode.cs │ ├── MaskingNodeSettings.cs │ ├── PrimitiveElement.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ScopedNode.cs │ ├── Serialization │ │ └── PrimitiveTypeConverter.cs │ ├── SourceNode.cs │ ├── SourceNodeComparator.cs │ ├── SourceNodeExtensions.cs │ ├── Specification │ │ ├── ElementDefinitionSummary.cs │ │ ├── IStructureDefinitionSummaryProvider.cs │ │ └── XmlRepresentation.cs │ ├── StructuralTypeException.cs │ ├── TreeComparisonResult.cs │ ├── TypedElementOnSourceNode.cs │ ├── TypedElementSettings.cs │ └── Types │ │ ├── Any.cs │ │ ├── Boolean.cs │ │ ├── Code.cs │ │ ├── Concept.cs │ │ ├── Date.cs │ │ ├── DateTime.cs │ │ ├── DateTimePrecision.cs │ │ ├── Decimal.cs │ │ ├── Integer.cs │ │ ├── Long.cs │ │ ├── Quantity.cs │ │ ├── Ratio.cs │ │ ├── String.cs │ │ └── Time.cs ├── Hl7.Fhir.Serialization │ ├── FhirFileFormats.cs │ ├── FhirJsonBuilder.cs │ ├── FhirJsonBuilderExtensions.cs │ ├── FhirJsonNode.cs │ ├── FhirJsonNodeFactory.cs │ ├── FhirJsonParsingSettings.cs │ ├── FhirJsonSerializationSettings.cs │ ├── FhirSerializationFormats.cs │ ├── FhirXmlBuilder.cs │ ├── FhirXmlBuilderExtensions.cs │ ├── FhirXmlNode.cs │ ├── FhirXmlNodeFactory.cs │ ├── FhirXmlParsingSettings.cs │ ├── FhirXmlSerializationSettings.cs │ ├── Hl7.Fhir.Serialization.csproj │ ├── INavigatorStream.cs │ ├── JTokenExtensions.cs │ ├── JsonNavigatorStream.cs │ ├── JsonSerializationDetails.cs │ ├── MissingTypeInformationException.cs │ ├── NavigatorStreamFactory.cs │ ├── NavigatorStreamHelper.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SerializationAnnotations.cs │ ├── Support │ │ ├── DateExtensions.cs │ │ └── GuidExtensions.cs │ ├── Utility │ │ └── SerializationUtil.cs │ ├── XObjectExtensions.cs │ ├── XObjectFhirXmlExtensions.cs │ ├── XmlNavigatorStream.cs │ ├── XmlSerializationDetails.cs │ └── xhtml │ │ ├── fhir-xhtml.xsd │ │ └── xml.xsd ├── Hl7.Fhir.Support.Poco.Tests │ ├── DeepMatchTest.cs │ ├── Hl7.Fhir.Support.Poco.Tests.csproj │ ├── HttpToEntryExtensionsTests.cs │ ├── Model │ │ ├── TestAddress.cs │ │ ├── TestAttachment.cs │ │ ├── TestBinary.cs │ │ ├── TestBundle.cs │ │ ├── TestCodeSystem.cs │ │ ├── TestEnums.cs │ │ ├── TestHumanName.cs │ │ ├── TestOrganization.cs │ │ ├── TestPatient.cs │ │ ├── TestQuestionnaire.cs │ │ └── TestSignature.cs │ ├── NewPocoSerializers │ │ ├── FhirJsonDeserializationTests.cs │ │ ├── FhirJsonSerializationTests.cs │ │ ├── FhirXmlDeserializationTests.cs │ │ ├── FhirXmlSerializationTests.cs │ │ ├── PathStackTests.cs │ │ ├── SummaryFilterIntegrationTests.cs │ │ └── SummaryFilterTests.cs │ ├── PocoValidationTests │ │ ├── IsValidValueTests.cs │ │ └── ValidatableObjectTests.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ResolverTests │ │ └── CommonFhirPackageSourceTest.cs │ └── TestData │ │ ├── fp-test-patient-errors-recovered.json │ │ ├── fp-test-patient-errors.json │ │ ├── fp-test-patient.json │ │ ├── fp-test-patient.xml │ │ ├── json-edge-cases.json │ │ ├── mask-text.xml │ │ └── testPackage.tgz ├── Hl7.Fhir.Support.Poco │ ├── ElementModel │ │ ├── IFhirValueProvider.cs │ │ ├── PocoBuilder.cs │ │ ├── PocoBuilderSettings.cs │ │ ├── PocoElementNode.cs │ │ ├── ScopedNodeExtensions.cs │ │ ├── TypedElementParseExtensions.cs │ │ └── TypedSerialization.cs │ ├── FhirPath │ │ ├── ElementNavFhirExtensions.cs │ │ └── FhirEvaluationContext.cs │ ├── Hl7.Fhir.Support.Poco.csproj │ ├── Introspection │ │ ├── ChoiceType.cs │ │ ├── ClassMapping.cs │ │ ├── DeclaredTypeAttribute.cs │ │ ├── FhirElementAttribute.cs │ │ ├── FhirModelAssemblyAttribute.cs │ │ ├── FhirTypeAttribute.cs │ │ ├── IFhirVersionDependent.cs │ │ ├── ModelInspector.cs │ │ ├── NotMappedAttribute.cs │ │ ├── PropertyMapping.cs │ │ ├── PropertyMappingCollection.cs │ │ ├── ReferencesAttribute.cs │ │ └── VersionedAttribute.cs │ ├── Model │ │ ├── Base.cs │ │ ├── Base64Binary.cs │ │ ├── Canonical.cs │ │ ├── Code.cs │ │ ├── CodeOfT.cs │ │ ├── CodeableConcept.cs │ │ ├── Coding.cs │ │ ├── ContactPoint.cs │ │ ├── Date-comparators.cs │ │ ├── Date.cs │ │ ├── DomainResource.cs │ │ ├── Element.cs │ │ ├── ElementValue.cs │ │ ├── Extension.cs │ │ ├── FhirBoolean.cs │ │ ├── FhirDateTime-comparators.cs │ │ ├── FhirDateTime.cs │ │ ├── FhirDecimal.cs │ │ ├── FhirString.cs │ │ ├── FhirTypeConstants.cs │ │ ├── FhirUri.cs │ │ ├── FhirUrl.cs │ │ ├── Generated │ │ │ ├── BackboneElement.cs │ │ │ ├── BackboneType.cs │ │ │ ├── Base64Binary.cs │ │ │ ├── Canonical.cs │ │ │ ├── Code.cs │ │ │ ├── CodeableConcept.cs │ │ │ ├── Coding.cs │ │ │ ├── ContactDetail.cs │ │ │ ├── ContactPoint.cs │ │ │ ├── DataType.cs │ │ │ ├── Date.cs │ │ │ ├── DomainResource.cs │ │ │ ├── FhirBoolean.cs │ │ │ ├── FhirDateTime.cs │ │ │ ├── FhirDecimal.cs │ │ │ ├── FhirString.cs │ │ │ ├── FhirUri.cs │ │ │ ├── FhirUrl.cs │ │ │ ├── Id.cs │ │ │ ├── Identifier.cs │ │ │ ├── Instant.cs │ │ │ ├── Integer.cs │ │ │ ├── Integer64.cs │ │ │ ├── Markdown.cs │ │ │ ├── Meta.cs │ │ │ ├── Oid.cs │ │ │ ├── OperationOutcome.cs │ │ │ ├── Parameters.cs │ │ │ ├── Period.cs │ │ │ ├── PositiveInt.cs │ │ │ ├── Quantity.cs │ │ │ ├── Range.cs │ │ │ ├── Resource.cs │ │ │ ├── ResourceReference.cs │ │ │ ├── Template-Bindings.cs │ │ │ ├── Time.cs │ │ │ ├── UnsignedInt.cs │ │ │ ├── UsageContext.cs │ │ │ ├── Uuid.cs │ │ │ ├── XHtml.cs │ │ │ └── _GeneratorLog.cs │ │ ├── IConformanceResource.cs │ │ ├── IDeepComparable.cs │ │ ├── IDeepCopyable.cs │ │ ├── IExtendable.cs │ │ ├── ISystemAndCode.cs │ │ ├── IValue.cs │ │ ├── Id.cs │ │ ├── Identifier.cs │ │ ├── Initializers.cs │ │ ├── Instant-comparators.cs │ │ ├── Instant.cs │ │ ├── Integer.cs │ │ ├── Integer64.cs │ │ ├── Markdown.cs │ │ ├── Narrative.cs │ │ ├── Oid.cs │ │ ├── OperationOutcome.cs │ │ ├── Parameters.cs │ │ ├── ParametersExtensions.cs │ │ ├── PatchParametersExtensions.cs │ │ ├── PositiveInt.cs │ │ ├── PrimitiveType.cs │ │ ├── Quantity.cs │ │ ├── Resource.cs │ │ ├── ResourceIdentityExtensions.cs │ │ ├── ResourceReference.cs │ │ ├── Time-comparators.cs │ │ ├── Time.cs │ │ ├── UnsignedInt.cs │ │ ├── Uuid.cs │ │ └── XHtml.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Rest │ │ ├── ContentType.cs │ │ ├── EntryRequest.cs │ │ ├── EntryResponse.cs │ │ ├── EntryToHttpExtensions.cs │ │ ├── EntryToTypedElementExtensions.cs │ │ ├── FhirClientSettings.cs │ │ ├── FhirOperationException.cs │ │ ├── HttpClientRequester.cs │ │ ├── HttpToEntryExtensions.cs │ │ ├── HttpUtil.cs │ │ ├── IClientRequester.cs │ │ ├── Legacy │ │ │ └── WebClientRequester.cs │ │ ├── ResourceIdentity.cs │ │ ├── ResourceReferenceExtensions.cs │ │ ├── RestUrl.cs │ │ ├── SearchParams.cs │ │ ├── SearchParamsExtensions.cs │ │ ├── TaskExtensions.cs │ │ ├── TokenExtensions.cs │ │ ├── UriParamList.cs │ │ └── WebRequestExtensions.cs │ ├── Serialization │ │ ├── BundleFilter.cs │ │ ├── ComplexTypeReader.cs │ │ ├── DataAnnotationDeserialzationValidator.cs │ │ ├── DefaultModelFactory.cs │ │ ├── DeserializationContext.cs │ │ ├── DeserializationFailedException.cs │ │ ├── DispatchingReader.cs │ │ ├── ElementMetadataFilter.cs │ │ ├── ExceptionAggregator.cs │ │ ├── FhirJsonConverter.cs │ │ ├── FhirJsonException.cs │ │ ├── FhirJsonPocoDeserializer.cs │ │ ├── FhirJsonPocoDeserializerSettings.cs │ │ ├── FhirJsonPocoSerializer.cs │ │ ├── FhirJsonPocoSerializerSettings.cs │ │ ├── FhirXmlException.cs │ │ ├── FhirXmlPocoDeserializer.cs │ │ ├── FhirXmlPocoDeserializerSettings.cs │ │ ├── FhirXmlPocoSerializer.cs │ │ ├── IDeserializationValidator.cs │ │ ├── IsExternalInit.cs │ │ ├── JsonSerializerOptionsExtensions.cs │ │ ├── ParserSettings.cs │ │ ├── PathStack.cs │ │ ├── PocoDeserializationHelper.cs │ │ ├── PrimitiveValueReader.cs │ │ ├── RepeatingElementReader.cs │ │ ├── RootRenamer.cs │ │ ├── SerializationFilter.cs │ │ ├── SerializerSettings.cs │ │ ├── SystemTextJsonParsingExtensions.cs │ │ ├── TopLevelFilter.cs │ │ └── XmlReaderExtensions.cs │ ├── Specification │ │ ├── Source │ │ │ ├── CachedResolver.cs │ │ │ ├── CommonFhirPackageSource.cs │ │ │ ├── IArtifactSource.cs │ │ │ ├── IResourceResolver.cs │ │ │ ├── MultiResolver.cs │ │ │ └── SyncToAsyncResolver.cs │ │ └── Terminology │ │ │ ├── ClosureParameters.cs │ │ │ ├── ContextDirection.cs │ │ │ ├── ITerminologyService.cs │ │ │ ├── LookupParameters.cs │ │ │ ├── OperationValidCodeExtensions.cs │ │ │ ├── SubsumesParameters.cs │ │ │ └── ValueSetExpanderSettings.cs │ ├── Support │ │ ├── Issue.cs │ │ ├── OperationOutcomeExtensions.cs │ │ ├── ResolvingConflictException.cs │ │ ├── ResourceReferenceNotFoundException.cs │ │ └── ValidationOutcomeExtensions.cs │ ├── Utility │ │ └── NullExtensions.cs │ └── Validation │ │ ├── AllowedTypesAttribute.cs │ │ ├── CardinalityAttribute.cs │ │ ├── CodePatternAttribute.cs │ │ ├── CodedValidationException.cs │ │ ├── CodedValidationResult.cs │ │ ├── DatePatternAttribute.cs │ │ ├── DateTimePatternAttribute.cs │ │ ├── DotNetAttributeValidation.cs │ │ ├── IdPatternAttribute.cs │ │ ├── NarrativeValidationKind.cs │ │ ├── NarrativeXhtmlPatternAttribute.cs │ │ ├── OidPatternAttribute.cs │ │ ├── TimePatternAttribute.cs │ │ ├── UriPatternAttribute.cs │ │ ├── UuidPatternAttribute.cs │ │ ├── ValidateEnumCodeAttribute.cs │ │ └── ValidationContextExtensions.cs ├── Hl7.Fhir.Support.Tests │ ├── ElementModel │ │ ├── AnyTests.cs │ │ ├── ConceptTests.cs │ │ ├── DateTest.cs │ │ ├── DateTimeTest.cs │ │ ├── ElementNodeTests.cs │ │ ├── EquivalenceTests.cs │ │ ├── QuantityTests.cs │ │ ├── RatioTest.cs │ │ └── TimeTest.cs │ ├── ExceptionAssert.cs │ ├── FhirPath │ │ └── FhirPathTests.cs │ ├── Hl7.Fhir.Support.Tests.csproj │ ├── Introspection │ │ ├── ClassMappingTest.cs │ │ ├── ModelInspectorTest.cs │ │ ├── PropertyMappingTest.cs │ │ └── SinceFhirVersionTests.cs │ ├── JsonAssert.cs │ ├── Language │ │ └── TypeSpecifierTests.cs │ ├── Rest │ │ └── TestResourceIdentifier.cs │ ├── Serialization │ │ ├── CommonTypeParsingTest.cs │ │ ├── PrimitiveTypeConverterTest.cs │ │ ├── TestDictionaryImplementation.cs │ │ └── TypeConverterTest.cs │ ├── Specification │ │ └── AsyncSources.cs │ ├── Utility │ │ ├── AnnotationListTests.cs │ │ ├── CacheTests.cs │ │ ├── CodeGenTests.cs │ │ ├── DebugDisplayTest.cs │ │ ├── EnumMappingTest.cs │ │ ├── EnumerableExtensionTests.cs │ │ ├── ExceptionSourceTests.cs │ │ ├── FhirVersionTests.cs │ │ ├── ObjectListExtensionTests.cs │ │ └── ResultTests.cs │ └── XmlAssert.cs ├── Hl7.Fhir.Support │ ├── Hl7.Fhir.Support.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Specification │ │ └── FhirRelease.cs │ ├── Utility │ │ ├── AnnotationList.cs │ │ ├── Cache.cs │ │ ├── CodedException.cs │ │ ├── DebuggerDisplayExtensions.cs │ │ ├── DictionaryUtilities.cs │ │ ├── EnumLiteralAttribute.cs │ │ ├── EnumUtility.cs │ │ ├── EnumerableExtensions.cs │ │ ├── ExceptionSourceExtensions.cs │ │ ├── ExceptionSourcing.cs │ │ ├── FhirEnumerationAttribute.cs │ │ ├── FhirReleaseParser.cs │ │ ├── IAnnotatable.cs │ │ ├── IAnnotated.cs │ │ ├── IPositionInfo.cs │ │ ├── IntExtensions.cs │ │ ├── Logging.cs │ │ ├── ObjectList.cs │ │ ├── PredicateExtensions.cs │ │ ├── PropertyInfoExtensions.cs │ │ ├── ReflectionHelper.cs │ │ ├── Result.cs │ │ ├── SemVersion.cs │ │ ├── StringExtensions.cs │ │ ├── SyncToAsyncExtensions.cs │ │ ├── Unit.cs │ │ └── XmlNs.cs │ └── Validation │ │ └── IncorrectElementDefinitionException.cs ├── Hl7.FhirPath.Tests │ ├── Functions │ │ ├── CollectionOperatorsTests.cs │ │ ├── FunctionsTests.cs │ │ ├── MathOperatorsTests.cs │ │ ├── OperationsTests.cs │ │ └── StringFunctionsTests.cs │ ├── HL7.FhirPath.Tests.csproj │ ├── Tests │ │ ├── AssertParser.cs │ │ ├── BasicFunctionTests.cs │ │ ├── CastTests.cs │ │ ├── ConversionsTests.cs │ │ ├── FhirPathGrammarTest.cs │ │ ├── FhirPathLexerTest.cs │ │ ├── IValueProviderFPExtensionsTests.cs │ │ └── SymbolTableTests.cs │ └── Utils │ │ ├── PolyFill.cs │ │ └── TestData.cs ├── Hl7.FhirPath │ ├── FhirPath │ │ ├── CompiledExpression.cs │ │ ├── EvaluationContext.cs │ │ ├── Expressions │ │ │ ├── CallSignature.cs │ │ │ ├── Closure.cs │ │ │ ├── ClosureExtensions.cs │ │ │ ├── DynaDispatcher.cs │ │ │ ├── EvaluatorVisitor.cs │ │ │ ├── ExpressionNode.cs │ │ │ ├── ExpressionVisitor.cs │ │ │ ├── Invokee.cs │ │ │ ├── SymbolTable.cs │ │ │ ├── SymbolTableInit.cs │ │ │ ├── TreeVisualizerVisitor.cs │ │ │ └── Typecasts.cs │ │ ├── FhirPathCompiler.cs │ │ ├── FhirPathCompilerCache.cs │ │ ├── Functions │ │ │ ├── CollectionOperators.cs │ │ │ ├── ConversionOperators.cs │ │ │ ├── EqualityOperators.cs │ │ │ ├── LogicOperators.cs │ │ │ ├── MathOperators.cs │ │ │ ├── StringOperators.cs │ │ │ ├── TypeOperators.cs │ │ │ └── UtilityOperators.cs │ │ ├── Language │ │ │ └── Debugging │ │ │ │ ├── ISourcePositionInfo.cs │ │ │ │ ├── OutputEventArgs.cs │ │ │ │ ├── Source.cs │ │ │ │ ├── SourceBreakpoint.cs │ │ │ │ └── StackFrame.cs │ │ ├── Parser │ │ │ ├── Grammar.cs │ │ │ ├── Lexer.cs │ │ │ └── Operators.cs │ │ └── TypedElementFPExtensions.cs │ ├── Hl7.FhirPath.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Sprache │ │ ├── CommentParser.cs │ │ ├── IComment.cs │ │ ├── IInput.cs │ │ ├── IPositionAware.cs │ │ ├── IResultOfT.cs │ │ ├── Input.cs │ │ ├── Option.cs │ │ ├── Parse.Optional.cs │ │ ├── Parse.Positioned.cs │ │ ├── Parse.Primitives.cs │ │ ├── Parse.Regex.cs │ │ ├── Parse.Sequence.cs │ │ ├── Parse.cs │ │ ├── ParseException.cs │ │ ├── ParserOfT.cs │ │ ├── Position.cs │ │ ├── Result.cs │ │ ├── ResultHelper.cs │ │ ├── Sprache.csproj │ │ └── StringExtensions.cs ├── firely-net-common-tests.props ├── firely-net-common.props └── platforms.props └── test.bat /.gitattributes: -------------------------------------------------------------------------------- 1 | # file extensions to fail to load in VS. An alternative would be to treat 2 | * text 3 | 4 | *.bmp binary 5 | *.dll binary 6 | *.gif binary 7 | *.jpg binary 8 | *.png binary 9 | *.snk binary 10 | *.snk.enc binary 11 | *.zip binary 12 | *.exe binary 13 | *.tgz binary 14 | 15 | *.ascx text 16 | *.cd text 17 | *.cmd text 18 | *.coffee text 19 | *.config text 20 | *.cs text diff=csharp 21 | *.csproj text merge=union 22 | *.cshtml text 23 | *.css text 24 | *.dtd text 25 | *.edmx text 26 | *.htm text 27 | *.html text 28 | *.js text 29 | *.json text 30 | *.msbuild text 31 | *.nuspec text 32 | *.resx text 33 | *.ruleset text 34 | *.StyleCop text 35 | *.targets text 36 | *.tt text 37 | *.txt text 38 | *.vb text 39 | *.vbhtml text 40 | *.vbproj text merge=union 41 | *.vbs text 42 | *.wsf text 43 | *.xml text 44 | *.xunit text 45 | 46 | *.sln text eol=crlf merge=union 47 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2013-2021, HL7, Firely (info@fire.ly), Microsoft Open Technologies 4 | and contributors. See the file CONTRIBUTORS for details 5 | 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, this 15 | list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 18 | 3. Neither the name of Firely nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PLEASE NOTE 2 | 3 | > THIS REPO IS NO LONGER IN USE 4 | 5 | This repository has served as the place for code shared between the FHIR release branches for the [Firely .NET SDK](https://github.com/FirelyTeam/firely-net-sdk). However, since SDK 5.0, all these branches have been unified and this repo is no longer in use and just kept for archival purposes. 6 | 7 | 8 | _(Original README continues below)_ 9 | 10 | |Branch|| 11 | |---|---| 12 | |develop|[![Build Status](https://dev.azure.com/firely/firely-net-sdk/_apis/build/status/Common/FirelyTeam.firely-net-common?branchName=develop)](https://dev.azure.com/firely/firely-net-sdk/_build/latest?definitionId=83&branchName=develop)| 13 | 14 | |NuGet Package|| 15 | |---|---| 16 | |Hl7.Fhir.ElementModel|[![Nuget](https://img.shields.io/nuget/dt/Hl7.Fhir.ElementModel)](https://www.nuget.org/packages/Hl7.Fhir.ElementModel) | 17 | |Hl7.Fhir.Serialization|[![Nuget](https://img.shields.io/nuget/dt/Hl7.Fhir.Serialization)](https://www.nuget.org/packages/Hl7.Fhir.Serialization)| 18 | |Hl7.FhirPath|[![Nuget](https://img.shields.io/nuget/dt/Hl7.FhirPath)](https://www.nuget.org/packages/Hl7.FhirPath)| 19 | |Hl7.Fhir.Support | [![Nuget](https://img.shields.io/nuget/dt/Hl7.Fhir.Support)](https://www.nuget.org/packages/Hl7.Fhir.Support)| 20 | |Hl7.Fhir.Support.Poco|[![Nuget](https://img.shields.io/nuget/dt/Hl7.Fhir.Support.Poco)](https://www.nuget.org/packages/Hl7.Fhir.Support.Poco) | 21 | 22 | ## Introduction ## 23 | This repository is a submodule-repository for the parent [Firely .NET SDK](https://github.com/FirelyTeam/firely-net-sdk). It contains code that works across all FHIR versions (e.g. DSTU2, R4, etc) and thus is shared by the branches of the parent repository. Although it contains functionality that can be used independently (e.g. the FhirPath evaluator), all issues should be reported to the parent repo. 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /build/RetrieveVersion.ps1: -------------------------------------------------------------------------------- 1 | Push-Location $PsScriptRoot\..\src 2 | 3 | if (Test-Path ..\src\firely-net-common.props -PathType leaf) 4 | { 5 | $propFile = "..\src\firely-net-common.props" 6 | } 7 | else 8 | { 9 | $propFile = "..\src\fhir-net-common.props" # fallback to old name 10 | } 11 | 12 | $xml = [xml](get-content $propFile) 13 | 14 | #Get the version 15 | [string]$version = $xml.Project.PropertyGroup.VersionPrefix 16 | $version = $version.Trim() 17 | 18 | #Get the suffix 19 | [string]$suffix = $xml.Project.PropertyGroup.VersionSuffix 20 | $suffix = $suffix.Trim() 21 | 22 | #Setting task variable $CurrentVersion (used for VSTS) 23 | Write-Host "##vso[task.setvariable variable=CurrentVersion]$version" 24 | 25 | #Setting task variable $CurrentVersion (used for VSTS) 26 | Write-Host "##vso[task.setvariable variable=CurrentSuffix]$suffix" 27 | 28 | #go back to the original directory 29 | Pop-Location 30 | -------------------------------------------------------------------------------- /build/UpdateVersion.ps1: -------------------------------------------------------------------------------- 1 | #set the next two variables or get them from an Invoke-Expression, the rest should work automatically. 2 | Param( 3 | [string]$newVersion, 4 | [string]$suffix 5 | ) 6 | 7 | #Go to src (version is not relevant to test projects) 8 | Push-Location $PsScriptRoot\..\src 9 | 10 | if (Test-Path ..\src\firely-net-common.props -PathType leaf) 11 | { 12 | $propFile = "..\src\firely-net-common.props" 13 | } 14 | else 15 | { 16 | $propFile = "..\src\fhir-net-common.props" # fallback to old name 17 | } 18 | 19 | $xml = [xml](get-content $propFile) 20 | 21 | # newVersion is not set, so getting it from the fhir-net-api.props 22 | If ([string]::IsNullOrEmpty($newVersion)) 23 | { 24 | #Get the version (without suffix) 25 | $newVersion = $xml.Project.PropertyGroup.VersionPrefix 26 | } 27 | 28 | #Get the existing suffix 29 | [string] $oldSuffix = $xml.Project.PropertyGroup.VersionSuffix 30 | $oldSuffix = $oldSuffix.Trim() 31 | 32 | # when the suffix is not alpha (probably beta), it cannot be overriden by the parameter 33 | if (!$oldSuffix.StartsWith("alpha") -or [string]::IsNullOrEmpty($oldSuffix)) 34 | { 35 | $suffix = $oldSuffix 36 | } 37 | 38 | Write-Host "Replacing version information with version: [$newVersion] suffix: [$suffix]" 39 | 40 | #Replacing the version and suffix 41 | (Get-Content $propFile) | 42 | Foreach-Object { $_ ` 43 | -replace ".*", "$newVersion" ` 44 | -replace ".*", "$suffix" ` 45 | } | 46 | Set-Content $propFile 47 | 48 | #go back to the original directory 49 | Pop-Location 50 | -------------------------------------------------------------------------------- /build/build-variables.yml: -------------------------------------------------------------------------------- 1 | # Repo: FirelyTeam/firely-net-common 2 | # File: build/build-variables.yml 3 | # Variables used during builds. 4 | 5 | variables: 6 | NET_CORE_SDK: 6.0.x 7 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 8 | TEST_TARGETFRAMEWORK: net6.0 9 | buildConfiguration: Release -------------------------------------------------------------------------------- /build/pipeline-variables.yml: -------------------------------------------------------------------------------- 1 | # Repo: FirelyTeam/firely-net-common 2 | # File: build/pipeline-variables.yml 3 | # Variables used during the whole pipeline. 4 | 5 | variables: 6 | isTagBranch: $[startswith(variables['Build.SourceBranch'], 'refs/tags/v')] -------------------------------------------------------------------------------- /build/templates/apply-versioning-steps-template.yml: -------------------------------------------------------------------------------- 1 | # Repo: FirelyTeam/firely-net-common 2 | # File: build/templates/apply-versioning-steps-template.yml 3 | 4 | steps: 5 | - task: PowerShell@2 6 | displayName: Retrieve current version 7 | inputs: 8 | targetType: filePath 9 | filePath: $(Build.SourcesDirectory)/build/RetrieveVersion.ps1 10 | arguments: -propFile $(Build.SourcesDirectory)/src/firely-net-common.props 11 | - powershell: | 12 | if ($Env:isTagBranch -eq $false) 13 | { 14 | # append a build number when we are not releasing 15 | Write-Host "##vso[task.setvariable variable=CurrentSuffix]$Env:CurrentSuffix-$Env:BUILD_BUILDNUMBER" 16 | } 17 | displayName: 'Setting suffix' 18 | 19 | - task: PowerShell@2 20 | displayName: Setting version for common projects 21 | inputs: 22 | targetType: filePath 23 | filePath: $(Build.SourcesDirectory)/build/UpdateVersion.ps1 24 | arguments: -propFile $(Build.SourcesDirectory)/common/src/firely-net-common.props -newVersion $(CurrentVersion) -suffix "$(CurrentSuffix)" 25 | -------------------------------------------------------------------------------- /build/templates/sign-dlls-template.yml: -------------------------------------------------------------------------------- 1 | # Repo: FirelyTeam/firely-net-common 2 | # File: build/templates/signing-dlls-template-template.yml 3 | 4 | steps: 5 | - task: DownloadSecureFile@1 6 | displayName: Download Signing key file 7 | inputs: 8 | secureFile: 47f5a9d4-7009-4fe1-9cb2-c0d6122ded23 9 | retryCount: 10 | condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # not a PR 11 | - task: CopyFiles@2 12 | displayName: Copy key file to $(Build.SourcesDirectory)/src 13 | inputs: 14 | SourceFolder: $(Agent.TempDirectory) 15 | Contents: FhirNetApi.snk 16 | TargetFolder: $(Build.SourcesDirectory)/src 17 | condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # not a PR 18 | - powershell: | 19 | $commonfiles = Get-ChildItem -Path $(Build.SourcesDirectory)\src\Hl7.Fhir*\bin\Release\*\Hl7.Fhir*.dll -Exclude Hl7.Fhir*Tests 20 | 21 | Write-Verbose "Last exitcode before signing: $lastexitcode" 22 | foreach ($file in ($commonfiles)) 23 | { 24 | Write-Verbose "Signing file: $file" 25 | 26 | & '$(Build.SourcesDirectory)\build\tools\sn.exe' -R $file $(Build.SourcesDirectory)\src\FhirNetApi.snk 27 | Write-Verbose "Last exitcode after signing file: $lastexitcode" 28 | } 29 | Write-Verbose "Last exitcode after signing all files: $lastexitcode" 30 | # suppress exitcode 31 | if ($lastexitcode -lt 2) { $global:lastexitcode = 0 } 32 | displayName: Signing the dlls 33 | name: signing 34 | condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # not a PR 35 | 36 | -------------------------------------------------------------------------------- /build/templates/test-job-template.yml: -------------------------------------------------------------------------------- 1 | # Repo: FirelyTeam/firely-net-common 2 | # File: build/templates/test-job-template.yml 3 | parameters: 4 | - name: testRunTitle 5 | default: 'Test' 6 | - name: projects 7 | 8 | steps: 9 | - task: UseDotNet@2 10 | displayName: 'Use .NET Core sdk $(NET_CORE_SDK)' 11 | inputs: 12 | version: $(NET_CORE_SDK) 13 | - task: DownloadPipelineArtifact@2 14 | inputs: 15 | displayName: Download Build artifacts 16 | artifact: 'TestBuild' 17 | path: $(System.DefaultWorkingDirectory)/TestBuild 18 | 19 | - task: DotNetCoreCLI@2 20 | displayName: Running unit tests 21 | inputs: 22 | command: test 23 | projects: ${{ parameters.projects }} 24 | arguments: '-f $(TEST_TARGETFRAMEWORK) --filter TestCategory!=IntegrationTest&TestCategory!=FhirClient --collect "Code coverage"' 25 | testRunTitle: ${{ parameters.testRunTitle }} -------------------------------------------------------------------------------- /build/tools/sn.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirelyTeam/firely-net-common/6a89ed0ecf01033e6d3a70da9bfc90c6f0ba4d08/build/tools/sn.exe -------------------------------------------------------------------------------- /clean.bat: -------------------------------------------------------------------------------- 1 | msbuild Hl7.Fhir.Common.sln /t:clean /v:minimal 2 | -------------------------------------------------------------------------------- /contributors.md: -------------------------------------------------------------------------------- 1 | ## Contributors 2 | 3 | This library was a collective effort by the following developers: 4 | 5 | * Brian Postlethwaite (Telstra Health) 6 | * Ewout Kramer (Firely) 7 | * Marten Smits (Firely) 8 | * Christiaan Knaap (Firely) 9 | * Martijn Harthoorn (Firely) 10 | * Michel Rutten (Firely) 11 | * Marco Visser (Firely) 12 | * George Stoain (Endava) 13 | * Tilo Christ (Siemens) 14 | * Henley Devereux (Artisan Technology Group) 15 | * Kenneth Myhra (Kufu) 16 | 17 | 18 | HSCIC (NHS Digital) for their financial support 19 | -------------------------------------------------------------------------------- /icon-firely-sdk-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirelyTeam/firely-net-common/6a89ed0ecf01033e6d3a70da9bfc90c6f0ba4d08/icon-firely-sdk-128.png -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirelyTeam/firely-net-common/6a89ed0ecf01033e6d3a70da9bfc90c6f0ba4d08/lib/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll -------------------------------------------------------------------------------- /pack.bat: -------------------------------------------------------------------------------- 1 | msbuild /t:clean /p:configuration=release %* 2 | msbuild /t:restore /p:configuration=release %* 3 | msbuild /t:build,pack /p:configuration=release %* 4 | -------------------------------------------------------------------------------- /src/Benchmarks/Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | Benchmarks 7 | Firely.Sdk.Benchmarks.Common 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | PreserveNewest 18 | 19 | 20 | PreserveNewest 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | 3 | namespace Firely.Sdk.Benchmarks.Common 4 | { 5 | public class Program 6 | { 7 | public static void Main(string[] args) 8 | { 9 | _ = BenchmarkRunner.Run(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Benchmarks/SerializationBenchmarks.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | using Hl7.Fhir.ElementModel; 3 | using Hl7.Fhir.Model; 4 | using Hl7.Fhir.Serialization; 5 | using Hl7.Fhir.Utility; 6 | using System.IO; 7 | using System.Text.Json; 8 | 9 | namespace Firely.Sdk.Benchmarks.Common 10 | { 11 | [MemoryDiagnoser] 12 | public class SerializationBenchmarks 13 | { 14 | internal TestPatient Patient; 15 | JsonSerializerOptions Options; 16 | FhirXmlPocoSerializer XmlSerializer; 17 | 18 | 19 | [GlobalSetup] 20 | public void BenchmarkSetup() 21 | { 22 | var filename = Path.Combine("TestData", "fp-test-patient.json"); 23 | var data = File.ReadAllText(filename); 24 | // For now, deserialize with the existing deserializer, until we have completed 25 | // the dynamicserializer too. 26 | Patient = TypedSerialization.ToPoco(FhirJsonNode.Parse(data)); 27 | Options = new JsonSerializerOptions().ForFhir(typeof(TestPatient).Assembly); 28 | XmlSerializer = new FhirXmlPocoSerializer(Hl7.Fhir.Specification.FhirRelease.STU3); 29 | } 30 | 31 | [Benchmark] 32 | public string JsonDictionarySerializer() 33 | { 34 | return JsonSerializer.Serialize(Patient, Options); 35 | } 36 | 37 | [Benchmark] 38 | public string XmlDictionarySerializer() 39 | { 40 | return SerializationUtil.WriteXmlToString(Patient, (o, w) => XmlSerializer.Serialize(o, w)); 41 | } 42 | 43 | [Benchmark] 44 | public string TypedElementSerializerJson() 45 | { 46 | return TypedSerialization.ToTypedElement(Patient).ToJson(); 47 | } 48 | 49 | [Benchmark] 50 | public string TypedElementSerializerXml() 51 | { 52 | return TypedSerialization.ToTypedElement(Patient).ToXml(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/FhirNetApi.publickey: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirelyTeam/firely-net-common/6a89ed0ecf01033e6d3a70da9bfc90c6f0ba4d08/src/FhirNetApi.publickey -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/Adapters/SourceNodeToTypedElementAdapter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using Hl7.Fhir.Specification; 13 | using Hl7.Fhir.Utility; 14 | 15 | namespace Hl7.Fhir.ElementModel.Adapters 16 | { 17 | internal class SourceNodeToTypedElementAdapter : ITypedElement, IAnnotated, IExceptionSource 18 | { 19 | public readonly ISourceNode Current; 20 | 21 | public SourceNodeToTypedElementAdapter(ISourceNode node) 22 | { 23 | Current = node ?? throw Error.ArgumentNull(nameof(node)); 24 | 25 | if (node is IExceptionSource ies && ies.ExceptionHandler == null) 26 | ies.ExceptionHandler = (o, a) => ExceptionHandler.NotifyOrThrow(o, a); 27 | } 28 | 29 | private SourceNodeToTypedElementAdapter(SourceNodeToTypedElementAdapter parent, ISourceNode sourceNode) 30 | { 31 | this.Current = sourceNode; 32 | this.ExceptionHandler = parent.ExceptionHandler; 33 | } 34 | 35 | public ExceptionNotificationHandler ExceptionHandler { get; set; } 36 | 37 | public string Name => Current.Name; 38 | 39 | public string InstanceType => Current.GetResourceTypeIndicator(); 40 | 41 | public object Value => Current.Text; 42 | 43 | public string Location => Current.Location; 44 | 45 | public IElementDefinitionSummary Definition => null; 46 | 47 | public IEnumerable Children(string name) => 48 | Current.Children(name).Select(c => new SourceNodeToTypedElementAdapter(this, c)); 49 | 50 | IEnumerable IAnnotated.Annotations(Type type) => Current.Annotations(type); 51 | } 52 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/BaseTypedElement.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.ElementModel; 2 | using Hl7.Fhir.Specification; 3 | using Hl7.Fhir.Utility; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Hl7.Fhir.Serialization 8 | { 9 | /// 10 | /// A base class for creating components wrapping another component. 11 | /// 12 | /// 13 | /// By default, all members of are forwarden to the instance passed in the 14 | /// constructor, but any of the members can be overridden in the subclass. 15 | /// 16 | public class BaseTypedElement : ITypedElement, IAnnotated, IExceptionSource 17 | { 18 | public readonly ITypedElement Wrapped; 19 | 20 | public BaseTypedElement(ITypedElement wrapped) 21 | { 22 | Wrapped = wrapped; 23 | 24 | if (wrapped is IExceptionSource ies && ies.ExceptionHandler == null) 25 | ies.ExceptionHandler = (o, a) => ExceptionHandler.NotifyOrThrow(o, a); 26 | } 27 | 28 | public virtual ExceptionNotificationHandler ExceptionHandler { get; set; } 29 | 30 | public virtual string Name => Wrapped.Name; 31 | 32 | public virtual string InstanceType => Wrapped.InstanceType; 33 | 34 | public virtual object Value => Wrapped.Value; 35 | 36 | public virtual string Location => Wrapped.Location; 37 | 38 | public virtual IElementDefinitionSummary Definition => Wrapped.Definition; 39 | 40 | public virtual IEnumerable Annotations(Type type) => Wrapped.Annotations(type); 41 | public virtual IEnumerable Children(string name = null) => Wrapped.Children(name); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/DomNode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Threading; 14 | 15 | namespace Hl7.Fhir.ElementModel 16 | { 17 | public class DomNode : IAnnotatable where T : DomNode 18 | { 19 | public string Name { get; set; } 20 | 21 | private List _childList = null; 22 | 23 | protected List ChildList 24 | { 25 | get => LazyInitializer.EnsureInitialized(ref _childList, () => new()); 26 | set => _childList = value; 27 | } 28 | 29 | internal IEnumerable ChildrenInternal(string name = null) => 30 | name == null ? ChildList : ChildList.Where(c => c.Name.MatchesPrefix(name)); 31 | 32 | public T Parent { get; protected set; } 33 | 34 | public DomNodeList this[string name] => new DomNodeList(ChildrenInternal(name)); 35 | 36 | public T this[int index] => ChildList[index]; 37 | 38 | #region << Annotations >> 39 | private AnnotationList _annotations = null; 40 | protected AnnotationList AnnotationsInternal => LazyInitializer.EnsureInitialized(ref _annotations, () => new()); 41 | 42 | protected bool HasAnnotations => _annotations is not null && !_annotations.IsEmpty; 43 | 44 | public void AddAnnotation(object annotation) 45 | { 46 | AnnotationsInternal.AddAnnotation(annotation); 47 | } 48 | 49 | public void RemoveAnnotations(Type type) 50 | { 51 | AnnotationsInternal.RemoveAnnotations(type); 52 | } 53 | #endregion 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/DomNodeList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System.Collections; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | 13 | namespace Hl7.Fhir.ElementModel 14 | { 15 | public class DomNodeList : IEnumerable where T : DomNode 16 | { 17 | private readonly IList _wrapped; 18 | 19 | internal DomNodeList(IEnumerable nodes) 20 | { 21 | _wrapped = nodes.ToList(); 22 | } 23 | 24 | public T this[int index] => _wrapped[index]; 25 | 26 | public DomNodeList this[string name] => 27 | new DomNodeList(_wrapped.SelectMany(c => c.ChildrenInternal(name))); 28 | 29 | public int Count => _wrapped.Count; 30 | 31 | public bool Contains(T item) => _wrapped.Contains(item); 32 | 33 | public IEnumerator GetEnumerator() => _wrapped.GetEnumerator(); 34 | 35 | IEnumerator IEnumerable.GetEnumerator() => _wrapped.GetEnumerator(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/Hl7.Fhir.ElementModel.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.Fhir.ElementModel 7 | HL7 FHIR library for the base ElementModel classes 8 | Interfaces and classes to work with FHIR data without using POCOs. 9 | Interfaces and classes to work with FHIR data without using POCOs, in concert with the Hl7.Fhir.Serialization assembly. 10 | HL7;FHIR;Elements;Firely;SDK 11 | Hl7.Fhir.ElementModel 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/ICdaInfoSupplier.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.ElementModel 12 | { 13 | [Obsolete("The ICdaInfoSupplier interface is part of alpha-level support for parsing CDA and should not yet be used in production. This interface is subject to change.")] 14 | public interface ICdaInfoSupplier 15 | { 16 | /// 17 | /// Retrieves the xHtml text of a cda logic model 18 | /// 19 | string XHtmlText { get; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/IResourceTypeSupplier.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | 12 | namespace Hl7.Fhir.ElementModel 13 | { 14 | /// 15 | /// This interface is implemented by FHIR parsers to represent the resource type indicator 16 | /// found in the parsed data. 17 | /// 18 | public interface IResourceTypeSupplier 19 | { 20 | /// 21 | /// Gets the resource type found at the location of the node in the source data (if any). 22 | /// 23 | /// The value of resource type indicator (e.g. resourceType in json, or contained node in XML) or 24 | /// null if such an indicator was not found. 25 | string ResourceType { get; } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/IShortPathGenerator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using Hl7.Fhir.Utility; 11 | using Hl7.Fhir.Specification; 12 | using System.Collections.Generic; 13 | 14 | namespace Hl7.Fhir.ElementModel 15 | { 16 | /// 17 | /// This interface is implemented by implementers of to represent the short path 18 | /// to an element. 19 | /// 20 | /// There is a difference between the and the short path. The 21 | /// former always includes an index selector, even if the element does not repeat, whereas the short path 22 | /// only uses index selectors when necessary. As an example, a Location would be Patient.active[0], 23 | /// whereas the short path for the same location would be Patient.active. For repeating nodes, the 24 | /// location and the short path are the same. 25 | public interface IShortPathGenerator 26 | { 27 | /// 28 | /// Gets the short path of the node the represents. 29 | /// (any single cardinality nodes will be stripped of their [0] array indexer) 30 | /// 31 | /// Returns the short path, which is a dotted path notation to the node 32 | string ShortPath { get; } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | // The following GUID is for the ID of the typelib if this project is exposed to COM 5 | 6 | [assembly: CLSCompliant(true)] 7 | 8 | #if DEBUG 9 | [assembly: InternalsVisibleTo("Hl7.Fhir.ElementModel.Tests")] 10 | #endif 11 | 12 | #if RELEASE 13 | [assembly: InternalsVisibleTo("Hl7.Fhir.ElementModel.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001717d77343870eca52515a2ff9ba7ef2ff314f2f1e651f4a069401e35193d4d5124b33379a6380d510239044f012f720d395064192157eae8f67b3e4d524b79daadebd4e65ce67db327949b77bf26ca6c0f97c4ca1a578811202a537e4d112fffb2e42e852afdd71c3295c694911cdf0535f709b72ba172c40a2b1f2b607ffdc")] 14 | #endif 15 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/StructuralTypeException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.ElementModel 12 | { 13 | public class StructuralTypeException : FormatException 14 | { 15 | public StructuralTypeException() { } 16 | public StructuralTypeException(string message) : base(message) { } 17 | public StructuralTypeException(string message, Exception inner) : base(message, inner) { } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/TreeComparisonResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | 10 | namespace Hl7.Fhir.ElementModel 11 | { 12 | public struct TreeComparisonResult 13 | { 14 | public bool Success; 15 | public string FailureLocation; 16 | public string Details; 17 | 18 | public static TreeComparisonResult Fail(string location, string details = null) => 19 | new TreeComparisonResult { Success = false, FailureLocation = location, Details = details }; 20 | 21 | public static readonly TreeComparisonResult OK = new TreeComparisonResult() { Success = true }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.ElementModel/Types/DateTimePrecision.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.ElementModel.Types 10 | { 11 | public enum DateTimePrecision 12 | { 13 | Year, 14 | Month, 15 | Day, 16 | Hour, 17 | Minute, 18 | Second, 19 | 20 | /// 21 | /// Milliseconds and fractions 22 | /// 23 | Fraction 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/FhirSerializationFormats.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Serialization 10 | { 11 | /// String constants that represent FHIR resource serialization formats supported by the API. 12 | /// 13 | public class FhirSerializationFormats 14 | { 15 | /// Represents the FHIR XML resource serialization format. 16 | public const string Xml = "xml"; 17 | 18 | /// Represents the FHIR JSON resource serialization format. 19 | public const string Json = "json"; 20 | 21 | // Represents the FHIR RDF resource serialization format. 22 | // public const string Rdf = "rdf"; 23 | 24 | 25 | /// Returns an array of all defined serialization formats. 26 | public static readonly string[] All = new[] 27 | { 28 | Xml, 29 | Json, 30 | // Rdf 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/Hl7.Fhir.Serialization.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.Fhir.Serialization 7 | HL7 FHIR serialization functionality 8 | Version-independent parsering and serialization functionality 9 | Contains general interfaces and classes for working with FHIR data, regardless of FHIR version or POCO's 10 | HL7;FHIR;xml;json;parsing;serialization;Firely;SDK 11 | Hl7.Fhir.Serialization 12 | 13 | 14 | 15 | 16 | Never 17 | 18 | 19 | Never 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/JTokenExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | 10 | using Newtonsoft.Json.Linq; 11 | 12 | namespace Hl7.Fhir.Serialization 13 | { 14 | internal static class JTokenExtensions 15 | { 16 | public static JProperty GetResourceTypePropertyFromObject(this JObject o, string myName) => 17 | !(o.Property(JsonSerializationDetails.RESOURCETYPE_MEMBER_NAME) is JProperty type) ? 18 | null 19 | : type.Value.Type == JTokenType.String && myName != "instance" ? type : null; 20 | // Hack to support R4 ExampleScenario.instance.resourceType element 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/JsonSerializationDetails.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using Hl7.Fhir.ElementModel; 11 | using Hl7.Fhir.Utility; 12 | using Newtonsoft.Json.Linq; 13 | 14 | namespace Hl7.Fhir.Serialization 15 | { 16 | public class JsonSerializationDetails : IPositionInfo 17 | { 18 | public const string RESOURCETYPE_MEMBER_NAME = "resourceType"; 19 | 20 | public object OriginalValue; 21 | 22 | public int? ArrayIndex; 23 | 24 | public bool UsesShadow; 25 | 26 | public int LineNumber { get; internal set; } 27 | public int LinePosition { get; internal set; } 28 | 29 | } 30 | 31 | public static class JsonSerializationDetailsExtensions 32 | { 33 | public static JsonSerializationDetails GetJsonSerializationDetails(this IAnnotated ann) => 34 | ann.TryGetAnnotation(out var rt) ? rt : null; 35 | 36 | public static JsonSerializationDetails GetJsonSerializationDetails(this ITypedElement node) => 37 | node is IAnnotated ia ? ia.GetJsonSerializationDetails() : null; 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/MissingTypeInformationException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Serialization 12 | { 13 | public class MissingTypeInformationException : Exception 14 | { 15 | public MissingTypeInformationException() { } 16 | public MissingTypeInformationException(string message) : base(message) { } 17 | public MissingTypeInformationException(string message, Exception inner) : base(message, inner) { } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/NavigatorStreamHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Serialization 12 | { 13 | /// Common utility methods for implementations. 14 | public static class NavigatorStreamHelper 15 | { 16 | /// Default base url for generating canonical urls for Bundle entries. 17 | public static readonly string DefaultCanonicalBaseUrlForBundleEntry = "http://example.org/"; 18 | 19 | /// Generate a canonical url for a Bundle entry. 20 | /// A resource type. 21 | /// A unique resource Id. 22 | /// A fully qualified canonical url string. 23 | /// The generated url starts with the . 24 | public static string FormatCanonicalUrlForBundleEntry(string resourceType, string resourceId) 25 | => FormatCanonicalUrl(DefaultCanonicalBaseUrlForBundleEntry, resourceType, resourceId); 26 | 27 | /// Generate a canonical url from the specified base Url, resource type and id. 28 | /// A base url. 29 | /// A resource type. 30 | /// A unique resource Id. 31 | /// A fully qualified canonical url string. 32 | public static string FormatCanonicalUrl(string baseUrl, string resourceType, string resourceId) 33 | => baseUrl + resourceType + "/" + resourceId; 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // The following GUID is for the ID of the typelib if this project is exposed to COM 7 | 8 | [assembly: CLSCompliant(true)] 9 | 10 | #if DEBUG 11 | [assembly: InternalsVisibleTo("Hl7.Fhir.Serialization.Tests")] 12 | #endif -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/SerializationAnnotations.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | 10 | namespace Hl7.Fhir.Serialization 11 | { 12 | public class SourceComments 13 | { 14 | /// 15 | /// Comments encountered before this node, but after the previous sibling 16 | /// 17 | public string[] CommentsBefore; 18 | 19 | /// 20 | /// Comments encountered after the last child of this element 21 | /// 22 | public string[] ClosingComments; 23 | 24 | /// 25 | /// Comments encountered after the root element of the document 26 | /// 27 | public string[] DocumentEndComments; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/Support/GuidExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Support 10 | { 11 | public static class GuidExtensions 12 | { 13 | public static string ToFhirId(this System.Guid me) 14 | { 15 | return me.ToString("n"); 16 | } 17 | 18 | public static string ToFhirId(this System.Guid? me) 19 | { 20 | if (me.HasValue) 21 | return me.Value.ToString("n"); 22 | return null; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Serialization/XmlSerializationDetails.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.ElementModel; 10 | using Hl7.Fhir.Utility; 11 | using System; 12 | using System.Xml; 13 | using System.Xml.Linq; 14 | 15 | namespace Hl7.Fhir.Serialization 16 | { 17 | public class XmlSerializationDetails : IPositionInfo 18 | { 19 | public XmlNodeType NodeType; 20 | public XNamespace Namespace; 21 | 22 | public bool IsNamespaceDeclaration; 23 | public bool IsXhtml; 24 | 25 | public string SchemaLocation; 26 | 27 | public bool IsCDAText; 28 | public bool IsXsiType; 29 | 30 | /// 31 | /// All child XText nodes 32 | /// 33 | public string NodeText; 34 | 35 | public string OriginalValue; 36 | 37 | public int LineNumber { get; internal set; } 38 | public int LinePosition { get; internal set; } 39 | } 40 | 41 | 42 | public static class XmlSerializationDetailsExtensions 43 | { 44 | public static XmlSerializationDetails GetXmlSerializationDetails(this IAnnotated ann) => 45 | ann.TryGetAnnotation(out var rt) ? rt : null; 46 | 47 | public static XmlSerializationDetails GetXmlSerializationDetails(this ITypedElement node) => 48 | node is IAnnotated ann ? ann.GetXmlSerializationDetails() : null; 49 | } 50 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/DeepMatchTest.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using System.Collections.Generic; 4 | 5 | namespace Hl7.Fhir.Support.Poco.Tests 6 | { 7 | [TestClass] 8 | public class DeepMatchTest 9 | { 10 | [TestMethod] 11 | public void MatchingEmptyRepeatingPattern() 12 | { 13 | var concept = new CodeableConcept 14 | { 15 | Coding = new List 16 | { 17 | new Coding 18 | { 19 | Code = "foobar" 20 | } 21 | } 22 | }; 23 | 24 | var pattern = new CodeableConcept(); 25 | 26 | Assert.IsTrue(concept.Matches(pattern)); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/Hl7.Fhir.Support.Poco.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.Fhir.Support.Poco.Tests 7 | 8 | 9 | 10 | 11 | PreserveNewest 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/NewPocoSerializers/PathStackTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Hl7.Fhir.Serialization; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using System; 5 | 6 | namespace Hl7.Fhir.Support.Poco.Tests 7 | { 8 | 9 | [TestClass] 10 | public class PathStackTests 11 | { 12 | [TestMethod] 13 | public void TestPathNavigation() 14 | { 15 | var ps = new PathStack(); 16 | 17 | ps.EnterResource("A"); t("A"); 18 | 19 | ps.EnterElement("b"); t("A.b"); 20 | ps.EnterElement("c"); t("A.b.c"); 21 | ps.EnterResource("D"); t("D"); 22 | ps.EnterElement("e"); t("D.e"); 23 | 24 | Assert.ThrowsException(() => ps.ExitResource()); 25 | ps.ExitElement(); t("D"); 26 | 27 | Assert.ThrowsException(() => ps.ExitElement()); 28 | ps.ExitResource(); t("A.b.c"); 29 | 30 | ps.ExitElement(); t("A.b"); 31 | ps.ExitElement(); t("A"); 32 | 33 | Assert.ThrowsException(() => ps.ExitElement()); 34 | ps.ExitResource(); t("$this"); 35 | 36 | void t(string e) => ps.GetPath().Should().Be(e); 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/PocoValidationTests/ValidatableObjectTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Hl7.Fhir.Model; 3 | using Hl7.Fhir.Utility; 4 | using Hl7.Fhir.Validation; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using System; 7 | using System.ComponentModel.DataAnnotations; 8 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 9 | 10 | #nullable enable 11 | 12 | namespace Hl7.Fhir.Support.Poco.Tests 13 | { 14 | 15 | [TestClass] 16 | public class ValidatableObjectTests 17 | { 18 | [TestMethod] 19 | public void TestCodeOfT() 20 | { 21 | var c = new Code(null); 22 | assertValid(c); 23 | c.Value.Should().BeNull(); 24 | 25 | c = new(FilterOperator.DescendentOf); 26 | assertValid(c); 27 | c.Value.Should().Be(FilterOperator.DescendentOf); 28 | 29 | c.ObjectValue = null; 30 | assertValid(c); 31 | c.Value.Should().BeNull(); 32 | 33 | c.ObjectValue = FilterOperator.ChildOf.GetLiteral(); 34 | assertValid(c); 35 | c.Value.Should().Be(FilterOperator.ChildOf); 36 | 37 | c.ObjectValue = "wrong"; 38 | assertValid(c, e: COVE.INVALID_CODED_VALUE); 39 | Assert.ThrowsException(() => c.Value); 40 | 41 | c.ObjectValue = 4; 42 | assertValid(c, e: COVE.INVALID_CODED_VALUE); 43 | Assert.ThrowsException(() => c.Value); 44 | } 45 | 46 | 47 | private static void assertValid(IValidatableObject o, CodedValidationException? e = null) 48 | { 49 | var validationResult = o.Validate(new ValidationContext(o)); 50 | if (e is null) 51 | validationResult.Should().BeEmpty(); 52 | else 53 | { 54 | validationResult.Should().AllBeOfType(); 55 | validationResult.Should().ContainSingle(vr => ((CodedValidationResult)vr).ValidationException.ErrorCode == e.ErrorCode); 56 | } 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Introspection; 2 | 3 | [assembly: FhirModelAssembly(Hl7.Fhir.Specification.FhirRelease.STU3)] 4 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/TestData/mask-text.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
Just an example
11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco.Tests/TestData/testPackage.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirelyTeam/firely-net-common/6a89ed0ecf01033e6d3a70da9bfc90c6f0ba4d08/src/Hl7.Fhir.Support.Poco.Tests/TestData/testPackage.tgz -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/ElementModel/IFhirValueProvider.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | 3 | namespace Hl7.Fhir.ElementModel 4 | { 5 | public interface IFhirValueProvider 6 | { 7 | Base FhirValue { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/ElementModel/TypedSerialization.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Introspection; 10 | using Hl7.Fhir.Model; 11 | using Hl7.Fhir.Serialization; 12 | using System; 13 | using System.Reflection; 14 | 15 | namespace Hl7.Fhir.ElementModel 16 | { 17 | public static class TypedSerialization 18 | { 19 | public static Base ToPoco(ISourceNode source, ModelInspector inspector, PocoBuilderSettings settings = null) => 20 | new PocoBuilder(inspector, settings) 21 | .BuildFrom(source, (Type)null); 22 | 23 | public static Base ToPoco(ISourceNode source, Type pocoType, PocoBuilderSettings settings = null) => 24 | new PocoBuilder(ModelInspector.ForAssembly(pocoType.GetTypeInfo().Assembly), settings) 25 | .BuildFrom(source, pocoType ?? throw new ArgumentNullException(nameof(pocoType))); 26 | 27 | public static T ToPoco(ISourceNode source, PocoBuilderSettings settings = null) where T : Base => 28 | (T)ToPoco(source, typeof(T), settings); 29 | 30 | public static Base ToPoco(ITypedElement element, Type pocoType, PocoBuilderSettings settings = null) => 31 | new PocoBuilder(ModelInspector.ForAssembly(pocoType.GetTypeInfo().Assembly), settings) 32 | .BuildFrom(element); 33 | 34 | public static T ToPoco(ITypedElement element, PocoBuilderSettings settings = null) where T : Base => 35 | (T)ToPoco(element, typeof(T), settings); 36 | 37 | public static ITypedElement ToTypedElement(Base @base, string rootName = null) => 38 | new PocoElementNode(ModelInspector.ForAssembly(@base.GetType().GetTypeInfo().Assembly), @base, rootName: rootName); 39 | 40 | public static ISourceNode ToSourceNode(Base @base, string rootName = null) => 41 | ToTypedElement(@base, rootName).ToSourceNode(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Hl7.Fhir.Support.Poco.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.Fhir.Support.Poco 7 | HL7 FHIR library containing support classes for POCO support in the Firely .NET SDK 8 | Base classes and supporting infrastructure to work with FHIR data using POCOs. 9 | This is the support library for working with the POCO representation of HL7's FHIR model data 10 | HL7;FHIR;POCO;REST;PARSE;SERIALIZE;Firely;SDK 11 | Hl7.Fhir.Support.Poco 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Introspection/DeclaredTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Introspection 12 | { 13 | /// 14 | /// Used to indicate that the type for this property in the POCO 15 | /// does not represent the type in the FHIR specification, but rather the type given 16 | /// in the constructor to this attribute. 17 | /// 18 | [CLSCompliant(false)] 19 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 20 | public class DeclaredTypeAttribute : VersionedAttribute 21 | { 22 | public DeclaredTypeAttribute() 23 | { 24 | } 25 | 26 | public Type Type { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Introspection/NotMappedAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2013, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | using Hl7.Fhir.Utility; 32 | using System; 33 | 34 | namespace Hl7.Fhir.Introspection 35 | { 36 | [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] 37 | public sealed class NotMappedAttribute : VersionedAttribute 38 | { 39 | public NotMappedAttribute() 40 | { 41 | // This attribute is just a marker, no functionality or data 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Introspection/PropertyMappingCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | #nullable enable 10 | 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | 15 | namespace Hl7.Fhir.Introspection 16 | { 17 | internal class PropertyMappingCollection 18 | { 19 | public PropertyMappingCollection() 20 | { 21 | // nothing beyond default initializers. 22 | } 23 | 24 | public PropertyMappingCollection(Dictionary byName) 25 | { 26 | if (byName.Comparer != StringComparer.OrdinalIgnoreCase) 27 | throw new ArgumentException("Dictionary should be keyed by OrdinalIgnoreCase."); 28 | 29 | ByName = byName; 30 | ByOrder = byName.Values.OrderBy(pm => pm.Order).ToList(); 31 | ChoiceProperties = ByOrder.Where(pm => pm.Choice == ChoiceType.DatatypeChoice).ToList(); 32 | } 33 | 34 | /// 35 | /// List of the properties, in the order of appearance. 36 | /// 37 | public readonly List ByOrder = new(); 38 | 39 | /// 40 | /// The list of properties that represent choice elements. 41 | /// 42 | public readonly List ChoiceProperties = new(); 43 | 44 | /// 45 | /// List of the properties, keyed by name. 46 | /// 47 | public readonly Dictionary ByName = new(); 48 | } 49 | } 50 | 51 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Introspection/VersionedAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Specification; 10 | using Hl7.Fhir.Utility; 11 | using System; 12 | using System.ComponentModel.DataAnnotations; 13 | 14 | namespace Hl7.Fhir.Introspection 15 | { 16 | public abstract class VersionedAttribute : Attribute, IFhirVersionDependent 17 | { 18 | /// 19 | public FhirRelease Since { get; set; } = (FhirRelease)int.MinValue; 20 | } 21 | 22 | public abstract class VersionedValidationAttribute : ValidationAttribute, IFhirVersionDependent 23 | { 24 | /// 25 | public FhirRelease Since { get; set; } = (FhirRelease)int.MinValue; 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/CodeableConcept.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | using System.Linq; 32 | using S = Hl7.Fhir.ElementModel.Types; 33 | 34 | 35 | namespace Hl7.Fhir.Model 36 | { 37 | public partial class CodeableConcept 38 | { 39 | public S.Concept ToSystemConcept() 40 | { 41 | var codes = Coding.Select(c => c.ToSystemCode()); 42 | return new S.Concept(codes, display: Text); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/ElementValue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Model 10 | { 11 | public struct ElementValue 12 | { 13 | public ElementValue(string name, Base value) 14 | { 15 | ElementName = name; 16 | Value = value; 17 | } 18 | 19 | public string ElementName; 20 | public Base Value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/FhirBoolean.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class FhirBoolean 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Boolean.TryParse(value, out _); 41 | } 42 | } 43 | 44 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/FhirDecimal.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class FhirDecimal 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Decimal.TryParse(value, out _); 41 | } 42 | 43 | } 44 | 45 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/FhirString.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | */ 29 | 30 | #nullable enable 31 | 32 | namespace Hl7.Fhir.Model 33 | { 34 | public partial class FhirString 35 | { 36 | /// 37 | /// Checks whether the given literal is correctly formatted. 38 | /// 39 | public static bool IsValidValue(string value) => value.Length <= 1024 * 1024; // Note that strings SHALL NOT exceed 1MB in size 40 | } 41 | } 42 | 43 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/ISystemAndCode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012, HL7, Inc 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | namespace Hl7.Fhir.Model 32 | { 33 | /// 34 | /// Provides a way to access the system and code from a Code<T> derived class, without having to mess 35 | /// about with the generic types/additional nasty reflection 36 | /// 37 | public interface ISystemAndCode 38 | { 39 | string System { get; } 40 | string Code { get; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/IValue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Model 10 | { 11 | // [WMR 20160615] 12 | // Motivation: we want to enable polymorphism against subclasses of Primitive, especially the Value property 13 | // However subclasses of Primitive don't implement Value in a consistent way 14 | // e.g. Code is derived from Primitive but exposes a Value property of type T? 15 | // => As workaround, subclasses can implement a common IValue interface 16 | 17 | /// Common generic Value property interface. 18 | /// The value type. 19 | public interface IValue 20 | { 21 | /// Gets or sets the value 22 | T Value { get; set; } 23 | } 24 | 25 | /// Common generic nullable value property interface. 26 | /// The value type. 27 | public interface INullableValue : IValue where T : struct { } 28 | } 29 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/Id.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | 32 | #nullable enable 33 | 34 | using System.Text.RegularExpressions; 35 | 36 | 37 | namespace Hl7.Fhir.Model 38 | { 39 | public partial class Id 40 | { 41 | /// 42 | /// Checks whether the given literal is correctly formatted. 43 | /// 44 | public static bool IsValidValue(string value) => Regex.IsMatch(value, "^" + PATTERN + "$", RegexOptions.Singleline); 45 | } 46 | } 47 | 48 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/Identifier.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012, HL7, Inc 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | using System; 32 | using System.Collections.Generic; 33 | using System.Linq; 34 | using System.Text; 35 | using Hl7.Fhir.Model; 36 | 37 | 38 | namespace Hl7.Fhir.Model 39 | { 40 | [System.Diagnostics.DebuggerDisplay(@"\{ Value={ValueElement.Value} System={System}}")] 41 | public partial class Identifier 42 | { 43 | public const string SYSTMEM_URI = "urn:ietf:rfc:3986"; 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/Integer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class Integer 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Integer.TryParse(value, out _); 41 | } 42 | } 43 | 44 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/Integer64.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class Integer64 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Long.TryParse(value, out _); 41 | } 42 | } 43 | 44 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/Markdown.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class Markdown 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => FhirString.IsValidValue(value); 41 | } 42 | 43 | } 44 | 45 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/ParametersExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using Hl7.Fhir.Utility; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Hl7.Fhir.Model 9 | { 10 | public static class ParametersExtensions 11 | { 12 | public static bool TryGetDuplicates(this Parameters parameters , out IEnumerable duplicates) 13 | { 14 | duplicates = parameters.Parameter?.Select(p => p.Name)? 15 | .GroupBy(x => x) 16 | .Where(g => g.Count() > 1) 17 | .Select(y => y.Key) 18 | .ToList(); 19 | 20 | return duplicates?.Any() == true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/PositiveInt.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class PositiveInt 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Integer.TryParse(value, out var parsed) && parsed.Value > 0; 41 | } 42 | } 43 | 44 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/ResourceIdentityExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Rest; 2 | using System; 3 | 4 | namespace Hl7.Fhir.Model 5 | { 6 | public static class ResourceIdentityExtensions 7 | { 8 | /// 9 | /// Returns the entire URI of the location that this resource was retrieved from 10 | /// 11 | /// 12 | /// It is not stored, but reconstructed from the components of the resource 13 | /// 14 | /// 15 | public static ResourceIdentity ResourceIdentity(this Resource r, string baseUrl = null) 16 | { 17 | if (r.Id is null) return null; 18 | 19 | var result = Rest.ResourceIdentity.Build(r.TypeName, r.Id, r.VersionId); 20 | 21 | if (!string.IsNullOrEmpty(baseUrl)) 22 | return result.WithBase(baseUrl); 23 | 24 | return r.ResourceBase != null ? result.WithBase(r.ResourceBase) : result; 25 | } 26 | 27 | public static ResourceIdentity ResourceIdentity(this Resource r, Uri baseUrl) => r.ResourceIdentity(baseUrl.OriginalString); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/Time.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class Time 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Time.TryParse(value, out var parsed) && !parsed.HasOffset; 41 | } 42 | } 43 | 44 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Model/UnsignedInt.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011+, HL7, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of HL7 nor the names of its contributors may be used to 14 | endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | */ 30 | 31 | #nullable enable 32 | 33 | namespace Hl7.Fhir.Model 34 | { 35 | public partial class UnsignedInt 36 | { 37 | /// 38 | /// Checks whether the given literal is correctly formatted. 39 | /// 40 | public static bool IsValidValue(string value) => ElementModel.Types.Integer.TryParse(value, out var parsed) && parsed.Value >= 0; 41 | } 42 | } 43 | 44 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Rest/EntryRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | using System; 11 | 12 | namespace Hl7.Fhir.Rest 13 | { 14 | public class EntryRequest 15 | { 16 | public HTTPVerb? Method { get; set; } 17 | public string Url { get; set; } 18 | public string ContentType { get; set; } 19 | public byte[] RequestBodyContent { get; set; } 20 | public EntryRequestHeaders Headers { get; set; } 21 | public InteractionType Type { get; set; } 22 | public string Agent { get; set; } 23 | } 24 | 25 | public class EntryRequestHeaders 26 | { 27 | public string IfMatch { get; set; } 28 | public string IfNoneMatch { get; set; } 29 | public string IfNoneExist { get; set; } 30 | public DateTimeOffset? IfModifiedSince { get; set; } 31 | public string Accept { get; set; } 32 | } 33 | 34 | //Needs to be in sync with Bundle.HTTPVerbs 35 | 36 | 37 | public enum InteractionType 38 | { 39 | Search, 40 | Unspecified, 41 | Read, 42 | VRead, 43 | Update, 44 | Delete, 45 | Create, 46 | Capabilities, 47 | History, 48 | Operation, 49 | Transaction, 50 | Patch 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Rest/EntryResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.ElementModel; 10 | using System; 11 | using System.Collections.Generic; 12 | 13 | namespace Hl7.Fhir.Rest 14 | { 15 | public class EntryResponse 16 | { 17 | public string Status { get; set; } 18 | public Dictionary Headers { get; set; } 19 | public DateTimeOffset? LastModified { get; set; } 20 | public string ContentType { get; set; } 21 | public string Etag { get; set; } 22 | public byte[] Body { get; set; } 23 | public string Location { get; set; } 24 | public Uri ResponseUri { get; set; } 25 | 26 | public EntryResponse() 27 | { 28 | Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); 29 | } 30 | } 31 | 32 | 33 | public class TypedEntryResponse : EntryResponse 34 | { 35 | public ITypedElement TypedElement { get; set; } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Rest/IClientRequester.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using System; 3 | using System.Net; 4 | using System.Threading.Tasks; 5 | 6 | namespace Hl7.Fhir.Rest 7 | { 8 | public interface IClientRequester 9 | { 10 | Task ExecuteAsync(EntryRequest interaction); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Rest/TaskExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using System; 3 | using System.Threading.Tasks; 4 | using Task = System.Threading.Tasks.Task; 5 | 6 | namespace Hl7.Fhir.Rest 7 | { 8 | public static class TaskExtensions 9 | { 10 | public static T WaitResult(this Task task) where T: class 11 | { 12 | if (task == null) return null; 13 | 14 | try 15 | { 16 | task.Wait(); 17 | } 18 | catch(AggregateException ae) 19 | { 20 | //throw ae; 21 | throw ae.Flatten().InnerException; 22 | } 23 | 24 | return task.Result; 25 | } 26 | 27 | /// 28 | /// Use the WaitNoResult so that the exception handling throws what you expect, 29 | /// and not the Aggregate exception 30 | /// 31 | /// 32 | public static void WaitNoResult(this Task task) 33 | { 34 | if (task == null) return; 35 | 36 | try 37 | { 38 | task.Wait(); 39 | } 40 | catch (AggregateException ae) 41 | { 42 | //throw ae; 43 | throw ae.Flatten().InnerException; 44 | } 45 | } 46 | 47 | public static Task FromResult(TResult resultValue) 48 | { 49 | var completionSource = new TaskCompletionSource(); 50 | completionSource.SetResult(resultValue); 51 | return completionSource.Task; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Rest/TokenExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using System.Linq; 3 | 4 | namespace Hl7.Fhir.Rest 5 | { 6 | internal static class TokenExtensions 7 | { 8 | internal static string ToToken(this Coding coding) 9 | { 10 | var result = string.Empty; 11 | if (!string.IsNullOrEmpty(coding.System)) 12 | { 13 | result += $"{coding.System}|"; 14 | } 15 | return result += coding.Code; 16 | } 17 | 18 | internal static string ToToken(this CodeableConcept codeableConcept) 19 | { 20 | Coding coding = codeableConcept.Coding.FirstOrDefault(); 21 | return (coding != null) ? coding.ToToken() : string.Empty; 22 | } 23 | 24 | internal static string ToToken(this Identifier identifier) 25 | { 26 | var result = string.Empty; 27 | if (!string.IsNullOrEmpty(identifier.System)) 28 | { 29 | result += $"{identifier.System}|"; 30 | } 31 | return result += identifier.Value; 32 | } 33 | 34 | internal static string ToToken(this ContactPoint contactPoint) 35 | { 36 | var result = string.Empty; 37 | if (contactPoint.Use.HasValue) 38 | { 39 | result += $"{contactPoint.Use}|"; 40 | } 41 | return result += contactPoint.Value; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/DefaultModelFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | using System; 11 | 12 | namespace Hl7.Fhir.Serialization 13 | { 14 | public class DefaultModelFactory 15 | { 16 | public DefaultModelFactory() 17 | { 18 | } 19 | 20 | 21 | public bool CanCreate(Type type) 22 | { 23 | if (type == null) throw Error.ArgumentNull(nameof(type)); 24 | 25 | // Can create any type, as long as a public default constructor is present 26 | var canCreate = ReflectionHelper.HasDefaultPublicConstructor(type) || 27 | (ReflectionHelper.IsTypedCollection(type) && !type.IsArray); 28 | 29 | return canCreate; 30 | } 31 | 32 | 33 | public object Create(Type type) 34 | { 35 | if (type == null) throw Error.ArgumentNull(nameof(type)); 36 | // if (!type.CanBeTreatedAsType(typeof(Base))) throw Error.Argument(nameof(type), "type argument must be a subclass of Base"); 37 | 38 | // var typeToCreate = findTypeSubstitution(type); 39 | var typeToCreate = type; 40 | 41 | // For nullable types, create an instance of the type that 42 | // is made nullable, since otherwise you'll create an (untyped) null 43 | if (ReflectionHelper.IsNullableType(typeToCreate)) 44 | typeToCreate = ReflectionHelper.GetNullableArgument(typeToCreate); 45 | 46 | return Activator.CreateInstance(typeToCreate); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/DeserializationFailedException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | using Hl7.Fhir.Model; 11 | using Hl7.Fhir.Utility; 12 | using System; 13 | using System.Collections.Generic; 14 | using System.Linq; 15 | 16 | #nullable enable 17 | 18 | namespace Hl7.Fhir.Serialization 19 | { 20 | /// 21 | /// Contains the list of errors detected while deserializing data into .NET POCOs. 22 | /// 23 | /// The deserializers will continue deserialization in the face of errors, and so will collect the full 24 | /// set of errors detected using this aggregate exception. 25 | public class DeserializationFailedException : Exception 26 | { 27 | public DeserializationFailedException(Base? partialResult, IEnumerable innerExceptions) : 28 | base(generateMessage(innerExceptions)) 29 | { 30 | PartialResult = partialResult; 31 | Exceptions = innerExceptions.ToList(); 32 | } 33 | 34 | private static string generateMessage(IEnumerable exceptions) 35 | { 36 | string b = "One or more errors occurred."; 37 | if (exceptions.Any()) 38 | b += " " + string.Join(" ", exceptions.Select(e => $"({e.Message})")); 39 | 40 | return b; 41 | } 42 | 43 | 44 | /// 45 | /// The best-effort result of deserialization. Maybe invalid or incomplete because of the errors encountered. 46 | /// 47 | public Base? PartialResult { get; private set; } 48 | 49 | public IReadOnlyCollection Exceptions { get; } 50 | } 51 | } 52 | 53 | #nullable restore 54 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/ExceptionAggregator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | using Hl7.Fhir.Utility; 11 | using System.Collections; 12 | using System.Collections.Generic; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Serialization 17 | { 18 | /// 19 | /// This class is used by the deserializers to collect errors while performing deserialization. 20 | /// 21 | /// Is probably going to be used by the (future)XmlDynamicDeserializer too. 22 | internal class ExceptionAggregator : IEnumerable 23 | { 24 | public List _aggregated = new(); 25 | 26 | public void Add(CodedException? e) 27 | { 28 | if (e is not null) 29 | _aggregated.Add(e); 30 | } 31 | 32 | public void Add(IEnumerable? es) 33 | { 34 | if (es is not null) 35 | _aggregated.AddRange(es); 36 | } 37 | 38 | public bool HasExceptions => _aggregated.Count > 0; 39 | 40 | public int Count => _aggregated.Count; 41 | 42 | public IEnumerator GetEnumerator() => ((IEnumerable)_aggregated).GetEnumerator(); 43 | IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_aggregated).GetEnumerator(); 44 | } 45 | 46 | 47 | } 48 | 49 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/FhirJsonPocoSerializerSettings.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | #if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER 11 | 12 | #nullable enable 13 | 14 | using Hl7.Fhir.Model; 15 | using Hl7.Fhir.Utility; 16 | using Hl7.Fhir.Validation; 17 | using System; 18 | using System.Text.Json; 19 | 20 | namespace Hl7.Fhir.Serialization 21 | { 22 | /// 23 | /// Specify the optional features for Json serialization. 24 | /// 25 | public record FhirJsonPocoSerializerSettings 26 | { 27 | /// 28 | /// Specifies the filter to use for summary serialization. 29 | /// 30 | public SerializationFilter? SummaryFilter { get; set; } = default; 31 | } 32 | } 33 | 34 | #nullable restore 35 | #endif -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/FhirXmlPocoDeserializerSettings.cs: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | 3 | using Hl7.Fhir.Model; 4 | 5 | namespace Hl7.Fhir.Serialization 6 | { 7 | public class FhirXmlPocoDeserializerSettings 8 | { 9 | /// 10 | /// If the caller will not access base64 data in the deserialized resources, base64 decoding 11 | /// of values can be turned off to increase performance. 12 | /// 13 | /// The element's will 14 | /// still contain the unparsed base64 data and will therefore be retained and round-tripped. 15 | public bool DisableBase64Decoding { get; init; } = false; 16 | 17 | /// 18 | /// If set, this validator is invoked before the value is set in the object under construction to validate 19 | /// and possibly alter the value. Setting this property to null will disable validation completely. 20 | /// 21 | public IDeserializationValidator? Validator { get; init; } = DataAnnotationDeserialzationValidator.Default; 22 | } 23 | } 24 | 25 | #nullable restore 26 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/IDeserializationValidator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | #nullable enable 11 | 12 | using Hl7.Fhir.Validation; 13 | 14 | namespace Hl7.Fhir.Serialization 15 | { 16 | /// 17 | /// A validator that will be run to validate values while deserializing a POCO. 18 | /// 19 | public interface IDeserializationValidator 20 | { 21 | /// 22 | /// Implements validation logic to be run on a property value just before that value is used 23 | /// to initialize the property. 24 | /// 25 | /// The instance to be validated. 26 | /// The current context of deserialization, like the path and the type under deserialization. 27 | /// null, zero or more validation errors which will be aggregated in the final result of deserialization. 28 | void ValidateProperty( 29 | ref object? instance, 30 | in PropertyDeserializationContext context, 31 | out CodedValidationException[]? reportedErrors); 32 | 33 | /// 34 | /// Implements validation logic to be run on a deserialized instance. 35 | /// 36 | /// The instance to be validated 37 | /// The current context of deserialization, like the path and the type under deserialization. 38 | /// null, zero or more validation errors which will be aggregated in the final result of deserialization. 39 | void ValidateInstance( 40 | object? instance, 41 | in InstanceDeserializationContext context, 42 | out CodedValidationException[]? reportedErrors); 43 | } 44 | } 45 | 46 | #nullable restore 47 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/IsExternalInit.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | #if NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET45 || NET451 || NET452 || NET6 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 6 | 7 | // Needed for pre-net5 targets to support "init"-type setters (C# 9.0). 8 | // See also https://github.com/dotnet/roslyn/issues/45510 9 | 10 | using System.ComponentModel; 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | /// 15 | /// Reserved to be used by the compiler for tracking metadata. 16 | /// This class should not be used by developers in source code. 17 | /// 18 | [EditorBrowsable(EditorBrowsableState.Never)] 19 | internal static class IsExternalInit 20 | { 21 | } 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/PocoDeserializationHelper.cs: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | 3 | namespace Hl7.Fhir.Serialization 4 | { 5 | internal static class PocoDeserializationHelper 6 | { 7 | internal static void RunPropertyValidation(ref object? instance, IDeserializationValidator validator, PropertyDeserializationContext context, ExceptionAggregator aggregator) 8 | { 9 | validator.ValidateProperty(ref instance, context, out var errors); 10 | aggregator.Add(errors); 11 | return; 12 | } 13 | 14 | internal static void RunInstanceValidation(object? instance, IDeserializationValidator validator, InstanceDeserializationContext context, ExceptionAggregator aggregator) 15 | { 16 | validator.ValidateInstance(instance, context, out var errors); 17 | aggregator.Add(errors); 18 | return; 19 | } 20 | } 21 | } 22 | 23 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/PrimitiveValueReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.ElementModel; 10 | using Hl7.Fhir.Utility; 11 | using System; 12 | using P = Hl7.Fhir.ElementModel.Types; 13 | 14 | namespace Hl7.Fhir.Serialization 15 | { 16 | #pragma warning disable 612, 618 17 | internal class PrimitiveValueReader 18 | { 19 | private readonly ITypedElement _current; 20 | 21 | public PrimitiveValueReader(ITypedElement data) 22 | { 23 | _current = data; 24 | } 25 | 26 | 27 | internal object Deserialize(Type nativeType) 28 | { 29 | if (nativeType == null) throw Error.ArgumentNull(nameof(nativeType)); 30 | 31 | object primitiveValue = _current.Value; 32 | 33 | if (nativeType.IsEnum()) return primitiveValue; 34 | 35 | try 36 | { 37 | // The POCO's know nothing about the special partial date/time classes used by ITypedElement, 38 | // instead FhirDateTime, Time and FhirDate all represent these values as simple strings. 39 | if (primitiveValue is P.DateTime || primitiveValue is P.Time || primitiveValue is P.Date) 40 | return PrimitiveTypeConverter.ConvertTo(primitiveValue.ToString(), nativeType); 41 | else 42 | return PrimitiveTypeConverter.ConvertTo(primitiveValue, nativeType); 43 | } 44 | catch (NotSupportedException exc) 45 | { 46 | // thrown when an unsupported conversion was required 47 | ComplexTypeReader.RaiseFormatError("Not supported - " + exc.Message, _current.Location); 48 | throw; // just to satisfy the compiler - RaiseFormatError throws. 49 | } 50 | } 51 | } 52 | #pragma warning restore 612,618 53 | } 54 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/RepeatingElementReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.ElementModel; 10 | using Hl7.Fhir.Introspection; 11 | using Hl7.Fhir.Utility; 12 | using System.Collections; 13 | 14 | namespace Hl7.Fhir.Serialization 15 | { 16 | internal class RepeatingElementReader 17 | { 18 | #pragma warning disable 612, 618 19 | private readonly ITypedElement _current; 20 | private readonly ModelInspector _inspector; 21 | 22 | public ParserSettings Settings { get; private set; } 23 | 24 | internal RepeatingElementReader(ModelInspector inspector, ITypedElement reader, ParserSettings settings) 25 | { 26 | _current = reader; 27 | _inspector = inspector; 28 | 29 | Settings = settings; 30 | } 31 | 32 | #pragma warning restore 612, 618 33 | 34 | public IList Deserialize(PropertyMapping prop, string memberName, IList existing = null) 35 | { 36 | if (prop == null) throw Error.ArgumentNull(nameof(prop)); 37 | 38 | IList result = existing; 39 | 40 | if (result == null) result = ReflectionHelper.CreateGenericList(prop.ImplementingType); 41 | 42 | var reader = new DispatchingReader(_inspector, _current, Settings, arrayMode: true); 43 | result.Add(reader.Deserialize(prop, memberName)); 44 | 45 | return result; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Serialization/RootRenamer.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.ElementModel; 2 | using Hl7.Fhir.Specification; 3 | using Hl7.Fhir.Utility; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Hl7.Fhir.Serialization 8 | { 9 | internal static class RootRenamerExtensions 10 | { 11 | public static ITypedElement Rename(this ITypedElement wrapped, string name) => 12 | name != null ? new RootRenamer(wrapped, name) : wrapped; 13 | 14 | private class RootRenamer : BaseTypedElement 15 | { 16 | private readonly string _renamed; 17 | 18 | public RootRenamer(ITypedElement wrapped, string name) : base(wrapped) 19 | { 20 | _renamed = name ?? throw Error.ArgumentNull(name); 21 | } 22 | 23 | public override string Name => _renamed; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Specification/Source/IArtifactSource.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using System.Collections.Generic; 10 | using System.IO; 11 | 12 | namespace Hl7.Fhir.Specification.Source 13 | { 14 | /// Interface for browsing and resolving FHIR artifacts by filename. 15 | public interface IArtifactSource 16 | { 17 | /// Gets a list of artifact filenames. 18 | IEnumerable ListArtifactNames(); 19 | 20 | /// Load the artifact with the specified filename. 21 | /// 22 | /// This method does not support duplicate file names in separate subfolders of the content directory. 23 | /// The ISummarySource interface provides methods to unambiguously retrieve specific 24 | /// artifacts from the associated summary instance. 25 | /// 26 | Stream LoadArtifactByName(string artifactName); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Specification/Terminology/ClosureParameters.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Hl7.Fhir.Specification.Terminology 7 | { 8 | public class ClosureParameters 9 | { 10 | public ClosureParameters(string name) 11 | { 12 | if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); 13 | 14 | Name = new FhirString(name); 15 | } 16 | 17 | /// 18 | /// The name that defines the particular context for the subsumption based closure table. 19 | /// 20 | public FhirString Name { get; private set; } 21 | /// 22 | /// Concepts to add to the closure table. 23 | /// 24 | public IEnumerable Concept { get; private set; } 25 | /// 26 | /// A request to resynchronise - request to send all new entries since the nominated version was sent by the server. 27 | /// 28 | public FhirString Version { get; private set; } 29 | 30 | #region Builder methods 31 | public ClosureParameters WithConcepts(IEnumerable codings) 32 | { 33 | Concept = codings; 34 | return this; 35 | } 36 | 37 | public ClosureParameters WithVersion(string version) 38 | { 39 | if (!string.IsNullOrWhiteSpace(version)) Version = new FhirString(version); 40 | return this; 41 | } 42 | #endregion 43 | 44 | public Parameters Build() 45 | { 46 | var result = new Parameters(); 47 | 48 | if (Name is { }) result.Add("name", Name); 49 | 50 | foreach (var concept in Concept ?? Enumerable.Empty()) 51 | { 52 | result.Add("concept", concept); 53 | } 54 | 55 | if (Version is { }) result.Add("version", Version); 56 | 57 | return result; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Specification/Terminology/ContextDirection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://github.com/FirelyTeam/firely-net-sdk/blob/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | 11 | namespace Hl7.Fhir.Specification.Terminology 12 | { 13 | public enum ContextDirection 14 | { 15 | [EnumLiteral("incoming")] 16 | Incoming, 17 | [EnumLiteral("outgoing")] 18 | Outgoing, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Specification/Terminology/OperationValidCodeExtensions.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.Model; 2 | using Hl7.Fhir.Support; 3 | 4 | namespace Hl7.Fhir.Specification.Terminology 5 | { 6 | public static class OperationValidCodeExtensions 7 | 8 | { 9 | /// 10 | /// This will tranform the Out Paramters of operation ValidCode to an OperationOutcome. 11 | /// 12 | /// the Out Paramters of operation ValidCode 13 | /// OperationOutcome from parameters 14 | /// This function will be removed, when the obsolete method ITerminologyService.ValidCode() 15 | /// will be removed. 16 | public static OperationOutcome ToOperationOutcome(this Parameters parameters) 17 | { 18 | var result = parameters.GetSingleValue("result")?.Value ?? false; 19 | var message = parameters.GetSingleValue("message")?.Value; 20 | 21 | var outcome = new OperationOutcome(); 22 | if (message is { }) 23 | { 24 | var issue = result ? Issue.TERMINOLOGY_OUTPUT_WARNING : Issue.TERMINOLOGY_OUTPUT_ERROR; 25 | outcome.AddIssue(message, issue); 26 | } 27 | return outcome; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Support/ResourceReferenceNotFoundException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | using System; 11 | 12 | namespace Hl7.Fhir.Support 13 | { 14 | // [WMR 20160721] NEW 15 | 16 | /// 17 | /// The exception that is throw when an attempt to resolve an external resource reference fails. 18 | /// 19 | public class ResourceReferenceNotFoundException : Exception 20 | { 21 | private readonly string _url; 22 | 23 | // private const string defaultMessage = "Resource reference not found for url '{0}'"; 24 | private const string defaultMessage = "Unresolved resource reference. Cannot find the resource with url '{0}'."; 25 | 26 | public ResourceReferenceNotFoundException(string url) : this(url, defaultMessage.FormatWith(url)) 27 | { 28 | // 29 | } 30 | 31 | public ResourceReferenceNotFoundException(string url, string message) : base(message) 32 | { 33 | if (string.IsNullOrEmpty(url)) throw new ArgumentNullException("url"); 34 | _url = url; 35 | } 36 | 37 | /// Returns the url of the unresolved resource reference. 38 | public string Url { get { return _url; } } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Utility/NullExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System.Collections; 11 | using System.Linq; 12 | 13 | namespace Hl7.Fhir.Utility 14 | { 15 | public static class NullExtensions 16 | { 17 | // Note: argument needs to be strongly typed (List, not IList) in order to prevent resolving conflicts with generic method below 18 | 19 | /// Determines if the list is null or empty. 20 | public static bool IsNullOrEmpty(this IList list) => list == null || list.Count == 0; 21 | 22 | /// 23 | /// Determines if the element is null or empty. 24 | /// For primitive values, verifies that the value equals null. 25 | /// For primitive string values, verifies that the string value is null or empty. 26 | /// Recursively verifies that all instances are null or empty. 27 | /// 28 | 29 | public static bool IsNullOrEmpty(this Base element) 30 | { 31 | if (element == null) { return true; } 32 | 33 | var isEmpty = element is IValue ss ? string.IsNullOrEmpty(ss.Value) 34 | : !(element is PrimitiveType pp) || pp.ObjectValue == null; 35 | 36 | // Note: Children collection includes extensions 37 | return isEmpty && !element.Children.Any(c => !c.IsNullOrEmpty()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/CodePatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates a code value against the FHIR rules for code. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class CodePatternAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Code.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.CODE_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(CodePatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/CodedValidationResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System.Collections.Generic; 10 | using System.ComponentModel.DataAnnotations; 11 | #nullable enable 12 | 13 | namespace Hl7.Fhir.Validation 14 | { 15 | public class CodedValidationResult : ValidationResult 16 | { 17 | public CodedValidationException ValidationException { get; set; } 18 | 19 | public CodedValidationResult(CodedValidationException validationException) : base(validationException.Message) 20 | { 21 | ValidationException = validationException; 22 | } 23 | 24 | public CodedValidationResult(CodedValidationException validationException, IEnumerable? memberNames) 25 | : base(validationException.Message, memberNames) 26 | { 27 | ValidationException = validationException; 28 | } 29 | 30 | protected CodedValidationResult(CodedValidationResult validationResult) : base(validationResult) 31 | { 32 | ValidationException = validationResult.ValidationException; 33 | } 34 | } 35 | 36 | } 37 | 38 | #nullable restore 39 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/DatePatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates a date value against the FHIR rules for date. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class DatePatternAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Date.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.DATE_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(DatePatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/DateTimePatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates a datetime value against the FHIR rules for datetime. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class DateTimePatternAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when FhirDateTime.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.DATETIME_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(DateTimePatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/IdPatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates an id value against the FHIR rules for id. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class IdPatternAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Id.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.ID_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(IdPatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/NarrativeValidationKind.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | #nullable enable 11 | 12 | namespace Hl7.Fhir.Validation 13 | { 14 | /// 15 | /// Determine the kind of narrative validation is done. 16 | /// 17 | public enum NarrativeValidationKind 18 | { 19 | /// 20 | /// No validation is performed. 21 | /// 22 | None, 23 | 24 | /// 25 | /// Value is validated to be well-formed xml. 26 | /// 27 | Xml, 28 | 29 | /// 30 | /// Value is well-formed Xml and is valid against the FHIR rules for Narrative Xhtml. 31 | /// 32 | FhirXhtml 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/OidPatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates an Oid value against the FHIR rules for oid. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class OidPatternAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Oid.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.OID_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(OidPatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/TimePatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates a datetime value against the FHIR rules for time. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class TimePatternAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Time.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.TIME_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(TimePatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/UriPatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates an Uri value against the FHIR rules for Uri. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class UriPatternAttribute : ValidationAttribute 23 | { 24 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 25 | value switch 26 | { 27 | null => ValidationResult.Success, 28 | string s when FhirUri.IsValidValue(s) => ValidationResult.Success, 29 | string s => COVE.URI_LITERAL_INVALID.AsResult(validationContext, s), 30 | _ => throw new ArgumentException($"{nameof(UriPatternAttribute)} attributes can only be applied to string properties.") 31 | }; 32 | } 33 | } 34 | 35 | #nullable restore 36 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/UuidPatternAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates an Uuid value against the FHIR rules for Uuid. 20 | /// 21 | 22 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 23 | public class UuidPatternAttribute : ValidationAttribute 24 | { 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Uuid.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.UUID_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(UuidPatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Poco/Validation/ValidateEnumCodeAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Model; 10 | using System; 11 | using System.ComponentModel.DataAnnotations; 12 | using COVE = Hl7.Fhir.Validation.CodedValidationException; 13 | 14 | #nullable enable 15 | 16 | namespace Hl7.Fhir.Validation 17 | { 18 | /// 19 | /// Validates a code value against the FHIR rules for code. 20 | /// 21 | [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)] 22 | public class ValidateEnumCodeAttribute : ValidationAttribute 23 | { 24 | /// 25 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => 26 | value switch 27 | { 28 | null => ValidationResult.Success, 29 | string s when Code.IsValidValue(s) => ValidationResult.Success, 30 | string s => COVE.CODE_LITERAL_INVALID.AsResult(validationContext, s), 31 | _ => throw new ArgumentException($"{nameof(CodePatternAttribute)} attributes can only be applied to string properties.") 32 | }; 33 | } 34 | } 35 | 36 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/ElementModel/RatioTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Microsoft.VisualStudio.TestTools.UnitTesting; 10 | using P = Hl7.Fhir.ElementModel.Types; 11 | 12 | namespace Hl7.Fhir.ElementModel.Tests 13 | { 14 | [TestClass] 15 | public class RatioTest 16 | { 17 | [TestMethod] 18 | public void RatioConstructor() 19 | { 20 | accept("4 'cm':25 'm2'", 4, "cm", 25, "m2"); 21 | accept("4 'cm' : 25 'm2'", 4, "cm", 25, "m2"); 22 | accept("4 'cm': 25 'm2' ", 4, "cm", 25, "m2"); 23 | reject(""); 24 | reject("4 'cm'"); 25 | reject(":"); 26 | reject(": 25 'm2'"); 27 | reject("Hi12:34:44"); 28 | reject("12:34:44there"); 29 | reject("12:34:44+A"); 30 | reject("12:34:44+345:432"); 31 | reject("92:34:44"); 32 | reject("12:34:AM"); 33 | 34 | static void accept(string testValue, decimal v1, string u1, decimal v2, string u2) 35 | { 36 | Assert.IsTrue(P.Ratio.TryParse(testValue, out var parsed), "TryParse"); 37 | Assert.AreEqual(v1, parsed.Numerator.Value); 38 | Assert.AreEqual(u1, parsed.Numerator.Unit); 39 | Assert.AreEqual(v2, parsed.Denominator.Value); 40 | Assert.AreEqual(u2, parsed.Denominator.Unit); 41 | 42 | Assert.AreEqual(testValue.Replace(" ", ""), parsed.ToString().Replace(" ", ""), "ToString"); 43 | } 44 | 45 | static void reject(string testValue) 46 | { 47 | Assert.IsFalse(P.Time.TryParse(testValue, out _)); 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/ExceptionAssert.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | 4 | namespace Hl7.Fhir.Tests 5 | { 6 | public class ExceptionAssert 7 | { 8 | public static T Throws(Action action, string message = null) where T : Exception 9 | { 10 | 11 | return Assert.ThrowsException(action); 12 | } 13 | 14 | public static T Throws(Func action, string message = null) where T : Exception 15 | { 16 | 17 | return Assert.ThrowsException(action); 18 | } 19 | 20 | public static System.Threading.Tasks.Task Throws(Func action, string message = null) where T : Exception 21 | { 22 | return Assert.ThrowsExceptionAsync(action); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/Hl7.Fhir.Support.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.Fhir.Support.Tests 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/Introspection/SinceFhirVersionTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Introspection; 10 | using Hl7.Fhir.Specification; 11 | using Microsoft.VisualStudio.TestTools.UnitTesting; 12 | 13 | namespace Hl7.Fhir.Tests.Serialization 14 | { 15 | [TestClass] 16 | public class SinceFhirVersionTests 17 | { 18 | [TestMethod] 19 | public void TestSinceParameterOnAttribute() 20 | { 21 | var fea = new FhirElementAttribute("test") { Since = FhirRelease.STU3 }; 22 | Assert.IsFalse(fea.AppliesToRelease(FhirRelease.DSTU1)); 23 | Assert.IsFalse(fea.AppliesToRelease(FhirRelease.DSTU2)); 24 | Assert.IsTrue(fea.AppliesToRelease(FhirRelease.STU3)); 25 | Assert.IsTrue(fea.AppliesToRelease(FhirRelease.R4)); 26 | Assert.IsTrue(fea.AppliesToRelease((FhirRelease)int.MaxValue)); 27 | 28 | fea = new FhirElementAttribute("test2") { }; 29 | Assert.IsTrue(fea.AppliesToRelease(FhirRelease.DSTU1)); 30 | Assert.IsTrue(fea.AppliesToRelease(FhirRelease.DSTU2)); 31 | Assert.IsTrue(fea.AppliesToRelease(FhirRelease.STU3)); 32 | Assert.IsTrue(fea.AppliesToRelease((FhirRelease)int.MaxValue)); 33 | 34 | var fra = new ReferencesAttribute() { Since = FhirRelease.STU3 }; 35 | Assert.IsFalse(fra.AppliesToRelease(FhirRelease.DSTU1)); 36 | Assert.IsFalse(fra.AppliesToRelease(FhirRelease.DSTU2)); 37 | Assert.IsTrue(fra.AppliesToRelease(FhirRelease.STU3)); 38 | Assert.IsTrue(fra.AppliesToRelease(FhirRelease.R4)); 39 | Assert.IsTrue(fra.AppliesToRelease((FhirRelease)int.MaxValue)); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/Serialization/CommonTypeParsingTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.ElementModel; 10 | using Hl7.Fhir.Model; 11 | using Microsoft.VisualStudio.TestTools.UnitTesting; 12 | 13 | namespace Hl7.Fhir.Support.Tests.Serialization 14 | { 15 | [TestClass] 16 | public class CommonTypeParsingTest 17 | { 18 | [TestMethod] 19 | public void CanConvertPocoToTypedElement() 20 | { 21 | Coding c = new Coding("http://nu.nl", "bla"); 22 | var te = TypedSerialization.ToTypedElement(c); 23 | Assert.AreEqual("Coding", te.InstanceType); 24 | 25 | Coding c2 = TypedSerialization.ToPoco(te); 26 | 27 | Assert.AreEqual(c.Code, c2.Code); 28 | Assert.AreEqual(c.System, c2.System); 29 | } 30 | 31 | [TestMethod] 32 | public void CanConvertPocoToSourceNode() 33 | { 34 | Coding c = new Coding("http://nu.nl", "bla"); 35 | var sn = TypedSerialization.ToSourceNode(c, "kode"); 36 | Assert.AreEqual("kode", sn.Name); 37 | 38 | Coding c2 = TypedSerialization.ToPoco(sn); 39 | 40 | Assert.AreEqual(c.Code, c2.Code); 41 | Assert.AreEqual(c.System, c2.System); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/Utility/DebugDisplayTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Linq; 4 | using Hl7.Fhir.Utility; 5 | 6 | namespace Hl7.Fhir.Utility.Tests 7 | { 8 | [TestClass] 9 | public class DebugDisplayTests 10 | { 11 | [TestMethod] 12 | public void GetDebugDisplay() 13 | { 14 | var testee = new ClassWithDebugDisplay(); 15 | Assert.AreEqual("You found it",testee.DebuggerDisplayString()); 16 | 17 | var testee2 = new ClassWithDebugDisplay2(); 18 | Assert.AreEqual("You found it", testee2.DebuggerDisplayString()); 19 | 20 | var testee3 = new ClassWithDebugDisplay3(); 21 | Assert.AreEqual("You found me too", testee3.DebuggerDisplayString()); 22 | } 23 | } 24 | 25 | 26 | internal class ClassWithDebugDisplay 27 | { 28 | internal protected virtual string DebuggerDisplay => "You found it"; 29 | } 30 | 31 | internal class ClassWithDebugDisplay2 : ClassWithDebugDisplay 32 | { 33 | 34 | } 35 | 36 | internal class ClassWithDebugDisplay3 : ClassWithDebugDisplay 37 | { 38 | protected internal override string DebuggerDisplay => "You found me too"; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support.Tests/Utility/EnumerableExtensionTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Hl7.Fhir.Utility; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | 8 | namespace Hl7.Fhir.Support.Tests 9 | { 10 | [TestClass] 11 | 12 | public class EnumerableExtensionTests 13 | { 14 | [TestMethod] 15 | public void FiltersNullable() 16 | { 17 | var testee = new List { 1, null, 2 }; 18 | testee.WithValues().Should().BeEquivalentTo(new[] { 1, 2 }); 19 | 20 | testee = new List { null, null }; 21 | testee.WithValues().Should().BeEquivalentTo(Enumerable.Empty()); 22 | 23 | var testee2 = new List { FileMode.Open }; 24 | testee2.WithValues().Should().BeEquivalentTo(new[] { FileMode.Open }); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Hl7.Fhir.Support.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.Fhir.Support 7 | HL7 FHIR support library 8 | Common interfaces and classes used by all FHIR .NET assemblies 9 | Common interfaces and classes used by all FHIR .NET assemblies 10 | HL7;FHIR;Elements;Utility;Firely;SDK 11 | Hl7.Fhir.Support 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // The following GUID is for the ID of the typelib if this project is exposed to COM 7 | 8 | [assembly: CLSCompliant(true)] 9 | 10 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Specification/FhirRelease.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Specification 10 | { 11 | /// 12 | /// The major FHIR publication releases. 13 | /// 14 | /// Note: this is set is ordered, so "older release" is less than "newer release". 15 | public enum FhirRelease 16 | { 17 | /// 18 | /// FHIR Release DSTU1 19 | /// http://hl7.org/fhir/DSTU1 20 | /// 21 | DSTU1 = 100, 22 | /// 23 | /// FHIR Release DSTU2 24 | /// http://hl7.org/fhir/DSTU2 25 | /// 26 | DSTU2 = 200, 27 | /// 28 | /// FHIR Release STU3 29 | /// http://hl7.org/fhir/STU3 30 | /// 31 | STU3 = 300, 32 | /// 33 | /// FHIR Release 4 34 | /// http://hl7.org/fhir/R4 35 | /// 36 | R4 = 400, 37 | /// 38 | /// FHIR Release 5 39 | /// 40 | R5 = 600, 41 | /// 42 | /// FHIR Release 4B 43 | /// 44 | R4B = 500, 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/CodedException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | #nullable enable 12 | 13 | namespace Hl7.Fhir.Utility 14 | { 15 | /// 16 | /// This is a class of Exceptions that is raised by the SDK and is coded with a unique code 17 | /// to enable callers to identify this exception and react appropriately on the code. 18 | /// 19 | /// Most modules of the SDK using this Exception will create specific subclasses 20 | /// for this subclass, providing a list of codes used by that module. 21 | public class CodedException : Exception 22 | { 23 | public CodedException(string errorCode, string message) : base(message) 24 | { 25 | ErrorCode = errorCode; 26 | } 27 | 28 | public CodedException(string errorCode, string message, Exception? innerException) : base(message, innerException) 29 | { 30 | ErrorCode = errorCode; 31 | } 32 | 33 | /// 34 | /// The unique and permanent code for this error. 35 | /// 36 | /// Developers can assume that these codes will not change in future versions. 37 | public string ErrorCode { get; } 38 | } 39 | } 40 | 41 | #nullable restore 42 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/DebuggerDisplayExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Utility 10 | { 11 | public static class DebuggerDisplayExtensions 12 | { 13 | public const string DEBUGGER_DISPLAY_PROP_NAME = "DebuggerDisplay"; 14 | public static string DebuggerDisplayString(this object target) 15 | { 16 | var debuggerDisplay = ReflectionHelper.FindProperty(target.GetType(), DEBUGGER_DISPLAY_PROP_NAME); 17 | if (debuggerDisplay is null) return null; 18 | 19 | return debuggerDisplay.GetValue(target, null) as string; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/DictionaryUtilities.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System.Collections.Generic; 10 | 11 | namespace Hl7.Fhir.Utility 12 | { 13 | public static class DictionaryUtilities 14 | { 15 | public static U GetOrDefault(this IDictionary dict, T key) => 16 | dict.TryGetValue(key, out U value) ? value : default; 17 | } 18 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | 13 | #nullable enable 14 | 15 | namespace Hl7.Fhir.Utility 16 | { 17 | public static class EnumerableExtensions 18 | { 19 | /// 20 | /// Transforms an with nullable contents T? into a (possibly smaller) 21 | /// enumerable of the non-nullable type T. 22 | /// 23 | public static IEnumerable WithValues(this IEnumerable nullables) where T : struct => 24 | nullables.Where(n => n.HasValue).Select(n => n!.Value); 25 | } 26 | } 27 | 28 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/ExceptionSourcing.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Utility 12 | { 13 | public delegate void ExceptionNotificationHandler(object source, ExceptionNotification args); 14 | 15 | public interface IExceptionSource 16 | { 17 | ExceptionNotificationHandler ExceptionHandler { get; set; } 18 | } 19 | 20 | 21 | public class ExceptionNotification 22 | { 23 | public static ExceptionNotification Info(string message) => new ExceptionNotification(message, null, ExceptionSeverity.Info); 24 | 25 | public static ExceptionNotification Warning(Exception exception) => new ExceptionNotification(exception.Message, exception, ExceptionSeverity.Warning); 26 | 27 | public static ExceptionNotification Error(Exception exception) => new ExceptionNotification(exception.Message, exception, ExceptionSeverity.Error); 28 | 29 | private ExceptionNotification(string message, Exception exception, ExceptionSeverity severity) 30 | { 31 | Message = message; 32 | Exception = exception; 33 | Severity = severity; 34 | } 35 | 36 | public readonly string Message; 37 | public readonly Exception Exception; 38 | public readonly ExceptionSeverity Severity; 39 | } 40 | 41 | public enum ExceptionSeverity 42 | { 43 | Error, 44 | Warning, 45 | Info 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/IAnnotatable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Utility 12 | { 13 | public interface IAnnotatable 14 | { 15 | void AddAnnotation(object annotation); 16 | 17 | void RemoveAnnotations(Type type); 18 | } 19 | 20 | public static class AnnotatableExtensions 21 | { 22 | public static void RemoveAnnotations(this IAnnotatable annotatable) 23 | { 24 | annotatable.RemoveAnnotations(typeof(A)); 25 | } 26 | 27 | private static readonly object _lock = new object(); 28 | 29 | public static void SetAnnotation(this IAnnotatable annotatable, A annotation) 30 | { 31 | lock (_lock) 32 | { 33 | annotatable.RemoveAnnotations(); 34 | if (annotation != null) 35 | annotatable.AddAnnotation(annotation); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/IAnnotated.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | 15 | namespace Hl7.Fhir.Utility 16 | { 17 | public interface IAnnotated 18 | { 19 | IEnumerable Annotations(Type type); 20 | } 21 | 22 | public static class AnnotatedExtensions 23 | { 24 | public static object Annotation(this IAnnotated annotated, Type type) => annotated.Annotations(type)?.FirstOrDefault(); 25 | 26 | public static bool TryGetAnnotation(this IAnnotated annotated, Type type, out object annotation) 27 | { 28 | annotation = annotated.Annotations(type)?.FirstOrDefault(); 29 | return annotation != null; 30 | } 31 | 32 | public static A Annotation(this IAnnotated annotated) => (A)annotated.Annotation(typeof(A)); 33 | 34 | public static bool TryGetAnnotation(this IAnnotated annotated, out A annotation) where A:class 35 | { 36 | annotation = annotated.Annotations()?.FirstOrDefault(); 37 | return annotation != null; 38 | } 39 | 40 | public static IEnumerable Annotations(this IAnnotated annotated) => annotated.Annotations(typeof(A))?.Cast() ?? Enumerable.Empty(); 41 | 42 | public static bool HasAnnotation(this IAnnotated annotated, Type type) => annotated.Annotations(type)?.Any() == true; 43 | 44 | public static bool HasAnnotation(this IAnnotated annotated) => annotated.HasAnnotation(typeof(A)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/IPositionInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | #nullable enable 10 | 11 | namespace Hl7.Fhir.Utility 12 | { 13 | /// 14 | /// Represents an object that can provide line/position information within data being processed. 15 | /// 16 | public interface IPositionInfo 17 | { 18 | /// 19 | /// The line number within the data, starting with 1 for the first line. 20 | /// 21 | int LineNumber { get; } 22 | 23 | /// 24 | /// The position within the line, starting with 1 for the first column. 25 | /// 26 | int LinePosition { get; } 27 | } 28 | 29 | /// 30 | /// A class representing line/position information within data being processed. 31 | /// 32 | public class PositionInfo : IPositionInfo 33 | { 34 | public PositionInfo(int lineNumber, int linePosition) 35 | { 36 | LineNumber = lineNumber; 37 | LinePosition = linePosition; 38 | } 39 | 40 | /// 41 | public int LineNumber { get; } 42 | 43 | /// 44 | public int LinePosition { get; } 45 | } 46 | } 47 | 48 | #nullable restore -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/IntExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Hl7.Fhir.Utility 4 | { 5 | internal static class IntExtensions 6 | { 7 | /// 8 | /// The number of digits in a non-negative number. Returns 1 for all 9 | /// negative numbers. That is ok because we are using it to calculate 10 | /// string length for a for numbers that 11 | /// aren't supposed to be negative, but when they are it is just a little 12 | /// slower. 13 | /// 14 | /// 15 | /// This approach is based on https://stackoverflow.com/a/51099524/268898 16 | /// where the poster offers performance benchmarks showing this is the 17 | /// fastest way to get a number of digits. 18 | /// 19 | public static int Digits(this int n) 20 | { 21 | if (n < 10) return 1; 22 | if (n < 100) return 2; 23 | if (n < 1_000) return 3; 24 | if (n < 10_000) return 4; 25 | if (n < 100_000) return 5; 26 | if (n < 1_000_000) return 6; 27 | if (n < 10_000_000) return 7; 28 | if (n < 100_000_000) return 8; 29 | if (n < 1_000_000_000) return 9; 30 | return 10; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/ObjectList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | 14 | 15 | namespace Hl7.Fhir.Utility 16 | { 17 | public static class ObjectListExtensions 18 | { 19 | [Obsolete("This method is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")] 20 | public static IEnumerable OfType(this IEnumerable me, Type t) 21 | { 22 | return me.Where(e => e.GetType() == t); 23 | } 24 | 25 | [Obsolete("This method is obsolete and will be removed in the next major release. Obsolete since 2021-09-22")] 26 | public static void RemoveOfType(this IList me, Type t) 27 | { 28 | var annotations = me.OfType(t).ToArray(); 29 | 30 | foreach (var found in annotations) 31 | me.Remove(found); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/PredicateExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Utility 12 | { 13 | public static class PredicateExtensions 14 | { 15 | public static Predicate And(this Predicate first, Predicate second) => v => first(v) && second(v); 16 | public static Predicate Or(this Predicate first, Predicate second) => v => first(v) || second(v); 17 | public static Predicate Not(this Predicate first) => v => !first(v); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/SyncToAsyncExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Threading.Tasks; 12 | 13 | namespace Hl7.Fhir.Utility 14 | { 15 | public static class TaskHelper 16 | { 17 | public static T Await(Func> asyncFunc) 18 | { 19 | // Call GetAwaiter() rather then .Result to unwrap the AggregateException 20 | return Task.Run(asyncFunc).ConfigureAwait(false).GetAwaiter().GetResult(); 21 | } 22 | 23 | public static void Await(Func asyncFunc) 24 | { 25 | // Call GetAwaiter() rather then .Result to unwrap the AggregateException 26 | Task.Run(asyncFunc).ConfigureAwait(false).GetAwaiter().GetResult(); 27 | } 28 | 29 | public static async Task AnyAsync(this IEnumerable source, Func> predicate) 30 | { 31 | foreach (var elem in source) 32 | if (await predicate(elem).ConfigureAwait(false)) return true; 33 | 34 | return false; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/Unit.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Utility 10 | { 11 | /// 12 | /// Units is the formal type with one element and has no representation in .NET. 13 | /// It is used to provide a type where none is wanted or expected, e.g. to supply 14 | /// a mandatory generic type argument to a monad when no real value needs to be 15 | /// represented in the monad. 16 | /// 17 | /// It's unfortunate that Microsoft does not allow us to use the already 18 | /// existing System.Void type for this - which is defined more or less equivalently. 19 | /// 20 | public struct Unit 21 | { 22 | public override bool Equals(object obj) => obj is Unit; 23 | public override int GetHashCode() => 0; 24 | public override string ToString() => "unit value"; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Utility/XmlNs.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Reflection; 14 | using System.Text; 15 | using System.Xml.Linq; 16 | 17 | namespace Hl7.Fhir.Utility 18 | { 19 | public static class XmlNs 20 | { 21 | public const string FHIR = "http://hl7.org/fhir"; 22 | public const string XHTML = "http://www.w3.org/1999/xhtml"; 23 | public const string NAMESPACE = "http://www.w3.org/XML/1998/namespace"; 24 | public const string XMLNS = "http://www.w3.org/2000/xmlns/"; 25 | 26 | public static readonly XNamespace XFHIR = FHIR; 27 | public static readonly XNamespace XHTMLNS = XHTML; 28 | 29 | public static readonly XName XHTMLDIV = XmlNs.XHTMLNS + "div"; 30 | public static readonly XName XSCHEMALOCATION = XName.Get("{http://www.w3.org/2001/XMLSchema-instance}schemaLocation"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Hl7.Fhir.Support/Validation/IncorrectElementDefinitionException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Validation 12 | { 13 | public class IncorrectElementDefinitionException : Exception 14 | { 15 | public IncorrectElementDefinitionException(string message) : base(message) 16 | { 17 | } 18 | 19 | public IncorrectElementDefinitionException(string message, Exception innerException) : base(message, innerException) 20 | { 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/Functions/CollectionOperatorsTests.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.ElementModel; 2 | using Hl7.FhirPath.Functions; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using System.Linq; 5 | 6 | namespace HL7.FhirPath.Tests.Functions 7 | { 8 | [TestClass] 9 | public class CollectionOperatorsTests 10 | { 11 | [TestMethod] 12 | public void Intersect() 13 | { 14 | var a = ElementNode.ForPrimitive("A"); 15 | var b1 = ElementNode.ForPrimitive("B"); 16 | var c = ElementNode.ForPrimitive("C"); 17 | var b2 = ElementNode.ForPrimitive("B"); 18 | 19 | var col1 = new ITypedElement[] { a, b1 }; 20 | var col2 = new ITypedElement[] { c, b2 }; 21 | var col3 = new ITypedElement[] { c }; 22 | 23 | var result = col1.Intersect(col2); 24 | Assert.IsNotNull(result); 25 | Assert.AreEqual("B", result.First().Value); 26 | 27 | result = col2.Intersect(col1); 28 | Assert.IsNotNull(result); 29 | Assert.AreEqual("B", result.First().Value); 30 | 31 | result = col1.Intersect(col3); 32 | Assert.IsNotNull(result); 33 | Assert.IsFalse(result.Any()); 34 | } 35 | 36 | 37 | [TestMethod] 38 | public void TestIntersect() 39 | { 40 | var left = ElementNode.CreateList(1, 3, 3, 5, 6); 41 | var right = ElementNode.CreateList(3, 5, 5, 6, 8); 42 | CollectionAssert.AreEqual(ElementNode.CreateList(3, 5, 6).ToList(), 43 | left.Intersect(right).ToList()); 44 | } 45 | 46 | [TestMethod] 47 | public void TestExclude() 48 | { 49 | var left = ElementNode.CreateList(1, 3, 3, 5, 6); 50 | var right = ElementNode.CreateList(5, 6); 51 | CollectionAssert.AreEqual(ElementNode.CreateList(1, 3, 3).ToList(), 52 | left.Exclude(right).ToList()); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/Functions/MathOperatorsTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Hl7.FhirPath.FhirPath.Functions; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace HL7.FhirPath.Tests.Functions 6 | { 7 | [TestClass] 8 | public class MathOperatorsTests 9 | { 10 | [TestMethod] 11 | public void Sqrt() 12 | { 13 | (-1.0m).Sqrt().Should().BeNull(); 14 | 15 | 4.0m.Sqrt().Should().BeOfType(typeof(decimal)); 16 | } 17 | 18 | [TestMethod] 19 | public void Power() 20 | { 21 | (-1.0m).Power(0.5m).Should().BeNull(); 22 | 23 | 2m.Power(2m).Should().BeOfType(typeof(decimal)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/HL7.FhirPath.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Hl7.FhirPath.Tests 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/Tests/IValueProviderFPExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Hl7.Fhir.ElementModel; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using System; 5 | using System.Reflection; 6 | 7 | namespace Hl7.FhirPath.Tests 8 | { 9 | [TestClass] 10 | public class IValueProviderFPExtensionsTests 11 | { 12 | [TestMethod] 13 | public void CacheInitializedWithUserDefinedSizeTest() 14 | { 15 | // Reinitialize the cache, because it could be already initialized by other unittests 16 | IValueProviderFPExtensions.ReInitializeCache(); 17 | 18 | // arrange and act 19 | IValueProviderFPExtensions.MAX_FP_EXPRESSION_CACHE_SIZE = 3000; 20 | var node = ElementNode.ForPrimitive("string"); 21 | // the select will initialize the cache 22 | node.Select("exists()"); 23 | 24 | // assert 25 | var cacheField = typeof(IValueProviderFPExtensions).GetField("CACHE", BindingFlags.Static | BindingFlags.NonPublic); 26 | cacheField.Should().NotBeNull(); 27 | 28 | var lazy = cacheField.GetValue(null) as Lazy; 29 | lazy.IsValueCreated.Should().BeTrue(); 30 | 31 | var cacheSizeField = typeof(FhirPathCompilerCache).GetField("_cacheSize", BindingFlags.NonPublic | BindingFlags.Instance); 32 | cacheSizeField.Should().NotBeNull(); 33 | var cacheSize = cacheSizeField.GetValue(lazy.Value) as int?; 34 | cacheSize.Should().Be(3000); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/Tests/SymbolTableTests.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.ElementModel; 2 | using Hl7.FhirPath; 3 | using Hl7.FhirPath.Expressions; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using System; 6 | using System.Threading.Tasks; 7 | 8 | namespace HL7.FhirPath.Tests.Tests 9 | { 10 | [TestClass] 11 | public class SymbolTableTests 12 | { 13 | [TestMethod] 14 | public void SymbolTableUsedByMultipleThreads() 15 | { 16 | // setup multiple tasks 17 | Task[] taskArray = new Task[10]; 18 | for (int i = 0; i < taskArray.Length; i++) 19 | { 20 | taskArray[i] = new Task(compile); 21 | } 22 | 23 | // execute the tasks in parallel 24 | try 25 | { 26 | Parallel.ForEach(taskArray, (t) => { t.Start(); }); 27 | Task.WaitAll(taskArray); 28 | 29 | } 30 | catch (Exception ex) 31 | { 32 | Assert.Fail(ex.Message + " " + ex.StackTrace); 33 | } 34 | 35 | void compile() 36 | { 37 | var compiler = new FhirPathCompiler(); 38 | compiler.Symbols.Add("noOp", NoOp); 39 | compiler.Compile("(CapabilityStatement.useContext.value as Quantity) | (CapabilityStatement.useContext.value as Range)"); 40 | 41 | static ITypedElement NoOp(ITypedElement elem, bool condition, string message, EvaluationContext ctx) => elem; 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/Utils/PolyFill.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Xml.Linq; 8 | 9 | namespace Hl7.FhirPath.Tests 10 | { 11 | public static class PolyFill 12 | { 13 | public static string TryGetAttribute(this XElement element, string name, out bool exists) 14 | { 15 | XAttribute attr = element.Attributes().FirstOrDefault(a => a.Name == name); 16 | exists = (attr != null); 17 | return attr?.Value; 18 | } 19 | } 20 | 21 | public static class Test 22 | { 23 | public static void Fail(string message) 24 | { 25 | throw new Exception("Test failed. "+ message); 26 | } 27 | 28 | public static bool IsInstanceOfType(object value, Type expectedType) 29 | { 30 | return value.GetType().GetTypeInfo().IsAssignableFrom(expectedType); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath.Tests/Utils/TestData.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Hl7.FhirPath.Tests 4 | { 5 | public static class TestData 6 | { 7 | public static string ReadTextFile(string name) 8 | { 9 | string file = Path.Combine("TestData", name); 10 | return File.ReadAllText(file); 11 | } 12 | 13 | public static string GetTestDataBasePath() 14 | { 15 | return "TestData"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/EvaluationContext.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.ElementModel; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Hl7.FhirPath 6 | { 7 | public class EvaluationContext 8 | { 9 | public static EvaluationContext CreateDefault() => new(); 10 | 11 | public EvaluationContext() 12 | { 13 | // no defaults yet 14 | } 15 | 16 | /// 17 | /// Create an EvaluationContext with the given value for %resource. 18 | /// 19 | /// The data that will be represented by %resource 20 | public EvaluationContext(ITypedElement resource) : this(resource, null) { } 21 | 22 | /// 23 | /// Create an EvaluationContext with the given value for %resource and %rootResource. 24 | /// 25 | /// The data that will be represented by %resource. 26 | /// The data that will be represented by %rootResource. 27 | public EvaluationContext(ITypedElement resource, ITypedElement rootResource) 28 | { 29 | Resource = resource; 30 | RootResource = rootResource ?? resource; 31 | } 32 | 33 | /// 34 | /// The data represented by %rootResource. 35 | /// 36 | public ITypedElement RootResource { get; set; } 37 | 38 | /// 39 | /// The data represented by %resource. 40 | /// 41 | public ITypedElement Resource { get; set; } 42 | 43 | /// 44 | /// A delegate that handles the output for the trace() function. 45 | /// 46 | public Action> Tracer { get; set; } 47 | 48 | #region Obsolete members 49 | [Obsolete("Please use CreateDefault() instead of this member, which may cause raise conditions.")] 50 | public static readonly EvaluationContext Default = new(); 51 | #endregion 52 | } 53 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Expressions/CallSignature.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | 13 | namespace Hl7.FhirPath.Expressions 14 | { 15 | internal class CallSignature 16 | { 17 | public string Name { get; private set; } 18 | 19 | public Type[] ArgumentTypes { get; private set; } 20 | 21 | public Type ReturnType { get; private set; } 22 | 23 | public CallSignature(string name, Type returnType, params Type[] argTypes ) 24 | { 25 | Name = name; 26 | ArgumentTypes = argTypes; 27 | ReturnType = returnType; 28 | } 29 | 30 | //public bool Matches(string functionName, IEnumerable argumentTypes) 31 | //{ 32 | // return functionName == Name && argumentTypes.Count() == ArgumentTypes.Count() && 33 | // argumentTypes.Zip(ArgumentTypes, (call, sig) => Typecasts.CanCastTo(call,sig)).All(r => r == true); 34 | //} 35 | 36 | public bool DynamicMatches(string functionName, IEnumerable arguments) 37 | { 38 | return functionName == Name && arguments.Count() == ArgumentTypes.Count() && 39 | arguments.Zip(ArgumentTypes, (call, sig) => Typecasts.CanCastTo(call, sig)).All(r => r == true); 40 | } 41 | public bool DynamicExactMatches(string functionName, IEnumerable arguments) 42 | { 43 | return functionName == Name && arguments.Count() == ArgumentTypes.Count() && 44 | arguments.Zip(ArgumentTypes, (call, sig) => Typecasts.IsOfExactType(call, sig)).All(r => r == true); 45 | } 46 | 47 | public bool Matches(string functionName, int argCount) 48 | { 49 | return functionName == Name && ArgumentTypes.Count() == argCount; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Expressions/ExpressionVisitor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | 15 | namespace Hl7.FhirPath.Expressions 16 | { 17 | public abstract class ExpressionVisitor 18 | { 19 | //public void Visit(Expression expression) 20 | //{ 21 | // if (expression is ConstantExpression) 22 | // VisitConstant((ConstantExpression)expression); 23 | // else if (expression is FunctionCallExpression) 24 | // VisitFunctionCall((FunctionCallExpression)expression); 25 | // else if (expression is LambdaExpression) 26 | // VisitLambda((LambdaExpression)expression); 27 | // else if (expression is NewNodeListInitExpression) 28 | // VisitNewNodeListInit((NewNodeListInitExpression)expression); 29 | // else if (expression is VariableRefExpression) 30 | // VisitVariableRef((VariableRefExpression)expression); 31 | //} 32 | 33 | public abstract T VisitConstant(ConstantExpression expression, SymbolTable scope); 34 | 35 | public abstract T VisitFunctionCall(FunctionCallExpression expression, SymbolTable scope); 36 | 37 | //public abstract T VisitLambda(LambdaExpression expression); 38 | 39 | public abstract T VisitNewNodeListInit(NewNodeListInitExpression expression, SymbolTable scope); 40 | 41 | public abstract T VisitVariableRef(VariableRefExpression expression, SymbolTable scope); 42 | 43 | //public abstract T VisitTypeBinaryExpression(TypeBinaryExpression expression); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Functions/MathOperators.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hl7.FhirPath.FhirPath.Functions 4 | { 5 | internal static class MathOperators 6 | { 7 | public static decimal? Sqrt(this decimal focus) 8 | { 9 | var result = Math.Sqrt((double)focus); 10 | return double.IsNaN(result) ? (decimal?)null : (decimal)result; 11 | } 12 | 13 | public static decimal? Power(this decimal focus, decimal exponent) 14 | { 15 | var result = Math.Pow((double)focus, (double)exponent); 16 | return double.IsNaN(result) ? (decimal?)null : (decimal)result; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Functions/TypeOperators.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using Hl7.Fhir.ElementModel; 13 | using Hl7.Fhir.Utility; 14 | 15 | namespace Hl7.FhirPath.Functions 16 | { 17 | internal static class TypeOperators 18 | { 19 | public static bool Is(this ITypedElement focus, string type) 20 | { 21 | if (focus.InstanceType != null) 22 | { 23 | return Is(focus.InstanceType, type); // I have no information about classes/subclasses 24 | } 25 | else 26 | throw Error.InvalidOperation("Is operator is called on untyped data"); 27 | } 28 | 29 | public static bool Is(string instanceType, string declaredType) 30 | { 31 | // Bit of a hack, this hardwires the FhirPath implementation to FHIR 32 | if (!instanceType.Contains(".")) instanceType = "FHIR." + instanceType; 33 | if (declaredType.Contains(".")) 34 | return instanceType == declaredType; 35 | else 36 | { 37 | return instanceType == "System." + declaredType || 38 | instanceType == "FHIR." + declaredType; 39 | } 40 | } 41 | 42 | public static IEnumerable FilterType(this IEnumerable focus, string typeName) 43 | => focus.Where(item => item.Is(typeName)); 44 | 45 | public static ITypedElement CastAs(this ITypedElement focus, string typeName) 46 | => focus.Is(typeName) ? focus : null; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Functions/UtilityOperators.cs: -------------------------------------------------------------------------------- 1 | using Hl7.Fhir.ElementModel; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | 7 | namespace Hl7.FhirPath.Functions 8 | { 9 | internal static class UtilityOperators 10 | { 11 | public static IEnumerable Extension(this IEnumerable focus, string url) 12 | { 13 | return focus.Navigate("extension") 14 | .Where(es => es.Children("url").SingleOrDefault().Value as string == url); 15 | } 16 | 17 | public static IEnumerable Trace(this IEnumerable focus, string name, EvaluationContext ctx) 18 | { 19 | ctx.Tracer?.Invoke(name, focus); 20 | return focus; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Language/Debugging/ISourcePositionInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | using System; 11 | 12 | namespace Hl7.Fhir.Language.Debugging 13 | { 14 | public interface ISourcePositionInfo : IPositionInfo 15 | { 16 | Source Source { get; } 17 | } 18 | 19 | 20 | public static class PositionInfoExtensions 21 | { 22 | private static readonly Random _generator = new Random((int)DateTimeOffset.Now.UtcTicks); 23 | 24 | public static StackFrame ToStackFrame(this ISourcePositionInfo location, string name = null) => 25 | new StackFrame 26 | { 27 | 28 | Id = _generator.Next(), 29 | Column = location.LinePosition, 30 | Line = location.LineNumber, 31 | Name = name, 32 | Source = location.Source 33 | }; 34 | 35 | public static string GetLocationLabel(this ISourcePositionInfo loc) 36 | { 37 | if (loc == null) throw new ArgumentNullException(nameof(loc)); 38 | 39 | var result = $"line {loc.LineNumber}"; 40 | if (loc.LinePosition > 0) result += $", column {loc.LinePosition}"; 41 | return result; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Language/Debugging/OutputEventArgs.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using System; 10 | 11 | namespace Hl7.Fhir.Language.Debugging 12 | { 13 | /// 14 | /// The event indicates that the debuggee has produced some output. 15 | /// 16 | public class OutputEventArgs : EventArgs 17 | { 18 | /// 19 | /// The output category. 20 | /// 21 | public OutputCategory Category { get; set; } 22 | 23 | /// 24 | /// The output to report. 25 | /// 26 | public string Output { get; set; } 27 | 28 | /// 29 | /// An optional source location where the output was produced. 30 | /// 31 | public Source Source { get; set; } 32 | 33 | /// 34 | /// An optional source location line where the output was produced. 35 | /// 36 | public int? Line { get; set; } 37 | 38 | /// 39 | /// An optional source location column where the output was produced. 40 | /// 41 | public int? Column { get; set; } 42 | } 43 | 44 | public enum OutputCategory 45 | { 46 | Console, 47 | StdOut, 48 | StdErr, 49 | Telemetry 50 | } 51 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Language/Debugging/Source.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Language.Debugging 10 | { 11 | /// 12 | /// A Source is a descriptor for source code. It is returned from the debug adapter as part of a StackFrame and 13 | /// it is used by clients when specifying breakpoints. 14 | /// 15 | public class Source 16 | { 17 | /// 18 | /// The short name of the source. 19 | /// 20 | /// 21 | /// Every source returned from the debug adapter has a name. When sending a source to the debug adapter this name is optional. 22 | /// 23 | public string Name { get; set; } 24 | 25 | /// 26 | /// The path of the source to be shown in the UI. 27 | /// 28 | /// It is only used to locate and load the content of the source if no sourceReference is specified (or its value is 0). 29 | /// 30 | public string Path { get; set; } 31 | 32 | /// 33 | /// Id for the source. 34 | /// 35 | /// 36 | /// If sourceReference > 0 the contents of the source must be retrieved through the SourceRequest (even if a path is specified). 37 | /// A sourceReference is only valid for a session, so it must not be used to persist a source. 38 | /// 39 | public int SourceReference { get; set; } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Language/Debugging/SourceBreakpoint.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | namespace Hl7.Fhir.Language.Debugging 10 | { 11 | /// 12 | /// Properties of a breakpoint or logpoint passed to the setBreakpoints request. 13 | /// 14 | public class SourceBreakpoint 15 | { 16 | /// 17 | /// The source line of the breakpoint or logpoint. 18 | /// 19 | public int Line { get; set; } 20 | 21 | /// 22 | /// An optional source column of the breakpoint. 23 | /// 24 | public int? Column { get; set; } 25 | 26 | /// 27 | /// An optional expression for conditional breakpoints. 28 | /// 29 | public string Condition { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Language/Debugging/StackFrame.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.Fhir.Utility; 10 | 11 | namespace Hl7.Fhir.Language.Debugging 12 | { 13 | /// 14 | /// Source location and other details about a stackframe. 15 | /// 16 | public class StackFrame : ISourcePositionInfo 17 | { 18 | /// 19 | /// An identifier for the stack frame. 20 | /// 21 | /// 22 | /// It must be unique across all threads. This id can be used to retrieve the scopes of the frame with the 23 | /// 'scopesRequest' or to restart the execution of a stackframe. 24 | /// 25 | public int Id { get; set; } 26 | 27 | /// 28 | /// The name of the stack frame, typically a method name. 29 | /// 30 | public string Name { get; set; } 31 | 32 | /// 33 | /// The optional source of the frame. 34 | /// 35 | public Source Source { get; set; } 36 | 37 | /// 38 | /// The line within the file of the frame. 39 | /// 40 | /// 41 | /// If source is null or doesn't exist, line is 0 and must be ignored. 42 | /// 43 | public int Line { get; set; } 44 | 45 | /// 46 | /// The column within the line. 47 | /// 48 | /// 49 | /// If source is null or doesn't exist, column is 0 and must be ignored. 50 | /// 51 | public int Column { get; set; } 52 | 53 | Source ISourcePositionInfo.Source => Source; 54 | 55 | int IPositionInfo.LineNumber => Line; 56 | 57 | int IPositionInfo.LinePosition => Column; 58 | 59 | public override string ToString() => $"{Name}[{Id}]"; 60 | } 61 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/FhirPath/Parser/Operators.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Firely (info@fire.ly) and contributors 3 | * See the file CONTRIBUTORS for details. 4 | * 5 | * This file is licensed under the BSD 3-Clause license 6 | * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE 7 | */ 8 | 9 | using Hl7.FhirPath.Sprache; 10 | using System.Linq; 11 | using System.Collections.Generic; 12 | 13 | 14 | namespace Hl7.FhirPath.Parser 15 | { 16 | internal partial class Lexer 17 | { 18 | internal static Parser Operator(params string[] ops ) 19 | { 20 | var first = Parse.String(ops.First()).Token(); 21 | return ops.Skip(1).Aggregate(first, (expr, s) => expr.Or(Parse.String(s).Token()), expr => expr.Text()); 22 | } 23 | 24 | internal static readonly Parser PolarityOperator = Lexer.Operator("+", "-"); 25 | internal static readonly Parser MulOperator = Lexer.Operator("*","/","div","mod"); 26 | internal static readonly Parser AddOperator = Lexer.Operator("+", "-", "&"); 27 | internal static readonly Parser UnionOperator = Lexer.Operator("|"); 28 | 29 | // NOTE: ORDER MATTERS, since otherwise shorter ops will be recognized before longer ones! 30 | internal static readonly Parser InEqOperator = Lexer.Operator("<=", "<", ">=", ">"); 31 | internal static readonly Parser TypeOperator = Lexer.Operator("is", "as"); 32 | 33 | // NOTE: ORDER MATTERS, since otherwise shorter ops will be recognized before longer ones! 34 | internal static readonly Parser EqOperator = Lexer.Operator("=", "~", "!=", "!~"); 35 | internal static readonly Parser MembershipOperator = Lexer.Operator("in", "contains"); 36 | internal static readonly Parser AndOperator = Lexer.Operator("and"); 37 | internal static readonly Parser OrOperator = Lexer.Operator("or", "xor"); 38 | internal static readonly Parser ImpliesOperator = Lexer.Operator("implies"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Hl7.FhirPath.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Hl7.FhirPath 7 | HL7 FhirPath evaluator 8 | Runtime environment for executing HL7 FhirPath queries and invariants. 9 | This library contains a runtime environment for executing HL7 FhirPath queries and invariants. It is used by the Firely .NET SDK to run validation for the HL7 FHIR object model. 10 | HL7;FluentPath;FhirPath;query language;CQL;FHIR;Firely;SDK 11 | Hl7.FhirPath 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | // The following GUID is for the ID of the typelib if this project is exposed to COM 5 | 6 | [assembly: CLSCompliant(true)] 7 | 8 | #if DEBUG 9 | [assembly: InternalsVisibleTo("Hl7.FhirPath.Tests")] 10 | [assembly: InternalsVisibleTo("Hl7.FhirPath.R4.Tests")] 11 | [assembly: InternalsVisibleTo("Hl7.Fhir.Core.Tests")] 12 | [assembly: InternalsVisibleTo("Hl7.Fhir.Support.Tests")] 13 | #endif 14 | 15 | #if RELEASE 16 | // https://docs.microsoft.com/en-us/dotnet/standard/assembly/create-signed-friend 17 | [assembly: InternalsVisibleTo("Hl7.FhirPath.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001717d77343870eca52515a2ff9ba7ef2ff314f2f1e651f4a069401e35193d4d5124b33379a6380d510239044f012f720d395064192157eae8f67b3e4d524b79daadebd4e65ce67db327949b77bf26ca6c0f97c4ca1a578811202a537e4d112fffb2e42e852afdd71c3295c694911cdf0535f709b72ba172c40a2b1f2b607ffdc")] 18 | [assembly: InternalsVisibleTo("Hl7.FhirPath.R4.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001717d77343870eca52515a2ff9ba7ef2ff314f2f1e651f4a069401e35193d4d5124b33379a6380d510239044f012f720d395064192157eae8f67b3e4d524b79daadebd4e65ce67db327949b77bf26ca6c0f97c4ca1a578811202a537e4d112fffb2e42e852afdd71c3295c694911cdf0535f709b72ba172c40a2b1f2b607ffdc")] 19 | [assembly: InternalsVisibleTo("Hl7.Fhir.Core.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001717d77343870eca52515a2ff9ba7ef2ff314f2f1e651f4a069401e35193d4d5124b33379a6380d510239044f012f720d395064192157eae8f67b3e4d524b79daadebd4e65ce67db327949b77bf26ca6c0f97c4ca1a578811202a537e4d112fffb2e42e852afdd71c3295c694911cdf0535f709b72ba172c40a2b1f2b607ffdc")] 20 | [assembly: InternalsVisibleTo("Hl7.Fhir.Support.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001717d77343870eca52515a2ff9ba7ef2ff314f2f1e651f4a069401e35193d4d5124b33379a6380d510239044f012f720d395064192157eae8f67b3e4d524b79daadebd4e65ce67db327949b77bf26ca6c0f97c4ca1a578811202a537e4d112fffb2e42e852afdd71c3295c694911cdf0535f709b72ba172c40a2b1f2b607ffdc")] 21 | #endif -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/IComment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Hl7.FhirPath.Sprache 7 | { 8 | interface IComment 9 | { 10 | /// 11 | ///Single-line comment header. 12 | /// 13 | string Single { get; set; } 14 | 15 | /// 16 | ///Newline character preference. 17 | /// 18 | string NewLine { get; set; } 19 | 20 | /// 21 | ///Multi-line comment opener. 22 | /// 23 | string MultiOpen { get; set; } 24 | 25 | /// 26 | ///Multi-line comment closer. 27 | /// 28 | string MultiClose { get; set; } 29 | 30 | /// 31 | ///Parse a single-line comment. 32 | /// 33 | Parser SingleLineComment { get; } 34 | 35 | /// 36 | ///Parse a multi-line comment. 37 | /// 38 | Parser MultiLineComment { get; } 39 | 40 | /// 41 | ///Parse a comment. 42 | /// 43 | Parser AnyComment { get; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/IInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Hl7.FhirPath.Sprache 7 | { 8 | /// 9 | /// Represents an input for parsing. 10 | /// 11 | public interface IInput : IEquatable 12 | { 13 | /// 14 | /// Advances the input. 15 | /// 16 | /// A new that is advanced. 17 | /// The input is already at the end of the source. 18 | IInput Advance(); 19 | 20 | /// 21 | /// Gets the whole source. 22 | /// 23 | string Source { get; } 24 | 25 | /// 26 | /// Gets the current . 27 | /// 28 | char Current { get; } 29 | 30 | /// 31 | /// Gets a value indicating whether the end of the source is reached. 32 | /// 33 | bool AtEnd { get; } 34 | 35 | /// 36 | /// Gets the current positon. 37 | /// 38 | int Position { get; } 39 | 40 | /// 41 | /// Gets the current line number. 42 | /// 43 | int Line { get; } 44 | 45 | /// 46 | /// Gets the current column. 47 | /// 48 | int Column { get; } 49 | 50 | /// 51 | /// Memos used by this input 52 | /// 53 | IDictionary Memos { get; } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/IPositionAware.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Hl7.FhirPath.Sprache 3 | { 4 | /// 5 | /// An interface for objects that have a source . 6 | /// 7 | /// Type of the matched result. 8 | public interface IPositionAware 9 | { 10 | /// 11 | /// Set the start and the matched length. 12 | /// 13 | /// The start position 14 | /// The matched length. 15 | /// The matched result. 16 | T SetPos(Position startPos, int length); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/IResultOfT.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hl7.FhirPath.Sprache 4 | { 5 | /// 6 | /// Represents a parsing result. 7 | /// 8 | /// The result type. 9 | public interface IResult 10 | { 11 | /// 12 | /// Gets the resulting value. 13 | /// 14 | T Value { get; } 15 | 16 | /// 17 | /// Gets a value indicating whether wether parsing was successful. 18 | /// 19 | bool WasSuccessful { get; } 20 | 21 | /// 22 | /// Gets the error message. 23 | /// 24 | string Message { get; } 25 | 26 | /// 27 | /// Gets the parser expectations in case of error. 28 | /// 29 | IEnumerable Expectations { get; } 30 | 31 | /// 32 | /// Gets the remainder of the input. 33 | /// 34 | IInput Remainder { get; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/Parse.Optional.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hl7.FhirPath.Sprache 4 | { 5 | partial class Parse 6 | { 7 | /// 8 | /// Construct a parser that indicates the given parser 9 | /// is optional. The returned parser will succeed on 10 | /// any input no matter whether the given parser 11 | /// succeeds or not. 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static Parser> Optional(this Parser parser) 17 | { 18 | if (parser == null) throw new ArgumentNullException("parser"); 19 | 20 | return i => 21 | { 22 | var pr = parser(i); 23 | 24 | if (pr.WasSuccessful) 25 | return Result.Success(new Some(pr.Value), pr.Remainder); 26 | 27 | return Result.Success(new None(), i); 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/Parse.Positioned.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Hl7.FhirPath.Sprache 3 | { 4 | partial class Parse 5 | { 6 | /// 7 | /// Construct a parser that will set the position to the position-aware 8 | /// T on succsessful match. 9 | /// 10 | /// 11 | /// 12 | /// 13 | public static Parser Positioned(this Parser parser) where T : IPositionAware 14 | { 15 | return i => 16 | { 17 | var r = parser(i); 18 | 19 | if (r.WasSuccessful) 20 | { 21 | return Result.Success(r.Value.SetPos(Position.FromInput(i), r.Remainder.Position - i.Position), r.Remainder); 22 | } 23 | return r; 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/Parse.Primitives.cs: -------------------------------------------------------------------------------- 1 | namespace Hl7.FhirPath.Sprache 2 | { 3 | partial class Parse 4 | { 5 | /// 6 | /// \n or \r\n 7 | /// 8 | public static Parser LineEnd = 9 | (from r in Char('\r').Optional() 10 | from n in Char('\n') 11 | select r.IsDefined ? r.Get().ToString() + n : n.ToString()) 12 | .Named("LineEnd"); 13 | 14 | /// 15 | /// line ending or end of input 16 | /// 17 | public static Parser LineTerminator = 18 | Return("").End() 19 | .Or(LineEnd.End()) 20 | .Or(LineEnd) 21 | .Named("LineTerminator"); 22 | 23 | /// 24 | /// Parser for identifier starting with and continuing with 25 | /// 26 | public static Parser Identifier(Parser firstLetterParser, Parser tailLetterParser) 27 | { 28 | return 29 | from firstLetter in firstLetterParser 30 | from tail in tailLetterParser.Many().Text() 31 | select firstLetter + tail; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/ParseException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hl7.FhirPath.Sprache 4 | { 5 | /// 6 | /// Represents an error that occurs during parsing. 7 | /// 8 | public class ParseException : Exception 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | public ParseException() { } 14 | 15 | /// 16 | /// Initializes a new instance of the class with a specified error message. 17 | /// 18 | /// The message that describes the error. 19 | public ParseException(string message) : base(message) { } 20 | 21 | /// 22 | /// Initializes a new instance of the class with a specified error message 23 | /// and a reference to the inner exception that is the cause of this exception. 24 | /// 25 | /// The error message that explains the reason for the exception. 26 | /// The exception that is the cause of the current exception, 27 | /// or a null reference (Nothing in Visual Basic) if no inner exception is specified. 28 | public ParseException(string message, Exception innerException) : base(message, innerException) { } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/ResultHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hl7.FhirPath.Sprache 4 | { 5 | internal static class ResultHelper 6 | { 7 | public static IResult IfSuccess(this IResult result, Func, IResult> next) 8 | { 9 | if(result == null) throw new ArgumentNullException("result"); 10 | 11 | if (result.WasSuccessful) 12 | return next(result); 13 | 14 | return Result.Failure(result.Remainder, result.Message, result.Expectations); 15 | } 16 | 17 | public static IResult IfFailure(this IResult result, Func, IResult> next) 18 | { 19 | if (result == null) throw new ArgumentNullException("result"); 20 | 21 | return result.WasSuccessful 22 | ? result 23 | : next(result); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/Sprache.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.1.1-beta1 5 | netstandard1.0;net40;net45 6 | portable 7 | Sprache 8 | Sprache 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Hl7.FhirPath/Sprache/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hl7.FhirPath.Sprache 5 | { 6 | internal static class StringExtensions 7 | { 8 | // String does not implement IEnumerable in portable subset (WinRT specifically) 9 | public static IEnumerable ToEnumerable(this string @this) 10 | { 11 | if (@this == null) throw new ArgumentNullException("@this"); 12 | 13 | for (var i = 0; i < @this.Length; ++i) 14 | { 15 | yield return @this[i]; 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test.bat: -------------------------------------------------------------------------------- 1 | msbuild Hl7.Fhir.Common.sln /t:clean /v:minimal 2 | msbuild Hl7.Fhir.Common.sln /t:restore /v:minimal 3 | msbuild Hl7.Fhir.Common.sln /t:build /v:minimal 4 | msbuild Hl7.Fhir.Common.sln /t:vstest /v:minimal 5 | --------------------------------------------------------------------------------