A clinical workflow can return the right response and still write the wrong data. That was the difficult part of moving a large C# healthcare system into Kotlin and Spring Boot: preserving the database behavior that existing hospital software depended on.

At SmartDoctor, I audited roughly 700 legacy commands during the migration. A complex command could contain around 100 SQL reads and writes. These are approximate figures from my experience; they describe the migration’s scope, not a newly measured benchmark.

The constraint: existing workflows had to keep working

The old system’s behavior was distributed across application branches and complex SQL. Rewriting a query into JPA or QueryDSL did not establish that it would run at the same point, with the same values, or produce the same sequence of effects.

That distinction mattered for clinical, reception and payment workflows. A later query could depend on an earlier update. A read could choose the next branch. Reviewing the final response alone could miss a changed operation order.

The Kotlin code therefore needed a comparison target beyond the C# method’s apparent intent: the SQL actually executed by a command.

My approach: compare the executed work

I instrumented the C# execution path to capture its SQL and configured Spring-side logging to expose statements with their bound values. I used those traces to audit the corresponding command implementations, including operation order.

The tracing libraries’ exact names are no longer in my retained record. Their useful property was visibility into executed statements and parameters; attaching a guessed product name would add little to the explanation.

For each command, the comparison focused on three questions:

  • Did the Kotlin implementation read and modify the same intended records?
  • Did the statement sequence preserve the dependencies of the workflow?
  • Did the bound values match the legacy operation’s behavior?

JPA and QueryDSL gave the new implementation a different structure. The audit still needed to inspect what reached SQL Server. Generated SQL, ORM flush timing and parameter binding are useful investigation points when the two traces differ; a familiar repository method name cannot settle the comparison.

Why order deserved its own check

Consider an illustrative workflow that updates a status before reading a count used by the next decision. Reversing those operations can change the count without causing a SQL error. The same tables and predicates can therefore participate in a different business outcome.

This is why I treated the ordered SQL trace as part of the migration contract. The goal was to preserve the required database interactions and their effects while moving the implementation into a maintainable Kotlin service.

What the work established

The command-by-command audit gave me a concrete way to review compatibility across the migration. I could investigate a difference at the statement and parameter level rather than rely only on whether an endpoint appeared to work.

I do not have the original full audit bundle available for this article, so I do not present the scope as an independently reproduced pass count or claim a measured reduction in defects. The retained source contains the C# references and the Kotlin hospital-domain implementation; the audit method and approximate scope are my account of the work.

The same habit led into a separate performance investigation: two queries that looked equivalent at the application level reached SQL Server with different string types. Read the parameter-binding investigation.