diff --git a/.gitignore b/.gitignore index 9491a2fd..88bfb4ba 100644 --- a/.gitignore +++ b/.gitignore @@ -193,7 +193,7 @@ publish/ PublishScripts/ # NuGet Packages -*.nupkg +# *.nupkg # NuGet Symbol Packages *.snupkg # The packages folder can be ignored because of Package Restore diff --git a/BMA.EHR.API.Command/BMA.EHR.API.Command.csproj b/BMA.EHR.API.Command/BMA.EHR.API.Command.csproj index 4510e069..62424ae0 100644 --- a/BMA.EHR.API.Command/BMA.EHR.API.Command.csproj +++ b/BMA.EHR.API.Command/BMA.EHR.API.Command.csproj @@ -7,7 +7,7 @@ - + diff --git a/BMA.EHR.Application/BMA.EHR.Application.csproj b/BMA.EHR.Application/BMA.EHR.Application.csproj index 5bf43f93..4748024b 100644 --- a/BMA.EHR.Application/BMA.EHR.Application.csproj +++ b/BMA.EHR.Application/BMA.EHR.Application.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/BMA.EHR.Domain/BMA.EHR.Domain.csproj b/BMA.EHR.Domain/BMA.EHR.Domain.csproj index 8fee8fa7..8332171c 100644 --- a/BMA.EHR.Domain/BMA.EHR.Domain.csproj +++ b/BMA.EHR.Domain/BMA.EHR.Domain.csproj @@ -7,8 +7,9 @@ + - + diff --git a/BMA.EHR.MetaData.Service/ErrorHandlerMiddleware.cs b/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs similarity index 97% rename from BMA.EHR.MetaData.Service/ErrorHandlerMiddleware.cs rename to BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs index b540d516..74b0d660 100644 --- a/BMA.EHR.MetaData.Service/ErrorHandlerMiddleware.cs +++ b/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs @@ -1,8 +1,9 @@ using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Shared; +using Microsoft.AspNetCore.Http; using System.Net; -namespace BMA.EHR.MetaData.Service +namespace BMA.EHR.Domain.Middlewares { public class ErrorHandlerMiddleware { diff --git a/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj b/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj index 0f8a6718..ac8c4cfe 100644 --- a/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj +++ b/BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj @@ -8,11 +8,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj b/BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj index d6b70739..445bcc43 100644 --- a/BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj +++ b/BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj @@ -13,12 +13,12 @@ - - + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BMA.EHR.MetaData.Service/Program.cs b/BMA.EHR.MetaData.Service/Program.cs index b090a581..d074187f 100644 --- a/BMA.EHR.MetaData.Service/Program.cs +++ b/BMA.EHR.MetaData.Service/Program.cs @@ -1,5 +1,6 @@ using BMA.EHR.API.Command; using BMA.EHR.Application; +using BMA.EHR.Domain.Middlewares; using BMA.EHR.Infrastructure; using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.MetaData.Service; @@ -111,7 +112,7 @@ var app = builder.Build(); app.MapHealthChecks("/health"); - //app.UseMiddleware(); + app.UseMiddleware(); app.UseHttpsRedirection(); app.UseCors(); app.UseAuthentication(); diff --git a/BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj b/BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj index 28056f7e..8cb1cb48 100644 --- a/BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj +++ b/BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj @@ -12,12 +12,12 @@ - - + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/BMA.EHR.Placement.Service/ErrorHandlerMiddleware.cs b/BMA.EHR.Placement.Service/ErrorHandlerMiddleware.cs deleted file mode 100644 index b540d516..00000000 --- a/BMA.EHR.Placement.Service/ErrorHandlerMiddleware.cs +++ /dev/null @@ -1,84 +0,0 @@ -using BMA.EHR.Domain.Common; -using BMA.EHR.Domain.Shared; -using System.Net; - -namespace BMA.EHR.MetaData.Service -{ - public class ErrorHandlerMiddleware - { - #region " Fields " - - private readonly RequestDelegate _next; - - #endregion - - #region " Constructor and Destructor " - - public ErrorHandlerMiddleware(RequestDelegate next) - { - _next = next; - } - - #endregion - - #region " Methods " - - public async Task Invoke(HttpContext context) - { - try - { - await _next(context); - - var response = context.Response; - response.ContentType = "application/json"; - - var responseModel = new ResponseObject(); - responseModel.Status = response.StatusCode; - - if (responseModel.Status == (int)HttpStatusCode.Unauthorized) - { - responseModel.Message = GlobalMessages.NotAuthorized; - await response.WriteAsJsonAsync(responseModel); - } - if (responseModel.Status == (int)HttpStatusCode.Forbidden) - { - responseModel.Message = GlobalMessages.ForbiddenAccess; - await response.WriteAsJsonAsync(responseModel); - } - } - catch (Exception error) - { - var response = context.Response; - response.ContentType = "application/json"; - - var responseModel = new ResponseObject(); - responseModel.Status = response.StatusCode; - var msg = error.Message; - var inner = error.InnerException; - while (inner != null) - { - msg += $" {inner.Message}\r\n"; - inner = inner.InnerException; - } - responseModel.Result = msg; - - switch (response.StatusCode) - { - case (int)HttpStatusCode.Unauthorized: - responseModel.Message = GlobalMessages.NotAuthorized; - break; - case (int)HttpStatusCode.Forbidden: - responseModel.Message = GlobalMessages.ForbiddenAccess; - break; - default: - responseModel.Status = (int)HttpStatusCode.InternalServerError; - responseModel.Message = GlobalMessages.ExceptionOccured; - break; - } - await response.WriteAsJsonAsync(responseModel); - } - } - - #endregion - } -} diff --git a/BMA.EHR.Placement.Service/Program.cs b/BMA.EHR.Placement.Service/Program.cs index 42f2b154..51d19f67 100644 --- a/BMA.EHR.Placement.Service/Program.cs +++ b/BMA.EHR.Placement.Service/Program.cs @@ -1,4 +1,5 @@ using BMA.EHR.Application; +using BMA.EHR.Domain.Middlewares; using BMA.EHR.Infrastructure; using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Placement.Service; @@ -110,7 +111,7 @@ var app = builder.Build(); app.MapHealthChecks("/health"); - //app.UseMiddleware(); + app.UseMiddleware(); app.UseHttpsRedirection(); app.UseCors(); app.UseAuthentication(); diff --git a/BMA.EHR.Report.Service/.github/workflows/build-local.yaml b/BMA.EHR.Report.Service/.github/workflows/build-local.yaml new file mode 100644 index 00000000..3a06de72 --- /dev/null +++ b/BMA.EHR.Report.Service/.github/workflows/build-local.yaml @@ -0,0 +1,46 @@ +# use for local build with act +name: build-local +run-name: build-local ${{ github.actor }} +on: + workflow_dispatch: +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: demo/bma-ehr-metadata-service +jobs: + # act workflow_dispatch -W .github/workflows/build-local.yaml --input IMAGE_VER=test-v6.1 + build-local: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + - name: Gen Version + id: gen_ver + run: | + if [[ $GITHUB_REF == 'refs/tags/'* ]]; then + IMAGE_VER='${GITHUB_REF/refs\/tags\//}' + else + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + fi + if [[ $IMAGE_VER == '' ]]; then + IMAGE_VER='test-vBeta' + fi + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Test Version + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + # - name: Login in to registry + # uses: docker/login-action@v2 + # with: + # registry: ${{env.REGISTRY}} + # username: ${{secrets.DOCKER_USER}} + # password: ${{secrets.DOCKER_PASS}} + - name: Build and load local docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + load: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest diff --git a/BMA.EHR.Report.Service/.github/workflows/release.yaml b/BMA.EHR.Report.Service/.github/workflows/release.yaml new file mode 100644 index 00000000..e261ffa6 --- /dev/null +++ b/BMA.EHR.Report.Service/.github/workflows/release.yaml @@ -0,0 +1,86 @@ +name: release-dev +run-name: release-dev ${{ github.actor }} +on: + # push: + # tags: + # - 'v[0-9]+.[0-9]+.[0-9]+' + # tags-ignore: + # - '2.*' + # Allow run workflow manually from Action tab + workflow_dispatch: +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: ehr/bma-ehr-report-service + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma-ehr-report + TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0 + +jobs: + # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd + release-dev: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + - name: Gen Version + id: gen_ver + run: | + if [[ $GITHUB_REF == 'refs/tags/'* ]]; then + IMAGE_VER='${GITHUB_REF/refs\/tags\//}' + else + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + fi + if [[ $IMAGE_VER == '' ]]; then + IMAGE_VER='test-vBeta' + fi + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Test Version + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login in to registry + uses: docker/login-action@v2 + with: + registry: ${{env.REGISTRY}} + username: ${{secrets.DOCKER_USER}} + password: ${{secrets.DOCKER_PASS}} + - name: Build and load local docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest + + - name: Reload docker compose + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{env.DEPLOY_HOST}} + username: frappet + password: ${{ secrets.SSH_PASSWORD }} + port: 22 + script: | + cd "${{env.COMPOSE_PATH}}" + docker-compose pull + docker-compose up -d + echo "${{ steps.gen_ver.outputs.image_ver }}"> success + - uses: snow-actions/line-notify@v1.1.0 + if: success() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Success✅✅✅ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: failure() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Failure❌❌❌ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} diff --git a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj new file mode 100644 index 00000000..be6d86cd --- /dev/null +++ b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj @@ -0,0 +1,53 @@ + + + + net7.0 + enable + enable + 1fb39f37-45f3-4d47-9c86-c0458563770e + Linux + True + . + BMA.EHR.Report.Service + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Blazor.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Blazor.17.0.23.315.nupkg new file mode 100644 index 00000000..06af74a5 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Blazor.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.BlazorNative.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.BlazorNative.17.0.23.315.nupkg new file mode 100644 index 00000000..b1e81f4f Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.BlazorNative.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Html5.WebForms.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Html5.WebForms.17.0.23.315.nupkg new file mode 100644 index 00000000..8fee2691 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Html5.WebForms.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Mvc.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Mvc.17.0.23.315.nupkg new file mode 100644 index 00000000..e247f007 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Mvc.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.WinForms.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.WinForms.17.0.23.315.nupkg new file mode 100644 index 00000000..2d6ff585 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.WinForms.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.WinUI.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.WinUI.17.0.23.315.nupkg new file mode 100644 index 00000000..07bf588b Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.WinUI.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Wpf.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Wpf.17.0.23.315.nupkg new file mode 100644 index 00000000..3c2c2494 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Wpf.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Wpf.Themes.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Wpf.Themes.17.0.23.315.nupkg new file mode 100644 index 00000000..3aa503ee Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.ReportViewer.Wpf.Themes.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.17.0.23.315.nupkg new file mode 100644 index 00000000..1eb635fb Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Adomd.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Adomd.17.0.23.315.nupkg new file mode 100644 index 00000000..c7cb14f7 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Adomd.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.Database.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.Database.17.0.23.315.nupkg new file mode 100644 index 00000000..8954912c Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.Database.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.StackExchangeRedis.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.StackExchangeRedis.17.0.23.315.nupkg new file mode 100644 index 00000000..0950b16c Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.StackExchangeRedis.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.StackExchangeRedis.2.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.StackExchangeRedis.2.17.0.23.315.nupkg new file mode 100644 index 00000000..2e8f359a Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Cache.StackExchangeRedis.2.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.JsonSerialization.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.JsonSerialization.17.0.23.315.nupkg new file mode 100644 index 00000000..4d89f01f Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.JsonSerialization.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.OpenXmlRendering.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.OpenXmlRendering.17.0.23.315.nupkg new file mode 100644 index 00000000..d182f08a Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.OpenXmlRendering.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.AspNetCore.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.AspNetCore.17.0.23.315.nupkg new file mode 100644 index 00000000..7cd9b22a Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.AspNetCore.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.HttpClient.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.HttpClient.17.0.23.315.nupkg new file mode 100644 index 00000000..c019ae02 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.HttpClient.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.ServiceStack.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.ServiceStack.17.0.23.315.nupkg new file mode 100644 index 00000000..499576eb Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.ServiceStack.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.WebApi.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.WebApi.17.0.23.315.nupkg new file mode 100644 index 00000000..72e4e344 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.Services.WebApi.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.Reporting.WebServiceDataSource.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.Reporting.WebServiceDataSource.17.0.23.315.nupkg new file mode 100644 index 00000000..34abde7c Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.Reporting.WebServiceDataSource.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.WebReportDesigner.Blazor.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.WebReportDesigner.Blazor.17.0.23.315.nupkg new file mode 100644 index 00000000..fb8e96c1 Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.WebReportDesigner.Blazor.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/Components/Telerik.WebReportDesigner.Services.17.0.23.315.nupkg b/BMA.EHR.Report.Service/Components/Telerik.WebReportDesigner.Services.17.0.23.315.nupkg new file mode 100644 index 00000000..349e332d Binary files /dev/null and b/BMA.EHR.Report.Service/Components/Telerik.WebReportDesigner.Services.17.0.23.315.nupkg differ diff --git a/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs b/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs new file mode 100644 index 00000000..b6339ba3 --- /dev/null +++ b/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; +using System.Reflection; + +namespace BMA.EHR.Report.Service +{ + public class ConfigureSwaggerOptions : IConfigureNamedOptions + { + private readonly IApiVersionDescriptionProvider _provider; + + public ConfigureSwaggerOptions( + IApiVersionDescriptionProvider provider) + { + _provider = provider; + } + + public void Configure(SwaggerGenOptions options) + { + // add swagger document for every API version discovered + foreach (var description in _provider.ApiVersionDescriptions) + { + options.EnableAnnotations(); + + options.SwaggerDoc( + description.GroupName, + CreateVersionInfo(description)); + } + + options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + Description = "Please enter a valid token", + Name = "Authorization", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT", + Scheme = "Bearer" + }); + + options.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new string[]{} + } + }); + + // generate the XML docs that'll drive the swagger docs + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + options.IncludeXmlComments(xmlPath); + } + + public void Configure(string name, SwaggerGenOptions options) + { + Configure(options); + } + + private OpenApiInfo CreateVersionInfo( + ApiVersionDescription desc) + { + var info = new OpenApiInfo() + { + Title = "BMA EHR Placement Service Document", + Version = desc.ApiVersion.ToString() + }; + + if (desc.IsDeprecated) + { + info.Description += " This API version has been deprecated. Please use one of the new APIs available from the explorer."; + } + + return info; + } + } +} diff --git a/BMA.EHR.Report.Service/Dockerfile b/BMA.EHR.Report.Service/Dockerfile new file mode 100644 index 00000000..549e7c74 --- /dev/null +++ b/BMA.EHR.Report.Service/Dockerfile @@ -0,0 +1,34 @@ +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY Components ./Components +COPY nuget.config . +COPY ["BMA.EHR.Report.Service.csproj", "."] +RUN dotnet restore "./BMA.EHR.Report.Service.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "BMA.EHR.Report.Service.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "BMA.EHR.Report.Service.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final + +RUN apt-get update && apt-get -y install fontconfig && apt-get install -y --allow-unauthenticated libgdiplus libc6-dev +COPY ./Fonts/THSarabunIT.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunITBold.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunITItalic.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunITBoldItalic.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunNew.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunNewBold.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunNewItalic.ttf /usr/share/fonts/truetype/ +COPY ./Fonts/THSarabunNewBoldItalic.ttf /usr/share/fonts/truetype/ +RUN fc-cache -f -v + +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "BMA.EHR.Report.Service.dll"] \ No newline at end of file diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunIT.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunIT.ttf new file mode 100644 index 00000000..d5d56bfd Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunIT.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunITBold.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunITBold.ttf new file mode 100644 index 00000000..e8651045 Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunITBold.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunITBoldItalic.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunITBoldItalic.ttf new file mode 100644 index 00000000..b105a1b5 Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunITBoldItalic.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunITItalic.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunITItalic.ttf new file mode 100644 index 00000000..cb58ca2a Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunITItalic.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunNew.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunNew.ttf new file mode 100644 index 00000000..13c55aee Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunNew.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunNewBold.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunNewBold.ttf new file mode 100644 index 00000000..a059996b Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunNewBold.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunNewBoldItalic.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunNewBoldItalic.ttf new file mode 100644 index 00000000..e38f6d2f Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunNewBoldItalic.ttf differ diff --git a/BMA.EHR.Report.Service/Fonts/THSarabunNewItalic.ttf b/BMA.EHR.Report.Service/Fonts/THSarabunNewItalic.ttf new file mode 100644 index 00000000..15312bc0 Binary files /dev/null and b/BMA.EHR.Report.Service/Fonts/THSarabunNewItalic.ttf differ diff --git a/BMA.EHR.Report.Service/Program.cs b/BMA.EHR.Report.Service/Program.cs new file mode 100644 index 00000000..a1160218 --- /dev/null +++ b/BMA.EHR.Report.Service/Program.cs @@ -0,0 +1,159 @@ +using BMA.EHR.Application; +using BMA.EHR.Domain.Middlewares; +using BMA.EHR.Infrastructure; +using BMA.EHR.Infrastructure.Persistence; +using BMA.EHR.Report.Service; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc.Versioning; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Logging; +using Microsoft.IdentityModel.Tokens; +using Serilog; +using Serilog.Exceptions; +using Serilog.Sinks.Elasticsearch; +using System.Reflection; +using System.Text; + +var builder = WebApplication.CreateBuilder(args); +{ + var issuer = builder.Configuration["Jwt:Issuer"]; + var key = builder.Configuration["Jwt:Key"]; + + + IdentityModelEventSource.ShowPII = true; + + builder.Services.AddHttpContextAccessor(); + + builder.Services.AddApiVersioning(opt => + { + opt.DefaultApiVersion = new ApiVersion(1, 0); + opt.AssumeDefaultVersionWhenUnspecified = true; + opt.ReportApiVersions = true; + opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(), + new HeaderApiVersionReader("x-api-version"), + new MediaTypeApiVersionReader("x-api-version")); + }); + + builder.Services.AddVersionedApiExplorer(setup => + { + setup.GroupNameFormat = "'v'VVV"; + setup.SubstituteApiVersionInUrl = true; + }); + + builder.Services.AddEndpointsApiExplorer(); + + // Authorization + builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt => + { + opt.RequireHttpsMetadata = false; //false for dev + opt.Authority = issuer; + opt.TokenValidationParameters = new() + { + ValidateIssuer = true, + ValidateAudience = false, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = issuer, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)) + }; + }); + builder.Services.AddAuthorization(); + + // use serilog + ConfigureLogs(); + builder.Host.UseSerilog(); + + // Add config CORS + builder.Services.AddCors(options => options.AddDefaultPolicy(builder => + { + builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader() + .SetIsOriginAllowedToAllowWildcardSubdomains(); + })); + + + // Add services to the container. + builder.Services.AddApplication(); + builder.Services.AddPersistence(builder.Configuration); + + builder.Services.AddControllers(options => + { + options.SuppressAsyncSuffixInActionNames = false; + }) + .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); + + builder.Services.AddSwaggerGen(); + builder.Services.ConfigureOptions(); + + builder.Services.AddHealthChecks(); +} + +var app = builder.Build(); +{ + var apiVersionDescriptionProvider = app.Services.GetRequiredService(); + + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(options => + { + foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions) + { + options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", + description.GroupName.ToUpperInvariant()); + } + }); + } + + app.MapHealthChecks("/health"); + + app.UseMiddleware(); + app.UseHttpsRedirection(); + app.UseCors(); + app.UseAuthentication(); + app.UseAuthorization(); + app.UseDefaultFiles(); + app.UseStaticFiles(); + app.MapControllers(); + + // apply migrations + await using var scope = app.Services.CreateAsyncScope(); + await using var db = scope.ServiceProvider.GetRequiredService(); + await db.Database.MigrateAsync(); + + app.Run(); +} + +void ConfigureLogs() +{ + var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + var configuration = new ConfigurationBuilder() + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile( + $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", + optional: true) + .Build(); + + Log.Logger = new LoggerConfiguration() + .Enrich.FromLogContext() + .MinimumLevel.Error() + .WriteTo.Console() + .Enrich.WithExceptionDetails() + .WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment ?? "")) + .Enrich.WithProperty("Environment", environment) + .ReadFrom.Configuration(configuration) + .CreateLogger(); +} + +ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment) +{ + return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"] ?? "")) + { + AutoRegisterTemplate = true, + IndexFormat = $"{Assembly.GetExecutingAssembly()?.GetName()?.Name?.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}" + }; +} diff --git a/BMA.EHR.Report.Service/Properties/launchSettings.json b/BMA.EHR.Report.Service/Properties/launchSettings.json new file mode 100644 index 00000000..985a5c8f --- /dev/null +++ b/BMA.EHR.Report.Service/Properties/launchSettings.json @@ -0,0 +1,48 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5156" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7164;http://localhost:5156" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:23132", + "sslPort": 44337 + } + } +} \ No newline at end of file diff --git a/BMA.EHR.Report.Service/appsettings.Development.json b/BMA.EHR.Report.Service/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/BMA.EHR.Report.Service/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/BMA.EHR.Report.Service/appsettings.json b/BMA.EHR.Report.Service/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/BMA.EHR.Report.Service/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/BMA.EHR.Report.Service/nuget.config b/BMA.EHR.Report.Service/nuget.config new file mode 100644 index 00000000..7d34cfc1 --- /dev/null +++ b/BMA.EHR.Report.Service/nuget.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/BMA.EHR.Solution.sln b/BMA.EHR.Solution.sln index 76b49b91..64043383 100644 --- a/BMA.EHR.Solution.sln +++ b/BMA.EHR.Solution.sln @@ -17,7 +17,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Service", "Service", "{FA61 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.API.Command", "BMA.EHR.API.Command\BMA.EHR.API.Command.csproj", "{FC7215BD-5651-4226-9210-8894E8FA8767}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BMA.EHR.Placement.Service", "BMA.EHR.Placement.Service\BMA.EHR.Placement.Service.csproj", "{81610EF7-AF80-44D8-9263-925C821CF45F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BMA.EHR.Placement.Service", "BMA.EHR.Placement.Service\BMA.EHR.Placement.Service.csproj", "{81610EF7-AF80-44D8-9263-925C821CF45F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BMA.EHR.Report.Service", "BMA.EHR.Report.Service\BMA.EHR.Report.Service.csproj", "{AC4B2602-C543-4165-85D7-F6F92F553D80}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -49,6 +51,10 @@ Global {81610EF7-AF80-44D8-9263-925C821CF45F}.Debug|Any CPU.Build.0 = Debug|Any CPU {81610EF7-AF80-44D8-9263-925C821CF45F}.Release|Any CPU.ActiveCfg = Release|Any CPU {81610EF7-AF80-44D8-9263-925C821CF45F}.Release|Any CPU.Build.0 = Release|Any CPU + {AC4B2602-C543-4165-85D7-F6F92F553D80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC4B2602-C543-4165-85D7-F6F92F553D80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC4B2602-C543-4165-85D7-F6F92F553D80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC4B2602-C543-4165-85D7-F6F92F553D80}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -61,6 +67,7 @@ Global {FA618F0C-1AF5-49AB-AE13-C020B403B64F} = {F3C2F68F-8DC8-45A3-825B-24F17867D380} {FC7215BD-5651-4226-9210-8894E8FA8767} = {F3C2F68F-8DC8-45A3-825B-24F17867D380} {81610EF7-AF80-44D8-9263-925C821CF45F} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} + {AC4B2602-C543-4165-85D7-F6F92F553D80} = {FA618F0C-1AF5-49AB-AE13-C020B403B64F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3111A492-1818-4438-B718-75199D8E779A}