Merge branch 'develop' into adiDev
Some checks failed
release-dev / release-dev (push) Failing after 10s

This commit is contained in:
AdisakKanthawilang 2025-06-24 12:09:17 +07:00
commit 419866bb70
22 changed files with 766 additions and 819 deletions

12
.gitignore vendored
View file

@ -16,8 +16,18 @@
# Mono auto generated files
mono_crash.*
# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
.idea/
.vs/
*.iml
*.ipr
*.iws
out/
.idea_modules/
atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Build results
[Dd]ebug/

View file

@ -1 +0,0 @@
BMA.EHR.Solution

Before

Width:  |  Height:  |  Size: 16 B

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="RiderAndroidProjectSystem" />
</component>
</project>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeRegion" value="us-east-1" />
<option name="recentlyUsedRegions">
<list>
<option value="us-east-1" />
</list>
</option>
</component>
</project>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="singleClickDiffPreview" value="1" />
<option name="unhandledExceptionsIgnoreList" value="1" />
<option name="vcsConfiguration" value="3" />
</component>
</project>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View file

@ -1,598 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoGeneratedRunConfigurationManager">
<projectFile kind="Docker">BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj</projectFile>
<projectFile profileName="BMA.EHR.CheckInConsumer">BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Insignia/BMA.EHR.Insignia.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Insignia/BMA.EHR.Insignia.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Insignia/BMA.EHR.Insignia.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Leave/BMA.EHR.Leave.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Leave/BMA.EHR.Leave.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Leave/BMA.EHR.Leave.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj</projectFile>
<projectFile profileName="dotnet">BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj</projectFile>
<projectFile profileName="report-designer">BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj</projectFile>
<projectFile kind="Docker">BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj</projectFile>
<projectFile profileName="http">BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj</projectFile>
<projectFile profileName="https">BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj</projectFile>
<projectFile kind="Docker">LinkageResponseTest/LinkageResponseTest.csproj</projectFile>
<projectFile profileName="LinkageResponseTest">LinkageResponseTest/LinkageResponseTest.csproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="85fddeb6-44fd-40a4-864f-89daec07db75" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/BMA.EHR.Application/Repositories/PermissionRepository.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BMA.EHR.Application/Repositories/PermissionRepository.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs" beforeDir="false" afterPath="$PROJECT_DIR$/BMA.EHR.Domain/Middlewares/ErrorHandlerMiddleware.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="DpaMonitoringSettings">
<option name="firstShow" value="false" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/784cd69e10484e988569506bb4e7688b1c2588/44/2a408f3d/SingleQueryingEnumerable`1.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/79e4164404d2be7b9d0cd51036b545bd14f5807c558d20f7cd375d4fd8ff23/ConnectionFactory.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/bf9021a960b74107a7e141aa06bc9d8a0a53c929178c2fb95b1597be8af8dc/ExceptionDispatchInfo.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs" root0="SKIP_HIGHLIGHTING" />
</component>
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
<component name="ProjectColorInfo">{
&quot;customColor&quot;: &quot;&quot;,
&quot;associatedIndex&quot;: 2
}</component>
<component name="ProjectId" id="2lB1pnEIkATarPnZkJ5vo5hUlwn" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
".NET Launch Settings Profile.BMA.EHR.Leave: https.executor": "Debug",
".NET Launch Settings Profile.BMA.EHR.Placement.Service: http.executor": "Debug",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "working",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.lookFeel",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager" selected=".NET Launch Settings Profile.BMA.EHR.Leave: https">
<configuration name="BMA.EHR.CheckInConsumer" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
<option name="LAUNCH_PROFILE_NAME" value="BMA.EHR.CheckInConsumer" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Command.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Command.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Discipline.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Discipline.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Insignia: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Insignia/BMA.EHR.Insignia.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Insignia: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Insignia/BMA.EHR.Insignia.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Leave: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Leave/BMA.EHR.Leave.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Leave: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Leave/BMA.EHR.Leave.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.MetaData.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.MetaData.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.OrganizationEmployee.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.OrganizationEmployee.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Placement.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Placement.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Report.Service: dotnet" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net6.0" />
<option name="LAUNCH_PROFILE_NAME" value="dotnet" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Report.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net6.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Report.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net6.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Report.Service: report-designer" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net6.0" />
<option name="LAUNCH_PROFILE_NAME" value="report-designer" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Retirement.Service: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.Retirement.Service: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="LinkageResponseTest" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/LinkageResponseTest/LinkageResponseTest.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
<option name="LAUNCH_PROFILE_NAME" value="LinkageResponseTest" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration name="BMA.EHR.CheckInConsumer/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.checkinconsumer" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="sourceFilePath" value="BMA.EHR.CheckInConsumer/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="false" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Command.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.command.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.Command.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Discipline.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.discipline.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="sourceFilePath" value="BMA.EHR.Discipline.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="false" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Insignia/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.insignia" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.Insignia/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Leave/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.leave" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.Leave/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.MetaData.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.metadata.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.MetaData.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.OrganizationEmployee.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.organizationemployee.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.OrganizationEmployee.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Placement.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.placement.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.Placement.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Report.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.report.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.Report.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="BMA.EHR.Retirement.Service/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="bma.ehr.retirement.service" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="BMA.EHR.Retirement.Service/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="true" />
<method v="2" />
</configuration>
<configuration name="LinkageResponseTest/Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="containerName" value="linkageresponsetest" />
<option name="contextFolderPath" value="$PROJECT_DIR$" />
<option name="sourceFilePath" value="LinkageResponseTest/Dockerfile" />
</settings>
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="false" />
<method v="2" />
</configuration>
<configuration default="true" type="docker-deploy" factoryName="dockerfile" temporary="true">
<deployment type="dockerfile">
<settings />
</deployment>
<EXTENSION ID="com.jetbrains.rider.docker.debug" isFastModeEnabled="true" isSslEnabled="false" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="85fddeb6-44fd-40a4-864f-89daec07db75" name="Changes" comment="" />
<created>1724638841465</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1724638841465</updated>
<workItem from="1724638842250" duration="4068000" />
<workItem from="1750388252688" duration="1877000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DotNet Breakpoints">
<url>file://$PROJECT_DIR$/BMA.EHR.Leave/Controllers/LeaveController.cs</url>
<line>1159</line>
<properties documentPath="$PROJECT_DIR$/BMA.EHR.Leave/Controllers/LeaveController.cs" containingFunctionPresentation="Method 'CheckInHistoryAsync'">
<startOffsets>
<option value="50795" />
</startOffsets>
<endOffsets>
<option value="50887" />
</endOffsets>
</properties>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View file

@ -115,12 +115,15 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
// apply migrations
//await using var scope = app.Services.CreateAsyncScope();

View file

@ -148,13 +148,15 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
// app.UseMiddleware<ErrorHandlerMiddleware>();
// app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{

View file

@ -0,0 +1,550 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Nest;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Net;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Text.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace BMA.EHR.Domain.Middlewares
{
public class CombinedErrorHandlerAndLoggingMiddleware
{
private readonly RequestDelegate _next;
private readonly IConfiguration _configuration;
private string Uri = "";
private string IndexFormat = "";
private string SystemName = "";
private string APIKey = "";
public CombinedErrorHandlerAndLoggingMiddleware(RequestDelegate next, IConfiguration configuration)
{
_next = next;
_configuration = configuration;
Uri = _configuration["ElasticConfiguration:Uri"] ?? "http://192.168.1.40:9200";
IndexFormat = _configuration["ElasticConfiguration:IndexFormat"] ?? "bma-ehr-log-index";
SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown";
}
public async Task Invoke(HttpContext context)
{
Console.WriteLine("=== CombinedErrorHandlerAndLoggingMiddleware Start ===");
var settings = new ConnectionSettings(new Uri(Uri))
.DefaultIndex(IndexFormat);
var client = new ElasticClient(settings);
var startTime = DateTime.UtcNow;
var stopwatch = Stopwatch.StartNew();
string? responseBodyJson = null;
string? requestBodyJson = null;
Exception? caughtException = null;
// อ่าน Request Body
string requestBody = await ReadRequestBodyAsync(context);
if (requestBody != "")
{
requestBodyJson = await FormatRequestBody(context, requestBody);
}
var originalBodyStream = context.Response.Body;
using (var memoryStream = new MemoryStream())
{
// เปลี่ยน stream ของ Response เพื่อให้สามารถอ่านได้
context.Response.Body = memoryStream;
var keycloakId = context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? Guid.Empty.ToString("D");
var token = context.Request.Headers["Authorization"];
GetProfileByKeycloakIdLocal? pf = null;
try
{
pf = await GetProfileByKeycloakIdAsync(Guid.Parse(keycloakId), token);
}
catch (Exception ex)
{
Console.WriteLine($"Error getting profile: {ex.Message}");
}
try
{
await _next(context);
Console.WriteLine($"Request completed with status: {context.Response.StatusCode}");
// จัดการ response format หลังจาก request ผ่าน pipeline แล้ว
// รวมถึงการจัดการ 401/403 ที่มาจาก Authentication middleware
await FormatResponse(context, memoryStream);
}
catch (ObjectDisposedException)
{
Console.WriteLine("ObjectDisposedException caught in main Invoke");
caughtException = new ObjectDisposedException("Response");
return;
}
catch (OperationCanceledException)
{
Console.WriteLine("OperationCanceledException caught in main Invoke");
caughtException = new OperationCanceledException("Operation was cancelled");
return;
}
catch (Exception error)
{
Console.WriteLine($"Exception caught in main Invoke: {error.Message}");
caughtException = error;
// จัดการ exception และ format เป็น response
await FormatExceptionResponse(context, error, memoryStream);
}
finally
{
stopwatch.Stop();
await LogRequest(context, client, startTime, stopwatch, pf, keycloakId, requestBodyJson, memoryStream, caughtException);
// เขียนข้อมูลกลับไปยัง original Response body
if (memoryStream.Length > 0)
{
memoryStream.Seek(0, SeekOrigin.Begin);
await memoryStream.CopyToAsync(originalBodyStream);
}
}
}
Console.WriteLine("=== CombinedErrorHandlerAndLoggingMiddleware End ===");
}
private async Task<string> FormatRequestBody(HttpContext context, string requestBody)
{
try
{
if (context.Request.HasFormContentType)
{
var form = await context.Request.ReadFormAsync();
var formData = new Dictionary<string, object>();
foreach (var field in form)
{
formData[field.Key] = field.Value.ToString();
}
if (form.Files.Count > 0)
{
var fileDataList = new List<object>();
foreach (var file in form.Files)
{
fileDataList.Add(new
{
FileName = file.FileName,
ContentType = file.ContentType,
Size = file.Length
});
}
formData["Files"] = fileDataList;
}
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true,
Converters = { new DateTimeFixConverter() }
};
return JsonSerializer.Serialize(formData, jsonOptions);
}
else
{
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true,
Converters = { new DateTimeFixConverter() }
};
return JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(requestBody), jsonOptions);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error formatting request body: {ex.Message}");
return requestBody;
}
}
private static async Task FormatResponse(HttpContext context, MemoryStream memoryStream)
{
try
{
if (context?.Response == null)
return;
var response = context.Response;
var statusCode = response.StatusCode;
Console.WriteLine($"FormatResponse: StatusCode={statusCode}, HasStarted={response.HasStarted}");
// จัดการ response format แม้กับ status code จาก Authentication middleware
if (!response.HasStarted && ShouldFormatResponse(statusCode))
{
Console.WriteLine($"Formatting response for status: {statusCode}");
var responseModel = CreateResponseModel(statusCode);
// Clear memory stream และเขียน response ใหม่
memoryStream.SetLength(0);
memoryStream.Position = 0;
// ไม่เปลี่ยน status code ที่ Authentication middleware ตั้งไว้
response.ContentType = "application/json; charset=utf-8";
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false
};
var jsonResponse = JsonSerializer.Serialize(responseModel, jsonOptions);
var bytes = System.Text.Encoding.UTF8.GetBytes(jsonResponse);
await memoryStream.WriteAsync(bytes, 0, bytes.Length);
Console.WriteLine($"Response formatted successfully: {jsonResponse}");
}
// หากเป็น 401/403 แต่ยังไม่มี response body ให้สร้างใหม่
else if (!response.HasStarted && (statusCode == 401 || statusCode == 403) && memoryStream.Length == 0)
{
Console.WriteLine($"Creating response body for {statusCode} status");
var responseModel = CreateResponseModel(statusCode);
response.ContentType = "application/json; charset=utf-8";
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false
};
var jsonResponse = JsonSerializer.Serialize(responseModel, jsonOptions);
var bytes = System.Text.Encoding.UTF8.GetBytes(jsonResponse);
await memoryStream.WriteAsync(bytes, 0, bytes.Length);
Console.WriteLine($"Response body created: {jsonResponse}");
}
}
catch (ObjectDisposedException)
{
Console.WriteLine("ObjectDisposedException in FormatResponse");
}
catch (Exception ex)
{
Console.WriteLine($"Error in FormatResponse: {ex.Message}");
}
}
private static async Task FormatExceptionResponse(HttpContext context, Exception error, MemoryStream memoryStream)
{
try
{
Console.WriteLine($"FormatExceptionResponse: Error={error.Message}");
if (context?.Response == null)
return;
var response = context.Response;
Console.WriteLine($"Response HasStarted: {response.HasStarted}");
if (!response.HasStarted)
{
// Clear memory stream และเขียน error response
memoryStream.SetLength(0);
memoryStream.Position = 0;
response.StatusCode = (int)HttpStatusCode.InternalServerError;
response.ContentType = "application/json; charset=utf-8";
var responseModel = new ResponseObject
{
Status = response.StatusCode,
Message = GlobalMessages.ExceptionOccured,
Result = GetErrorMessage(error)
};
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false
};
var jsonResponse = JsonSerializer.Serialize(responseModel, jsonOptions);
var bytes = System.Text.Encoding.UTF8.GetBytes(jsonResponse);
await memoryStream.WriteAsync(bytes, 0, bytes.Length);
Console.WriteLine($"Exception response formatted: {jsonResponse}");
}
else
{
Console.WriteLine("Cannot format exception response - response already started");
}
}
catch (ObjectDisposedException)
{
Console.WriteLine("ObjectDisposedException in FormatExceptionResponse");
}
catch (Exception ex)
{
Console.WriteLine($"Error in FormatExceptionResponse: {ex.Message}");
}
}
private async Task LogRequest(HttpContext context, ElasticClient client, DateTime startTime, Stopwatch stopwatch,
GetProfileByKeycloakIdLocal? pf, string keycloakId, string? requestBodyJson, MemoryStream memoryStream, Exception? caughtException)
{
try
{
var processTime = stopwatch.ElapsedMilliseconds;
var endTime = DateTime.UtcNow;
var statusCode = caughtException != null ? (int)HttpStatusCode.InternalServerError : context.Response.StatusCode;
var logType = caughtException != null ? "error" : statusCode switch
{
>= 500 => "error",
>= 400 => "warning",
_ => "info"
};
string? message = null;
string? responseBodyJson = null;
// อ่านข้อมูลจาก Response
if (memoryStream.Length > 0)
{
memoryStream.Seek(0, SeekOrigin.Begin);
var responseBody = new StreamReader(memoryStream).ReadToEnd();
if (responseBody != "")
{
var contentType = context.Response.ContentType;
var isFileResponse = !contentType.StartsWith("application/json") && (
contentType.StartsWith("application/") ||
contentType.StartsWith("image/") ||
contentType.StartsWith("audio/") ||
context.Response.Headers.ContainsKey("Content-Disposition")
);
if (isFileResponse)
{
responseBodyJson = "";
message = "success";
}
else
{
try
{
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true,
Converters = { new DateTimeFixConverter() }
};
responseBodyJson = JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(responseBody), jsonOptions);
var json = JsonSerializer.Deserialize<JsonElement>(responseBody);
if (json.ValueKind == JsonValueKind.Array)
{
message = "success";
}
else
{
if (json.TryGetProperty("message", out var messageElement))
{
message = messageElement.GetString();
}
}
}
catch
{
responseBodyJson = responseBody;
message = caughtException?.Message ?? "Unknown error";
}
}
}
}
if (caughtException != null)
{
message = caughtException.Message;
}
var logData = new
{
logType = logType,
ip = context.Connection.RemoteIpAddress?.ToString(),
rootId = pf?.RootId,
systemName = SystemName,
startTimeStamp = startTime.ToString("o"),
endTimeStamp = endTime.ToString("o"),
processTime = processTime,
host = context.Request.Host.Value,
method = context.Request.Method,
endpoint = context.Request.Path + context.Request.QueryString,
responseCode = statusCode == 304 ? "200" : statusCode.ToString(),
responseDescription = message,
input = requestBodyJson,
output = responseBodyJson,
userId = keycloakId,
userName = $"{pf?.Prefix ?? ""}{pf?.FirstName ?? ""} {pf?.LastName ?? ""}",
user = pf?.CitizenId ?? "",
exception = caughtException?.ToString()
};
client.IndexDocument(logData);
}
catch (Exception ex)
{
Console.WriteLine($"Error logging request: {ex.Message}");
}
}
private static bool ShouldFormatResponse(int statusCode)
{
return statusCode == (int)HttpStatusCode.Unauthorized ||
statusCode == (int)HttpStatusCode.Forbidden ||
statusCode == (int)HttpStatusCode.BadRequest ||
statusCode == (int)HttpStatusCode.NotFound ||
statusCode == (int)HttpStatusCode.Conflict ||
statusCode == (int)HttpStatusCode.UnprocessableEntity ||
statusCode == (int)HttpStatusCode.InternalServerError;
}
private static ResponseObject CreateResponseModel(int statusCode)
{
var message = statusCode switch
{
(int)HttpStatusCode.Unauthorized => GlobalMessages.NotAuthorized,
(int)HttpStatusCode.Forbidden => GlobalMessages.ForbiddenAccess,
(int)HttpStatusCode.BadRequest => "Bad Request",
(int)HttpStatusCode.NotFound => "Resource Not Found",
(int)HttpStatusCode.Conflict => "Conflict",
(int)HttpStatusCode.UnprocessableEntity => "Validation Error",
(int)HttpStatusCode.InternalServerError => GlobalMessages.ExceptionOccured,
_ => "Error"
};
return new ResponseObject
{
Status = statusCode,
Message = message
};
}
private static string GetErrorMessage(Exception error)
{
var msg = error.Message;
var inner = error.InnerException;
while (inner != null)
{
msg += $" {inner.Message}\r\n";
inner = inner.InnerException;
}
return msg;
}
protected async Task<string> GetExternalAPIAsync(string apiPath, string accessToken, string apiKey)
{
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", apiKey);
var _res = await client.GetAsync(apiPath);
if (_res.IsSuccessStatusCode)
{
var _result = await _res.Content.ReadAsStringAsync();
return _result;
}
return string.Empty;
}
}
catch
{
throw;
}
}
public async Task<GetProfileByKeycloakIdLocal?> GetProfileByKeycloakIdAsync(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultLocal>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
private async Task<string> ReadRequestBodyAsync(HttpContext context)
{
context.Request.EnableBuffering();
using var reader = new StreamReader(context.Request.Body, leaveOpen: true);
var body = await reader.ReadToEndAsync();
context.Request.Body.Position = 0;
return body;
}
}
// Model classes (ถ้ายังไม่มีใน namespace นี้)
public class GetProfileByKeycloakIdLocal
{
public Guid Id { get; set; }
public string? Prefix { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? CitizenId { get; set; }
public string? Root { get; set; }
public string? Child1 { get; set; }
public string? Child2 { get; set; }
public string? Child3 { get; set; }
public string? Child4 { get; set; }
public Guid? RootId { get; set; }
public Guid? Child1Id { get; set; }
public Guid? Child2Id { get; set; }
public Guid? Child3Id { get; set; }
public Guid? Child4Id { get; set; }
public Guid? RootDnaId { get; set; }
public Guid? Child1DnaId { get; set; }
public Guid? Child2DnaId { get; set; }
public Guid? Child3DnaId { get; set; }
public Guid? Child4DnaId { get; set; }
public double? Amount { get; set; }
public double? PositionSalaryAmount { get; set; }
public string? Commander { get; set; }
public Guid? CommanderId { get; set; }
public Guid? CommanderKeycloak { get; set; }
}
public class GetProfileByKeycloakIdResultLocal
{
public string Message { get; set; } = string.Empty;
public int Status { get; set; } = -1;
public GetProfileByKeycloakIdLocal? Result { get; set; }
}
}

View file

@ -17,85 +17,166 @@ namespace BMA.EHR.Domain.Middlewares
public async Task Invoke(HttpContext context)
{
Console.WriteLine("=== ErrorHandlerMiddleware Start ===");
try
{
await _next(context);
Console.WriteLine($"Request completed with status: {context.Response.StatusCode}");
// จัดการ response format หลังจาก request ผ่าน pipeline แล้ว
await FormatResponse(context);
}
catch (ObjectDisposedException)
{
Console.WriteLine("ObjectDisposedException caught in main Invoke");
return;
}
catch (OperationCanceledException)
{
Console.WriteLine("OperationCanceledException caught in main Invoke");
return;
}
catch (Exception error)
{
Console.WriteLine($"Exception caught in main Invoke: {error.Message}");
// จัดการ exception และ format เป็น response
await FormatExceptionResponse(context, error);
}
Console.WriteLine("=== ErrorHandlerMiddleware End ===");
}
private static async Task FormatResponse(HttpContext context)
{
try
{
if (context?.Response == null)
return;
var response = context.Response;
var statusCode = response.StatusCode;
// ตรวจสอบว่า response ยังไม่ถูกส่งและเป็น status code ที่ต้องการจัดการ
if (!response.HasStarted &&
(statusCode == (int)HttpStatusCode.Unauthorized || statusCode == (int)HttpStatusCode.Forbidden))
{
var responseModel = new ResponseObject
{
Status = statusCode,
Message = statusCode == (int)HttpStatusCode.Unauthorized
? GlobalMessages.NotAuthorized
: GlobalMessages.ForbiddenAccess
};
// Debug log
Console.WriteLine($"FormatResponse: StatusCode={statusCode}, HasStarted={response.HasStarted}");
response.ContentType = "application/json";
// จัดการเฉพาะ status code ที่ต้องการ format และ response ยังไม่เริ่ม
if (!response.HasStarted && ShouldFormatResponse(statusCode))
{
Console.WriteLine($"Formatting response for status: {statusCode}");
var responseModel = CreateResponseModel(statusCode);
// Clear และตั้งค่าใหม่
response.Clear();
response.StatusCode = statusCode; // เซ็ตกลับไป
response.ContentType = "application/json; charset=utf-8";
// ใช้ JsonSerializer แทน WriteAsJsonAsync เพื่อความปลอดภัย
var jsonResponse = JsonSerializer.Serialize(responseModel);
await response.WriteAsync(jsonResponse);
Console.WriteLine($"Response formatted successfully: {jsonResponse}");
}
}
catch (Exception error)
catch (ObjectDisposedException)
{
await HandleExceptionAsync(context, error);
Console.WriteLine("ObjectDisposedException in FormatResponse");
}
catch (Exception ex)
{
Console.WriteLine($"Error in FormatResponse: {ex.Message}");
}
}
private static async Task HandleExceptionAsync(HttpContext context, Exception error)
private static async Task FormatExceptionResponse(HttpContext context, Exception error)
{
var response = context.Response;
// ตรวจสอบว่า response ยังไม่ถูกส่งไป
if (response.HasStarted)
{
// ถ้า response เริ่มแล้ว ไม่สามารถแก้ไขได้ แค่ log
Console.WriteLine("Cannot write error response, stream already started.");
Console.WriteLine($"Error: {error}");
return;
}
try
{
// Clear response เฉพาะเมื่อยังไม่ได้เริ่มส่ง
response.Clear();
response.ContentType = "application/json";
response.StatusCode = (int)HttpStatusCode.InternalServerError;
Console.WriteLine($"FormatExceptionResponse: Error={error.Message}");
if (context?.Response == null)
return;
// สร้าง error message
var msg = error.Message;
var inner = error.InnerException;
while (inner != null)
var response = context.Response;
Console.WriteLine($"Response HasStarted: {response.HasStarted}");
if (!response.HasStarted)
{
msg += $" {inner.Message}\r\n";
inner = inner.InnerException;
// Clear และตั้งค่า response
response.Clear();
response.StatusCode = (int)HttpStatusCode.InternalServerError;
response.ContentType = "application/json; charset=utf-8";
var responseModel = new ResponseObject
{
Status = response.StatusCode,
Message = GlobalMessages.ExceptionOccured,
Result = GetErrorMessage(error)
};
var jsonResponse = JsonSerializer.Serialize(responseModel);
await response.WriteAsync(jsonResponse);
Console.WriteLine($"Exception response formatted: {jsonResponse}");
}
var responseModel = new ResponseObject
else
{
Status = response.StatusCode,
Message = GlobalMessages.ExceptionOccured,
Result = msg
};
// ใช้ JsonSerializer และ WriteAsync เพื่อหลีกเลี่ยงปัญหา stream
var jsonResponse = JsonSerializer.Serialize(responseModel);
await response.WriteAsync(jsonResponse);
Console.WriteLine("Cannot format exception response - response already started");
}
}
catch (Exception writeError)
catch (ObjectDisposedException)
{
// ถ้าเขียน response ไม่ได้ ให้ log error
Console.WriteLine("Failed to write error response:");
Console.WriteLine($"Original Error: {error}");
Console.WriteLine($"Write Error: {writeError}");
Console.WriteLine("ObjectDisposedException in FormatExceptionResponse");
}
catch (Exception ex)
{
Console.WriteLine($"Error in FormatExceptionResponse: {ex.Message}");
}
}
private static bool ShouldFormatResponse(int statusCode)
{
// กำหนด status code ที่ต้องการ format
return statusCode == (int)HttpStatusCode.Unauthorized ||
statusCode == (int)HttpStatusCode.Forbidden ||
statusCode == (int)HttpStatusCode.BadRequest ||
statusCode == (int)HttpStatusCode.NotFound ||
statusCode == (int)HttpStatusCode.Conflict ||
statusCode == (int)HttpStatusCode.UnprocessableEntity ||
statusCode == (int)HttpStatusCode.InternalServerError; // 500
}
private static ResponseObject CreateResponseModel(int statusCode)
{
var message = statusCode switch
{
(int)HttpStatusCode.Unauthorized => GlobalMessages.NotAuthorized,
(int)HttpStatusCode.Forbidden => GlobalMessages.ForbiddenAccess,
(int)HttpStatusCode.BadRequest => "Bad Request",
(int)HttpStatusCode.NotFound => "Resource Not Found",
(int)HttpStatusCode.Conflict => "Conflict",
(int)HttpStatusCode.UnprocessableEntity => "Validation Error",
(int)HttpStatusCode.InternalServerError => GlobalMessages.ExceptionOccured,
_ => "Error"
};
return new ResponseObject
{
Status = statusCode,
Message = message
};
}
private static string GetErrorMessage(Exception error)
{
var msg = error.Message;
var inner = error.InnerException;
while (inner != null)
{
msg += $" {inner.Message}\r\n";
inner = inner.InnerException;
}
return msg;
}
}
}

View file

@ -247,46 +247,46 @@ namespace BMA.EHR.Domain.Middlewares
}
}
public class GetProfileByKeycloakIdLocal
{
public Guid Id { get; set; }
public string? Prefix { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? CitizenId { get; set; }
public string? Root { get; set; }
public string? Child1 { get; set; }
public string? Child2 { get; set; }
public string? Child3 { get; set; }
public string? Child4 { get; set; }
public Guid? RootId { get; set; }
public Guid? Child1Id { get; set; }
public Guid? Child2Id { get; set; }
public Guid? Child3Id { get; set; }
public Guid? Child4Id { get; set; }
public Guid? RootDnaId { get; set; }
public Guid? Child1DnaId { get; set; }
public Guid? Child2DnaId { get; set; }
public Guid? Child3DnaId { get; set; }
public Guid? Child4DnaId { get; set; }
public double? Amount { get; set; }
public double? PositionSalaryAmount { get; set; }
public string? Commander { get; set; }
public Guid? CommanderId { get; set; }
public Guid? CommanderKeycloak { get; set; }
}
public class GetProfileByKeycloakIdResultLocal
{
public string Message { get; set; } = string.Empty;
public int Status { get; set; } = -1;
public GetProfileByKeycloakIdLocal? Result { get; set; }
}
// public class GetProfileByKeycloakIdLocal
// {
// public Guid Id { get; set; }
//
// public string? Prefix { get; set; }
// public string? FirstName { get; set; }
// public string? LastName { get; set; }
// public string? CitizenId { get; set; }
//
// public string? Root { get; set; }
// public string? Child1 { get; set; }
// public string? Child2 { get; set; }
// public string? Child3 { get; set; }
// public string? Child4 { get; set; }
// public Guid? RootId { get; set; }
// public Guid? Child1Id { get; set; }
// public Guid? Child2Id { get; set; }
// public Guid? Child3Id { get; set; }
// public Guid? Child4Id { get; set; }
// public Guid? RootDnaId { get; set; }
// public Guid? Child1DnaId { get; set; }
// public Guid? Child2DnaId { get; set; }
// public Guid? Child3DnaId { get; set; }
// public Guid? Child4DnaId { get; set; }
// public double? Amount { get; set; }
// public double? PositionSalaryAmount { get; set; }
// public string? Commander { get; set; }
//
// public Guid? CommanderId { get; set; }
//
// public Guid? CommanderKeycloak { get; set; }
//
// }
//
// public class GetProfileByKeycloakIdResultLocal
// {
// public string Message { get; set; } = string.Empty;
//
// public int Status { get; set; } = -1;
//
// public GetProfileByKeycloakIdLocal? Result { get; set; }
// }
}

View file

@ -164,13 +164,14 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
// app.UseMiddleware<ErrorHandlerMiddleware>();
// app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{
Authorization = new[] { new CustomAuthorizeFilter() }

View file

@ -155,14 +155,19 @@ app.MapHealthChecks("/health");
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
// Disable ก่อน เพื่อแก้ไขให้เรีบร้อยก่อนการใช้งาน
app.UseMiddleware<RequestLoggingMiddleware>();
// app.UseMiddleware<ErrorHandlerMiddleware>();
// // Disable ก่อน เพื่อแก้ไขให้เรีบร้อยก่อนการใช้งาน
// app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()

View file

@ -131,12 +131,13 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
//app.UseMiddleware<ErrorHandlerMiddleware>();
// apply migrations
await using var scope = app.Services.CreateAsyncScope();

View file

@ -113,7 +113,7 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();

View file

@ -147,13 +147,14 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
// app.UseMiddleware<ErrorHandlerMiddleware>();
// app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{

View file

@ -123,12 +123,13 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
//app.UseMiddleware<ErrorHandlerMiddleware>();
// apply migrations
await using var scope = app.Services.CreateAsyncScope();

View file

@ -155,13 +155,14 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<CombinedErrorHandlerAndLoggingMiddleware>();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
// app.UseMiddleware<ErrorHandlerMiddleware>();
// app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{