Skip to content

Add targeted SQL data-fix script to remap mislabeled Mikrodilution tests to Micronaut#224

Draft
Copilot wants to merge 8 commits into
masterfrom
copilot/fix-test-method-mikrodilution-to-micronaut
Draft

Add targeted SQL data-fix script to remap mislabeled Mikrodilution tests to Micronaut#224
Copilot wants to merge 8 commits into
masterfrom
copilot/fix-test-method-mikrodilution-to-micronaut

Conversation

Copilot AI commented May 10, 2026

Copy link
Copy Markdown
Contributor

Some AntimicrobialSensitivityTest rows were labeled with TestingMethod = 1 (Microdilution / “Mikrodilution”) even though they belong to Micronaut. This PR adds a focused data-fix script that remaps only the affected SentinelEntry ranges provided by the lab.

  • What changed

    • Added Scripts/2026-05-10-FixTestMethodMikrodilutionToMicronaut.sql.
    • Script contains:
      • a short change header,
      • an enhanced pre-update verification SELECT that joins SentinelEntries and includes:
        • SenderLaboratoryNumber
        • computed LaboratoryNumber (SN-<Year>-<YearlySequentialEntryNumber>)
      • a scoped UPDATE from TestingMethod = 1 to TestingMethod = 3.
    • Added SQL lint configuration file .sqlfluff to correctly configure SQL dialect (tsql) for CI linting.
  • Update scope

    • Applies only to rows where TestingMethod = 1.
    • Restricts affected entries via compact SentinelEntry ID ranges:
      • 1304–1598
      • 1683–1693
      • 1795–1801
      • 1942
      • 2788–2805
  • Implementation snippet

    UPDATE AntimicrobialSensitivityTest
    SET TestingMethod = 3 -- Micronaut
    WHERE TestingMethod = 1 -- Microdilution (displayed as "Mikrodilution")
      AND SentinelEntryId IN (
          SELECT Id FROM SentinelEntries
          WHERE (Id BETWEEN 1304 AND 1598)
             OR (Id BETWEEN 1683 AND 1693)
             OR (Id BETWEEN 1795 AND 1801)
             OR Id = 1942
             OR (Id BETWEEN 2788 AND 2805)
      );
Original prompt

Background

Issue #218 reports that a set of AntimicrobialSensitivityTest entries are mislabelled as Microdilution (displayed as "Mikrodilution" in the UI) but should be Micronaut.

The SpeciesTestingMethod enum in NRZMyk.Services/Data/Entities/SpeciesTestingMethod.cs defines:

public enum SpeciesTestingMethod
{
    Vitek,         // 0
    Microdilution, // 1  — Description: "Mikrodilution"
    YeastOne,      // 2  — Description: "Yeast One"
    Micronaut,     // 3
    ETest          // 4  — Description: "E-Test"
}

So the fix is: set TestingMethod = 3 (Micronaut) where TestingMethod = 1 (Mikrodilution) for the affected sentinel entries.

Task

Add a new SQL script at Scripts/2026-05-10-FixTestMethodMikrodilutionToMicronaut.sql following the conventions of existing scripts in that folder (e.g. Scripts/2023-06-04-FixMicResistanceBasedOnReferenceMethod.sql).

The script should:

  1. Start with a comment block describing when / what the change is.
  2. Include a verification SELECT so the affected rows can be checked before running the UPDATE.
  3. Include the UPDATE statement.

The affected SentinelEntryId values come from a CSV provided by the laboratory. They fall into these compact ID ranges (use ranges, not individual IDs):

Range Notes
1304 – 1598 main batch, SN-2022-xxxx
1683 – 1693 additional SN-2022-xxxx
1795 – 1801 SN-2023-xxxx early batch
1942 single SN-2023-0241 entry (only its Mikrodilution test remains to fix)
2788 – 2805 SN-2024-xxxx

Use BETWEEN for ranges and OR to combine them. The TestingMethod = 1 filter ensures only currently-mislabelled rows are updated (already-correct Micronaut tests, e.g. on SentinelEntry 1942, will not be touched).

Keep the script minimal — no per-row detail, just the ranges above and the two TestingMethod integer constants with inline comments explaining what they mean.

The UPDATE should look roughly like:

-- ~NNN rows affected (verify with SELECT above before running)
UPDATE AntimicrobialSensitivityTest
SET TestingMethod = 3   -- Micronaut
WHERE TestingMethod = 1 -- Microdilution (displayed as "Mikrodilution")
  AND SentinelEntryId IN (
      SELECT Id FROM SentinelEntries
      WHERE (Id BETWEEN 1304 AND 1598)
         OR (Id BETWEEN 1683 AND 1693)
         OR (Id BETWEEN 1795 AND 1801)
         OR Id = 1942
         OR (Id BETWEEN 2788 AND 2805)
  );

Match the style and commenting conventions of the existing scripts in Scripts/.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please prepare a SQL script for this Issue @markusrt/NRZMyk/issues/218

Raise a PR that adds a new SQL script to the Scripts/ folder.

CSV on records to change is attached. Information from Email: "im Anhang die Tabelle mit den SN Nummern bei denen die Testmethode von Mikrodilution auf Micronaut geändert werden muss."

Important: Do include as less as possible detailed information to the script. Some parts of internal IDs, e.g. a range is fine, but the script should, if possible, not contain every detailed ID.

Assistant: Now I have everything I need. The enum shows:

  • Microdilution = 1 (displayed as "Mikrodilution")
  • Micronaut = 3

From the CSV, the affected SentinelEntry IDs cluster into these groups: 1304–1598, 1683–1693, 1795–1801, 1942, and 2788–2805. The TestingMethod = 1 filter ensures only actually-labelled Mikrodilution rows are touched (e.g. ID 1942's already-correct Micronaut tests won't be changed).

Assistant: We're waiting for your response to the tool confirmation dialog to continue creating the pull request.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Add SQL script to change testing method from Mikrodilution to Micronaut Add targeted SQL data-fix script to remap mislabeled Mikrodilution tests to Micronaut May 10, 2026
Copilot AI requested a review from markusrt May 10, 2026 12:15
@markusrt

Copy link
Copy Markdown
Owner

@copilot Please fix linting config, it does not seem to be correctly setup for SQL yet: https://github.com/markusrt/NRZMyk/actions/runs/25628461114

Agent-Logs-Url: https://github.com/markusrt/NRZMyk/sessions/9168512f-6a8b-4326-8edb-ed1a353beb5d

Co-authored-by: markusrt <299753+markusrt@users.noreply.github.com>

-- Verification query (run before UPDATE)
SELECT *
FROM AntimicrobialSensitivityTest

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please add the laboratorynumber and senderlaboratorynumber to this select via join so a human can verify the data is correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in fb87f25. The verification SELECT now joins SentinelEntries and includes both SenderLaboratoryNumber and computed LaboratoryNumber so the affected rows can be reviewed by humans before running the UPDATE.

Agent-Logs-Url: https://github.com/markusrt/NRZMyk/sessions/9168512f-6a8b-4326-8edb-ed1a353beb5d

Co-authored-by: markusrt <299753+markusrt@users.noreply.github.com>
Agent-Logs-Url: https://github.com/markusrt/NRZMyk/sessions/9168512f-6a8b-4326-8edb-ed1a353beb5d

Co-authored-by: markusrt <299753+markusrt@users.noreply.github.com>

Copilot AI commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please fix linting config, it does not seem to be correctly setup for SQL yet: https://github.com/markusrt/NRZMyk/actions/runs/25628461114

Implemented in df2c714. I added a repository-level .sqlfluff config so SQLFluff uses the tsql dialect in CI, and documented the excluded SQLFluff rules to keep linting focused on parse/syntax validity for our data-fix SQL scripts.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants