From b1869d809b9bfdda553d3c0d8840149189231598 Mon Sep 17 00:00:00 2001 From: Gino Canessa Date: Mon, 9 Sep 2024 16:02:45 -0500 Subject: [PATCH 1/3] Remove dotnet setup action from test action (included in default image) Fix: detection of user environment folder in parameters Fix: load directory was not interacting correctly without an RI specified. --- .github/workflows/build-and-test.yml | 8 ++--- README.md | 4 +-- src/fhir-candle/Program.cs | 15 ++++++++- .../Properties/launchSettings.json | 6 ++-- src/fhir-candle/Services/FhirStoreManager.cs | 32 ++++++++++++++++--- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cf67d47..6c043d6 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -21,11 +21,7 @@ jobs: os: [ubuntu-latest, windows-latest, macOS-latest] steps: - - uses: actions/checkout@v3 - - name: Setup .NET Core - uses: actions/setup-dotnet@v3 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} + - uses: actions/checkout@v4 - name: Install dependencies run: dotnet restore @@ -34,4 +30,4 @@ jobs: run: dotnet build --configuration Release --no-restore - name: Test - run: dotnet test --no-restore --verbosity normal + run: dotnet test --configuration Release --no-restore --verbosity normal diff --git a/README.md b/README.md index 80da910..eed6883 100644 --- a/README.md +++ b/README.md @@ -132,8 +132,8 @@ The server will load initial data specified by the `--fhir-source` argument. If is a relative path, the software will look for the directory starting at the current running path. If the system is loading multiple tenants, it will check the path for additional directories based -on the tenant names. For example, a path like `data` passed into the default server will look for -`data/r4`, `data/r4b`, and `data/r5`. If tenant directories are not found, all tenants will try to +on the tenant names. For example, a path like `fhirData` passed into the default server will look for +`fhirData/r4`, `fhirData/r4b`, and `fhirData/r5`. If tenant directories are not found, all tenants will try to load resources from the specified path. ### Subscriptions Reference Implementation diff --git a/src/fhir-candle/Program.cs b/src/fhir-candle/Program.cs index d2edd9f..d905b8b 100644 --- a/src/fhir-candle/Program.cs +++ b/src/fhir-candle/Program.cs @@ -655,7 +655,20 @@ public static string FindRelativeDir( string dirName, bool throwIfNotFound = true) { - string currentDir = string.IsNullOrEmpty(startDir) ? Path.GetDirectoryName(AppContext.BaseDirectory) ?? string.Empty : startDir; + if (dirName.Contains('~')) + { + // we have a relative path from the user directory + dirName = dirName.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); + } + + if (Directory.Exists(dirName)) + { + return Path.GetFullPath(dirName); + } + + string currentDir = string.IsNullOrEmpty(startDir) + ? Path.GetDirectoryName(AppContext.BaseDirectory) ?? string.Empty + : startDir; string testDir = Path.Combine(currentDir, dirName); while (!Directory.Exists(testDir)) diff --git a/src/fhir-candle/Properties/launchSettings.json b/src/fhir-candle/Properties/launchSettings.json index bd5f6c2..e0c7b24 100644 --- a/src/fhir-candle/Properties/launchSettings.json +++ b/src/fhir-candle/Properties/launchSettings.json @@ -8,13 +8,11 @@ "profiles": { "candle": { "commandName": "Project", - "commandLineArgs": "--r4 r4 --smart-optional r4", + "commandLineArgs": "--r4 r4 --smart-optional * --fhir-source ~/fhirData", "launchBrowser": true, "applicationUrl": "http://localhost:5826", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development", - "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4318", - "OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf" + "ASPNETCORE_ENVIRONMENT": "Development" } }, "candle-test-data": { diff --git a/src/fhir-candle/Services/FhirStoreManager.cs b/src/fhir-candle/Services/FhirStoreManager.cs index c6d3dad..dcc06ad 100644 --- a/src/fhir-candle/Services/FhirStoreManager.cs +++ b/src/fhir-candle/Services/FhirStoreManager.cs @@ -147,7 +147,7 @@ public void Init() _isInitialized = true; - // make sure the package service has been initalized + // make sure the package service has been initialized _packageService.Init(); _logger.LogInformation("FhirStoreManager <<< Creating FHIR tenants..."); @@ -196,6 +196,8 @@ public void Init() LoadRequestedPackages(supplemental, _serverConfig.LoadPackageExamples == true).Wait(); } + bool loadedContent = false; + // sort through RI info if (!string.IsNullOrEmpty(_serverConfig.ReferenceImplementation)) { @@ -205,6 +207,21 @@ public void Init() : Path.Combine(_serverConfig.SourceDirectory, _serverConfig.ReferenceImplementation); LoadRiContents(supplemental); + + loadedContent = true; + } + + if (!loadedContent && (!string.IsNullOrEmpty(_serverConfig.SourceDirectory))) + { + // look for a package supplemental directory + string supplementalRoot = Program.FindRelativeDir(string.Empty, _serverConfig.SourceDirectory, false); + + if ((!string.IsNullOrEmpty(supplementalRoot)) && + Directory.Exists(supplementalRoot)) + { + loadContents(supplementalRoot); + loadedContent = true; + } } // load packages @@ -357,9 +374,7 @@ private void LoadPackagePages() } } - /// Loads ri contents. - /// The dir. - public void LoadRiContents(string dir) + private void loadContents(string dir) { if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) @@ -367,7 +382,7 @@ public void LoadRiContents(string dir) return; } - _logger.LogInformation("FhirStoreManager <<< Loading RI contents..."); + _logger.LogInformation($"FhirStoreManager <<< Loading contents of {Path.GetFullPath(dir)}..."); // loop over controllers to see where we can add this foreach ((string tenantName, TenantConfiguration config) in _tenants) @@ -458,6 +473,13 @@ public void LoadRiContents(string dir) } } + /// Loads ri contents. + /// The dir. + public void LoadRiContents(string dir) + { + loadContents(dir); + } + /// Loads requested packages. /// Thrown when an exception error condition occurs. /// The supplemental root. From 168f1f48adc470dd26e0ea08f2a39e584af7a733 Mon Sep 17 00:00:00 2001 From: Gino Canessa Date: Mon, 9 Sep 2024 16:04:04 -0500 Subject: [PATCH 2/3] Fix: unit test action should only run on PRs --- .github/workflows/build-and-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 6c043d6..c860f3f 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,7 +1,6 @@ name: Tests # Basics from https://learn.microsoft.com/en-us/dotnet/devops/dotnet-test-github-action on: - push: pull_request: branches: [ main ] paths: From 77beafc36fbb1b5b80f76a27312032efe26aa729 Mon Sep 17 00:00:00 2001 From: Gino Canessa Date: Mon, 9 Sep 2024 16:08:20 -0500 Subject: [PATCH 3/3] Only allow root content load if there are no subdirectories in the content folder. --- src/fhir-candle/Services/FhirStoreManager.cs | 28 +++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/fhir-candle/Services/FhirStoreManager.cs b/src/fhir-candle/Services/FhirStoreManager.cs index dcc06ad..6f23d0b 100644 --- a/src/fhir-candle/Services/FhirStoreManager.cs +++ b/src/fhir-candle/Services/FhirStoreManager.cs @@ -223,6 +223,26 @@ public void Init() loadedContent = true; } } + else if (!loadedContent) + { + // look for a package supplemental directory + string supplementalRoot = Program.FindRelativeDir(string.Empty, "fhirData", false); + + if ((!string.IsNullOrEmpty(supplementalRoot)) && + Directory.Exists(supplementalRoot)) + { + // only allow the root load if the directory does NOT have any subfolders + if (Directory.GetDirectories(supplementalRoot).Length == 0) + { + loadContents(supplementalRoot, true); + } + else + { + loadContents(supplementalRoot, false); + } + loadedContent = true; + } + } // load packages LoadPackagePages(); @@ -374,7 +394,7 @@ private void LoadPackagePages() } } - private void loadContents(string dir) + private void loadContents(string dir, bool allowRootLoad = true) { if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) @@ -406,7 +426,7 @@ private void loadContents(string dir) Path.Combine(dir, tenantName), true); } - else + else if (allowRootLoad) { _storesByController[tenantName].LoadPackage( string.Empty, @@ -432,7 +452,7 @@ private void loadContents(string dir) Path.Combine(dir, tenantName), true); } - else + else if (allowRootLoad) { _storesByController[tenantName].LoadPackage( string.Empty, @@ -458,7 +478,7 @@ private void loadContents(string dir) Path.Combine(dir, tenantName), true); } - else + else if (allowRootLoad) { _storesByController[tenantName].LoadPackage( string.Empty,