diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cf67d47..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: @@ -21,11 +20,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 +29,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..6f23d0b 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,41 @@ 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; + } + } + 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 @@ -357,9 +394,7 @@ private void LoadPackagePages() } } - /// Loads ri contents. - /// The dir. - public void LoadRiContents(string dir) + private void loadContents(string dir, bool allowRootLoad = true) { if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) @@ -367,7 +402,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) @@ -391,7 +426,7 @@ public void LoadRiContents(string dir) Path.Combine(dir, tenantName), true); } - else + else if (allowRootLoad) { _storesByController[tenantName].LoadPackage( string.Empty, @@ -417,7 +452,7 @@ public void LoadRiContents(string dir) Path.Combine(dir, tenantName), true); } - else + else if (allowRootLoad) { _storesByController[tenantName].LoadPackage( string.Empty, @@ -443,7 +478,7 @@ public void LoadRiContents(string dir) Path.Combine(dir, tenantName), true); } - else + else if (allowRootLoad) { _storesByController[tenantName].LoadPackage( string.Empty, @@ -458,6 +493,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.