Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport r4 changes to stu3 #583

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
259a047
build: Remove references to netcoreapp3.1
kennethmyhra Aug 27, 2023
34bac99
docs: Remove references to netcoreapp3.1
kennethmyhra Aug 27, 2023
5894bb5
Engine: Rename FhirModelExtensions to BundleExtensions
kennethmyhra Aug 27, 2023
ec5344b
Meta: Remove code style rule private_method_should_be_camelcase
kennethmyhra Sep 10, 2023
24a03f5
Engine: Return FHIR version from SparkSettings.FhirRelease
kennethmyhra Sep 10, 2023
f686f2c
Mongo: Add GuidGenerator a new unique identity generator
kennethmyhra Sep 9, 2023
991a2a0
Mongo: Wire up GuidGenerator the new unique Id generator
kennethmyhra Sep 9, 2023
90cb619
Documentation: Start documenting migration process from v1 to v2
kennethmyhra Sep 11, 2023
66b0aa9
Mongo: Add copyright header to IServiceCollectionExtensions.cs
kennethmyhra Sep 11, 2023
24f969f
Meta: Add dependabot configuration to update NuGet and GitHub actions
kennethmyhra Sep 11, 2023
8f7d067
build(deps): bump yuzutech/annotations-action from 0.1.0 to 0.4.0
dependabot[bot] Sep 11, 2023
c30ec5c
build(deps): bump actions/checkout from 3 to 4
dependabot[bot] Sep 11, 2023
100bb66
build(deps): bump jQuery from 3.6.1 to 3.7.1
dependabot[bot] Sep 11, 2023
9b1eed5
build(deps): bump actions/upload-artifact from 2 to 3
dependabot[bot] Sep 11, 2023
d21c027
build(deps): bump bootstrap from 5.2.2 to 5.3.1
dependabot[bot] Sep 11, 2023
48c40fe
build(deps): bump Autofac from 6.5.0 to 7.1.0
dependabot[bot] Sep 11, 2023
db90df9
build(deps): bump Fhir.Metrics from 1.2.1 to 1.2.2
dependabot[bot] Sep 11, 2023
75ebded
Engine: Better resolve handling for search parameters of type reference
kennethmyhra Aug 27, 2023
1008b9e
Engine: Wire up ResourceResolver to our IndexService
kennethmyhra Aug 27, 2023
0862d26
Documentation: Add note on rebuilding the index
kennethmyhra Sep 11, 2023
07608fa
Documentation: Reformat MigrateFromv1Tov2.md
kennethmyhra Sep 11, 2023
6e2df13
Meta: Add MigrateFromv1Tov2.md to the docs section in the solution file
kennethmyhra Sep 11, 2023
6f01de9
Engine: Null check arguments passed to IndexService's constructor
kennethmyhra Sep 11, 2023
3ec1f07
Meta: Update backup image of the spark example database
kennethmyhra Sep 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .docker/linux/stu3.archive.gz
Binary file not shown.
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.private_method_should_be_camelcase.severity = suggestion
dotnet_naming_rule.private_method_should_be_camelcase.symbols = private_method
dotnet_naming_rule.private_method_should_be_camelcase.style = camelcase

Expand Down Expand Up @@ -242,4 +241,4 @@ dotnet_naming_style._camelcase.capitalization = camel_case
dotnet_naming_style.allupper.required_prefix =
dotnet_naming_style.allupper.required_suffix =
dotnet_naming_style.allupper.word_separator =
dotnet_naming_style.allupper.capitalization = all_upper
dotnet_naming_style.allupper.capitalization = all_upper
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: nuget
directory: "/"
schedule:
interval: daily
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
4 changes: 2 additions & 2 deletions .github/workflows/docker_image_linux.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Release
name: Docker Release

on:
release:
Expand All @@ -8,7 +8,7 @@ jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Get the version
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integration Tests
name: Integration Tests

on:
workflow_dispatch:
Expand All @@ -13,7 +13,7 @@ jobs:
steps:
-
name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Build the latest Spark Docker image
run: docker build . --file .docker/linux/Spark.Dockerfile
Expand All @@ -37,35 +37,35 @@ jobs:
-
name: Attach test results
if: github.event_name != 'pull_request'
uses: yuzutech/annotations-action@v0.1.0
uses: yuzutech/annotations-action@v0.4.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
input: tests/integration-tests/annotations.json
-
name: Archive logs
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: logs-stu3-${{ github.sha }}
path: tests/integration-tests/logs/*.log*
-
name: Archive test reports
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: html_summaries-stu3-${{ github.sha }}
path: tests/integration-tests/html_summaries/**/*.html
-
name: Archive JSON results
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: json_results-stu3-${{ github.sha }}
path: tests/integration-tests/json_results/**/*.json
-
name: Archive annotations file
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: annotations-stu3-${{ github.sha }}
path: tests/integration-tests/annotations.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Tests

on:
push:
Expand All @@ -12,7 +12,7 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
Expand Down
1 change: 1 addition & 0 deletions Spark.sln
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{C6DB166C-A
docs\InstallingSpark.md = docs\InstallingSpark.md
docs\RunningSparkInDocker.md = docs\RunningSparkInDocker.md
docs\UsingSpark.md = docs\UsingSpark.md
docs\MigrateFromv1Tov2.md = docs\MigrateFromv1Tov2.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{977F2FE5-C232-4F93-AA0A-73DB85A20879}"
Expand Down
10 changes: 10 additions & 0 deletions docs/MigrateFromv1Tov2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Migrate from 1.0 to 2.0

### New IGenerator implementation
MongoIdGenerator is replaced by GuidGenerator and is the new default identity generator for resource's.
See issue https://github.com/FirelyTeam/spark/issues/572 for more information.

### Rebuild indexes
Better resolve handling for search parameters of type reference has been added, for this to take effect on existing
resources the index has to be rebuilt. This can be done by by using the Admin UI that comes with Spark.Web or wire up
IndexRebuildService in your implementation.
3 changes: 1 addition & 2 deletions docs/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ Sample code for this tutorial is located here: [spark-example](https://github.co
## Setting up the ASP.NET core application

First create an empty ASP.NET Core project:

```bash
dotnet new web --framework netcoreapp3.1
dotnet new web --name spark-example
```

Add the core package:
Expand Down
8 changes: 4 additions & 4 deletions src/Spark-Legacy/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net472" />
<package id="Autofac" version="6.5.0" targetFramework="net472" />
<package id="Autofac" version="7.1.0" targetFramework="net472" />
<package id="Autofac.Mvc5" version="6.1.0" targetFramework="net472" />
<package id="Autofac.SignalR2" version="6.0.0" targetFramework="net472" />
<package id="Autofac.WebApi2" version="6.1.1" targetFramework="net472" />
Expand All @@ -11,7 +11,7 @@
<package id="Microsoft.Extensions.Logging.Abstractions" version="6.0.3" targetFramework="net472" />
<package id="Snappier" version="1.0.0" targetFramework="net472" />
<package id="ZstdSharp.Port" version="0.6.5" targetFramework="net472" />
<package id="bootstrap" version="5.2.2" targetFramework="net472" />
<package id="bootstrap" version="5.3.1" targetFramework="net472" />
<package id="Crc32C.NET" version="1.0.5.0" targetFramework="net472" />
<package id="DnsClient" version="1.7.0" targetFramework="net472" />
<package id="EnterpriseLibrary.SemanticLogging" version="2.0.1406.1" targetFramework="net472" />
Expand All @@ -23,7 +23,7 @@
<package id="Hl7.Fhir.Support" version="4.3.0" targetFramework="net472" />
<package id="Hl7.Fhir.Support.Poco" version="4.3.0" targetFramework="net472" />
<package id="Hl7.FhirPath" version="4.3.0" targetFramework="net472" />
<package id="jQuery" version="3.6.1" targetFramework="net472" />
<package id="jQuery" version="3.7.1" targetFramework="net472" />
<package id="Microsoft.AspNet.Cors" version="5.2.9" targetFramework="net472" />
<package id="Microsoft.AspNet.Mvc" version="5.2.9" targetFramework="net472" />
<package id="Microsoft.AspNet.Razor" version="3.2.9" targetFramework="net472" />
Expand Down
6 changes: 4 additions & 2 deletions src/Spark.Engine.Test/Service/IndexServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ public void TestInitialize()
};
var searchParameters = new List<SearchParamDefinition> { spPatientName, spMiddleName };
var resources = new Dictionary<Type, string> { { typeof(Patient), "Patient" }, { typeof(HumanName), "HumanName" } };

var resourceResolver = new ResourceResolver();

// For this test setup we want a limited available types and search parameters.
IFhirModel limitedFhirModel = new FhirModel(resources, searchParameters);
ElementIndexer limitedElementIndexer = new ElementIndexer(limitedFhirModel);
_limitedIndexService = new IndexService(limitedFhirModel, indexStoreMock.Object, limitedElementIndexer);
_limitedIndexService = new IndexService(limitedFhirModel, indexStoreMock.Object, limitedElementIndexer, resourceResolver);

// For this test setup we want all available types and search parameters.
IFhirModel fullFhirModel = new FhirModel();
ElementIndexer fullElementIndexer = new ElementIndexer(fullFhirModel);
_fullIndexService = new IndexService(fullFhirModel, indexStoreMock.Object, fullElementIndexer);
_fullIndexService = new IndexService(fullFhirModel, indexStoreMock.Object, fullElementIndexer, resourceResolver);
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/Spark.Engine.Test/Spark.Engine.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down Expand Up @@ -53,4 +53,4 @@
</None>
</ItemGroup>

</Project>
</Project>
4 changes: 2 additions & 2 deletions src/Spark.Engine/Extensions/BundleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2014, Furore (info@furore.com) and contributors
* See the file CONTRIBUTORS for details.
*
Expand All @@ -12,7 +12,7 @@

namespace Spark.Engine.Extensions
{
public static class FhirModelExtensions
public static class BundleExtensions
{
public static void Append(this Bundle bundle, Resource resource)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, Incendi (info@incendi.no) and contributors
* Copyright (c) 2019-2023, Incendi (info@incendi.no) and contributors
* See the file CONTRIBUTORS for details.
*
* This file is licensed under the BSD 3-Clause license
Expand Down Expand Up @@ -141,6 +141,8 @@ public static IMvcCoreBuilder AddFhir(this IServiceCollection services, SparkSet

services.TryAddTransient<IReferenceNormalizationService, ReferenceNormalizationService>();

services.TryAddSingleton<ResourceResolver>();

services.TryAddTransient<IIndexService, IndexService>();
services.TryAddTransient<ILocalhost>((provider) => new Localhost(settings.Endpoint));
services.TryAddTransient<IFhirModel>((provider) => new FhirModel(ModelInfo.SearchParameters));
Expand Down
61 changes: 61 additions & 0 deletions src/Spark.Engine/Search/ResourceResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023, Incendi (info@incendi.no) and contributors
* See the file CONTRIBUTORS for details.
*
* This file is licensed under the BSD 3-Clause license
* available at https://raw.githubusercontent.com/FirelyTeam/spark/stu3/master/LICENSE
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace Spark.Engine.Search
{
public class ResourceResolver
{
private const string RESOURCE_TYPE_CAPTURE = "resourceType";
private const string RESOURCE_ID_CAPTURE = "resourceId";

private readonly Regex _referenceRegex;
private readonly IStructureDefinitionSummaryProvider _structureDefinitionSummaryProvider;

public ResourceResolver()
{
var resourceTypesPattern = string.Join("|", ModelInfo.SupportedResources);
var referenceCaptureRegexPattern = $@"(?<{RESOURCE_TYPE_CAPTURE}>{resourceTypesPattern})\/(?<{RESOURCE_ID_CAPTURE}>[A-Za-z0-9\-\.]{{1,64}})(\/_history\/[A-Za-z0-9\-\.]{{1,64}})?";
_referenceRegex = new Regex(referenceCaptureRegexPattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.ExplicitCapture);

_structureDefinitionSummaryProvider = new PocoStructureDefinitionSummaryProvider();
}

public ITypedElement Resolve(string reference)
{
if (string.IsNullOrWhiteSpace(reference))
{
return null;
}

var match = _referenceRegex.Match(reference);
if (!match.Success)
{
return null;
}

string resourceTypeInString = match.Groups[RESOURCE_TYPE_CAPTURE].Value;
string resourceId = match.Groups[RESOURCE_ID_CAPTURE].Value;
ISourceNode node = FhirJsonNode.Create(
JObject.FromObject(
new
{
resourceType = resourceTypeInString,
id = resourceId,
}));

return node.ToTypedElement(_structureDefinitionSummaryProvider);
}
}
}
41 changes: 32 additions & 9 deletions src/Spark.Engine/Service/FhirServiceExtensions/IndexService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
* Copyright (c) 2021, Incendi (info@incendi.no) and contributors
/*
* Copyright (c) 2021-2023, Incendi (info@incendi.no) and contributors
* See the file CONTRIBUTORS for details.
*
*
* This file is licensed under the BSD 3-Clause license
* available at https://raw.githubusercontent.com/FirelyTeam/spark/stu3/master/LICENSE
*/

using Hl7.Fhir.ElementModel;
using Hl7.Fhir.FhirPath;
using Hl7.Fhir.Model;
using Hl7.FhirPath;
using Spark.Engine.Core;
using Spark.Engine.Extensions;
using Spark.Engine.Model;
Expand All @@ -28,12 +30,14 @@ public class IndexService : IIndexService
private readonly IFhirModel _fhirModel;
private readonly IIndexStore _indexStore;
private readonly ElementIndexer _elementIndexer;
private readonly ResourceResolver _elementResolver;

public IndexService(IFhirModel fhirModel, IIndexStore indexStore, ElementIndexer elementIndexer)
public IndexService(IFhirModel fhirModel, IIndexStore indexStore, ElementIndexer elementIndexer, ResourceResolver elementResolver)
{
_fhirModel = fhirModel;
_indexStore = indexStore;
_elementIndexer = elementIndexer;
_fhirModel = fhirModel ?? throw new ArgumentNullException(nameof(fhirModel));
_indexStore = indexStore ?? throw new ArgumentNullException(nameof(indexStore));
_elementIndexer = elementIndexer ?? throw new ArgumentNullException(nameof(elementIndexer));
_elementResolver = elementResolver ?? throw new ArgumentNullException(nameof(elementResolver));
}

public void Process(Entry entry)
Expand Down Expand Up @@ -84,6 +88,14 @@ public async Task<IndexValue> IndexResourceAsync(Resource resource, IKey key)
return indexValue;
}

private EvaluationContext GetEvaluationContext(Func<string, ITypedElement> elementResolver = null)
{
return new FhirEvaluationContext
{
ElementResolver = elementResolver,
};
}

private IndexValue IndexResourceRecursively(Resource resource, IKey key, string rootPartName = "root")
{
IEnumerable<SearchParameter> searchParameters = _fhirModel.FindSearchParameters(resource.GetType());
Expand All @@ -104,8 +116,19 @@ private IndexValue IndexResourceRecursively(Resource resource, IKey key, string
if (searchParameter.Type == Hl7.Fhir.Model.SearchParamType.Composite) continue;

var indexValue = new IndexValue(searchParameter.Code);
var resolvedValues = resource.SelectNew(searchParameter.Expression);
foreach(var value in resolvedValues)
IEnumerable<Base> resolvedValues;
// HACK: Ignoring search parameter expressions which the FhirPath engine does not yet have support for

try
{
resolvedValues = resource.SelectNew(searchParameter.Expression, new FhirEvaluationContext { ElementResolver = _elementResolver.Resolve });
}
catch (Exception)
{
// TODO: log error!
resolvedValues = new List<Base>();
}
foreach (var value in resolvedValues)
{
if (!(value is Element element)) continue;

Expand Down
4 changes: 2 additions & 2 deletions src/Spark.Engine/Spark.Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net462</TargetFrameworks>
Expand All @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fhir.Metrics" Version="1.2.1" />
<PackageReference Include="Fhir.Metrics" Version="1.2.2" />
<PackageReference Include="Hl7.Fhir.STU3" Version="4.3.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
Loading
Loading