Conversation
|
|
||
| UPDATE dbo.SearchParam | ||
| SET Status = sps.Status, LastUpdated = @lastUpdated, IsPartiallySupported = sps.IsPartiallySupported | ||
| SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled.ToString()}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported.ToString()}' ELSE sps.Status END) ELSE sps.Status END |
Check notice
Code scanning / CodeQL
Redundant ToString() call Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
In general, to fix redundant ToString() calls in interpolated or concatenated strings, remove the explicit .ToString() when the language/runtime will implicitly convert the value to string anyway (such as in $"..." or string.Format). This keeps the code simpler and avoids unnecessary method calls.
In this specific case, within InitializeSearchParameterStatuses in SqlServerFhirModel.cs, line 397 builds a SQL command via an interpolated verbatim string. It uses '{SearchParameterStatus.Enabled.ToString()}' and '{SearchParameterStatus.Supported.ToString()}' inside the command text. C# interpolated strings automatically call ToString() on SearchParameterStatus.Enabled and SearchParameterStatus.Supported, so the explicit .ToString() calls are redundant. The correct fix is to remove .ToString() from both occurrences on that line, leaving '{SearchParameterStatus.Enabled}' and '{SearchParameterStatus.Supported}'. No other imports, methods, or definitions are needed, and the resulting SQL text will be identical to the current one.
Concretely:
- Edit
src/Microsoft.Health.Fhir.SqlServer/Features/Storage/SqlServerFhirModel.cs. - In the
sqlCommandWrapper.CommandTextassignment, on theUPDATE dbo.SearchParamline, replaceSearchParameterStatus.Enabled.ToString()withSearchParameterStatus.EnabledandSearchParameterStatus.Supported.ToString()withSearchParameterStatus.Supported. - Leave all other code unchanged.
| @@ -394,7 +394,7 @@ | ||
| DECLARE @resourcesPresent bit = CASE WHEN EXISTS (SELECT TOP 1 * FROM Resource) THEN 1 ELSE 0 END | ||
|
|
||
| UPDATE dbo.SearchParam | ||
| SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled.ToString()}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported.ToString()}' ELSE sps.Status END) ELSE sps.Status END | ||
| SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported}' ELSE sps.Status END) ELSE sps.Status END | ||
| , LastUpdated = @lastUpdated, IsPartiallySupported = sps.IsPartiallySupported | ||
| FROM dbo.SearchParam INNER JOIN @searchParamStatuses as sps | ||
| ON dbo.SearchParam.Uri = sps.Uri |
|
|
||
| UPDATE dbo.SearchParam | ||
| SET Status = sps.Status, LastUpdated = @lastUpdated, IsPartiallySupported = sps.IsPartiallySupported | ||
| SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled.ToString()}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported.ToString()}' ELSE sps.Status END) ELSE sps.Status END |
Check notice
Code scanning / CodeQL
Redundant ToString() call Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
In general, to fix redundant ToString() calls in interpolated strings or string concatenations, you should remove the explicit .ToString() and let C#’s implicit conversion (via string.Format or interpolation) invoke ToString() as needed. This avoids unnecessary method calls and cleans up the code without altering behavior.
In this specific method, InitializeSearchParameterStatuses, the SQL command text is built with an interpolated verbatim string assigned to sqlCommandWrapper.CommandText. Line 397 contains two explicit ToString() calls: SearchParameterStatus.Enabled.ToString() and SearchParameterStatus.Supported.ToString(). These appear inside {...} interpolation holes, so the compiler will already call ToString() on those values. We can safely remove both .ToString() calls and interpolate SearchParameterStatus.Enabled and SearchParameterStatus.Supported directly. No additional imports, methods, or definitions are needed; only this line in SqlServerFhirModel.cs must be updated.
Concretely, update line 397 from:
SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled.ToString()}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported.ToString()}' ELSE sps.Status END) ELSE sps.Status ENDto:
SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported}' ELSE sps.Status END) ELSE sps.Status ENDThis preserves the generated SQL while removing redundant ToString() calls.
| @@ -394,7 +394,7 @@ | ||
| DECLARE @resourcesPresent bit = CASE WHEN EXISTS (SELECT TOP 1 * FROM Resource) THEN 1 ELSE 0 END | ||
|
|
||
| UPDATE dbo.SearchParam | ||
| SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled.ToString()}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported.ToString()}' ELSE sps.Status END) ELSE sps.Status END | ||
| SET Status = CASE WHEN sps.Status = '{SearchParameterStatus.Enabled}' THEN (CASE WHEN @resourcesPresent = 1 THEN '{SearchParameterStatus.Supported}' ELSE sps.Status END) ELSE sps.Status END | ||
| , LastUpdated = @lastUpdated, IsPartiallySupported = sps.IsPartiallySupported | ||
| FROM dbo.SearchParam INNER JOIN @searchParamStatuses as sps | ||
| ON dbo.SearchParam.Uri = sps.Uri |
Description
Adds a built in search parameter for the expiry date extension.
Related issues
Addresses User Story 183519
Testing
Describe how this change was tested.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)