Skip to content

Ignixa L3: Native persistence writes - #6076

Draft
Brendan Kowitz (brendankowitz) wants to merge 31 commits into
mainfrom
feature/ignixa-sdk/l3-native-persistence-writes
Draft

Brendan Kowitz (brendankowitz) wants to merge 31 commits into
mainfrom
feature/ignixa-sdk/l3-native-persistence-writes

Conversation

@brendankowitz

@brendankowitz Brendan Kowitz (brendankowitz) commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

This draft includes Tasks 1–5 of AB#198707: the PersistenceWrite seam and startup diagnostics, the native Ignixa import carrier and date coercion, the Firely-compatible native JSON writer, startup registration and activation, and SQL import integration evidence. No schema or native read changes; native Cosmos validation is out of scope.

Enable: Set FhirServer:CoreFeatures:FhirSdkProvider:PersistenceWrite to Ignixa and restart. If unset, it inherits SystemDefault, which defaults to Firely. Roll back: Explicitly set PersistenceWrite to Firely and restart; other seams are unchanged. The startup log reports the selected writer, and host startup fails if the writer cannot be constructed.

The baseline is Ignixa import + Firely write (IF): Ignixa import + native write (II) must accept and store equivalent JSON for lines IF accepts, subject to the exceptions below. The writer emits directly from the native node without round-tripping through a Firely POCO or post-processing serialized JSON. It delegates non-native carriers to Firely before writing and never retries a failed native write with Firely.

  • Text and instants: II preserves edge whitespace in string, markdown, and xhtml. Outside the existing Meta.lastUpdated normalization, II preserves readable instant spellings, including partial or offset-less forms that Firely accepts and IF may normalize. Firely readability alone does not make those spellings conformant FHIR instants.
  • Decimal precision (D1): II preserves the valid input token, including scale and exponent spelling, and retains valid values beyond System.Decimal precision that IF rounds or underflows. Values that neither can store are rejected visibly.
  • ExampleScenario (F11): II retains valid ExampleScenario.instance[].resourceType values that IF drops.
  • Malformed input (D2): Malformed-only divergences are 2.1 follow-ups only if they neither store data IF rejects nor silently lose data. Differences on valid FHIR, storing data IF rejects, and silent data loss still block, apart from the documented exceptions.
  • Choice cardinality (F41): II rejects multiple populated arms of a singleton choice, matching IF. A primitive value and its underscore companion count as one arm.
  • Temporal read-back (D3; F42/F43): II validates date, dateTime, instant, and time against Firely read behavior. It rejects malformed instants as IF does and reports a per-line error for malformed dates, date-times, and times that IF can write but the production Firely deserializer cannot read. Readable input spellings are preserved subject to existing import normalization.
  • Root metadata: II emits the root meta.versionId and meta.lastUpdated scalars before all other root Meta children. This makes the current SQL first-match rewrite target the root rather than an earlier distinct nested value inside root meta (for example under meta.extension or _source.extension). It does not cover Meta that serializes before root meta, such as _id.extension[].valueMeta. Firely writes that shape first too (FF, IF and II alike), so it is inherited behavior. Like document-wide replacement of an equal nested value, it belongs to the open root-scoped SQL meta gate. No production SQL changed.

AB#206675 follow-ups: invalid choices such as R4 Observation.valueCode (II rejects; IF can write unreadable output); singleton arrays on non-collection primitives and meta; null primitive array slots with scalar companions; _photo on a complex element; Extension.url edge whitespace; and Unicode edge whitespace on base64. Malformed root meta or meta.lastUpdated replacement is pre-existing and out of scope.

Open merge gates: AB#206675 (2.1, including its separate corpus) and AB#206676 (2.2 equality) must merge; SQL metadata edits must be scoped to the root; the isolated write performance comparison remains outstanding. This PR stays draft.

Related issues

Refs AB#198707. ADR-2608 defines provider selection.

Testing

Validation at 79771103732bfbb422659ff2a3adb837bd5da647 (passed / failed / skipped):

Acceptance criterion Implemented in Evidence and result
Seam key, inheritance, and override; one writer activates at startup; non-native carrier yields Firely-identical bytes FhirSdkProviderConfiguration, PersistenceModule Core 1,782 / 0 / 0; R4 and R5 API each 1,919 / 0 / 0. STU3 API had one timing failure in BundleHandlerTests; the affected class passed 51 / 0 / 0 on isolated rerun.
Native node and date coercion; native JSON matches IF subject to documented exceptions; accepted outputs read back IgnixaImportResourceParser, ModelExtensions, IgnixaRawResourceFactory, FirelyCompatibleResourceJsonWriter Full R4 Core 2,657 / 0 / 1. Focused writer tests: STU3 238, R4 323, R4B 324, R5 210 passed, with no failures or skips. All 434 accepted differential rows (70 / 167 / 149 / 48, respectively) read back through the production Firely ResourceDeserializer for both IF and II.
Invalid primitive inputs do not produce unreadable native output Schema-generated writer corpus 156 rows (STU3 34, R4 40, R4B 40, R5 42): 37 matched readable outputs, 107 matched rejections, and 12 unreadable IF writes that II rejected (one malformed date, dateTime, and time per version). No unreadable II output. STU3's unused uuid has no representative schema element.
Real NDJSON through both production parser/writer pairs and the SQL importer SqlServerImporterIntegrationTests Local R4 19 / 0 / 4; STU3 and R5 each 18 / 0 / 4. Covers raw SQL bytes, history, uploaded errors, no-op re-import, conflicts, and soft delete. The new R4 test failed with the old writer and confirms the SQL-assigned root version/time change while distinct nested Meta bytes under both _source.extension and meta.extension stay unchanged. SQL corpus evidence uses four accepted and two rejected parity fixtures, not the separate 2.1 corpus.

Four SQL cases are skipped:

Test Reason
GivenReorderedPropertiesWithSameVersion_WhenReimported_ThenSucceedsWithoutNewVersion Requires AB#206676 (2.2 equality)
GivenFirelyWrittenResource_WhenReimportedWithIgnixaNativeWrites_ThenNoSpuriousVersion Requires AB#206676 (2.2 equality)
GivenIgnixaWrittenResource_WhenReimportedWithFirely_ThenNoSpuriousVersion Requires AB#206676 (2.2 equality)
GivenContainedMetaBeforeRootMeta_WhenStoreRewritesRootMeta_ThenOnlyRootMetaChanges (equal-value row only) Requires AB#206676 (root-scoped SQL meta rewrite)
$dotnet = "$env:LOCALAPPDATA\Microsoft\dotnet\dotnet.exe"
& $dotnet build Microsoft.Health.Fhir.sln -c Debug '-p:IntermediateOutputPath=obj\Debug\net11.0\' # Passed; 0 warnings, 0 errors
& $dotnet test --project src\Microsoft.Health.Fhir.Core.UnitTests\Microsoft.Health.Fhir.Core.UnitTests.csproj -c Debug --no-build # 1782/0/0
& $dotnet test --project src\Microsoft.Health.Fhir.R4.Core.UnitTests\Microsoft.Health.Fhir.R4.Core.UnitTests.csproj -c Debug --no-build # 2657/0/1
foreach ($version in 'R4','Stu3','R5') {
    & $dotnet test --project "src\Microsoft.Health.Fhir.Api.UnitTests\Microsoft.Health.Fhir.$version.Api.UnitTests.csproj" -c Debug --no-build # R4 and R5: 1919/0/0 each; STU3: one timing failure, class rerun 51/0/0
}
foreach ($version in 'Stu3','R4','R4B','R5') {
    $project = "Microsoft.Health.Fhir.$version.Core.UnitTests"
    & $dotnet test --project "src\$project\$project.csproj" -c Debug --no-build -- --filter-class Microsoft.Health.Fhir.Core.UnitTests.Features.Persistence.IgnixaRawResourceFactoryTests # 238/0/0, 323/0/0, 324/0/0, 210/0/0
}
$env:SqlServer__ConnectionString = 'Server=(local);Integrated Security=true;TrustServerCertificate=true'
foreach ($version in 'R4','Stu3','R5') {
    $project = "Microsoft.Health.Fhir.$version.Tests.Integration"
    & $dotnet test --project "test\$project\$project.csproj" -c Debug --no-build -- --filter-class Microsoft.Health.Fhir.Tests.Integration.Persistence.SqlServerImporterIntegrationTests # 19/0/4, 18/0/4, 18/0/4
}

The PR pipeline's Run R4 SQL vNext SDK Tests (testR4SqlVNext) and Run Stu3 SQL vNext SDK Tests (testStu3SqlVNext) set SystemDefault=Ignixa, so existing import E2E tests inherit the native writer. CI results for this head are not yet verified.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Feature. Adds a configurable SDK seam; no schema change.

Copilot AI added 7 commits November 19, 2026 15:44
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Match the Firely dateTime lexical shape before truncating date fields. Preserve nonmatching literals in the native node.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@brendankowitz Brendan Kowitz (brendankowitz) added Enhancement Enhancement on existing functionality. Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs No-PaaS-breaking-change ADR-Included ADR Included in the PR labels Nov 20, 2026
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.38%. Comparing base (246fb62) to head (7977110).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6076      +/-   ##
==========================================
+ Coverage   81.64%   82.38%   +0.73%     
==========================================
  Files        1036     1038       +2     
  Lines       40462    40833     +371     
  Branches     6607     6726     +119     
==========================================
+ Hits        33037    33640     +603     
+ Misses       5877     5627     -250     
- Partials     1548     1566      +18     

see 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI added 8 commits November 19, 2026 18:15
Use inline Element metadata before an explicit companion at the same slot. Preserve literal whitespace and reject empty required-binding codes.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Validate trimmed codes against the versioned Firely enum metadata. Select primitive metadata before validation and retain the same slots for both arrays.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Compare acceptance and stored JSON through both Ignixa import paths. Pin the ExampleScenario discriminator difference without weakening the rest of the comparison.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Strip ASCII base64 whitespace during native emission. Compare base64 fixture literals directly and keep the explicit ExampleScenario exception.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use Firely model metadata from the host, validate base64 and numeric literals before writing, and align primitive companions. Exercise both Ignixa import paths against the four versioned corpora.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Pin both sides of the textual whitespace exception. Require matching decimal scale when neither writer uses exponent notation.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Retain fixture timestamps for incremental writes that compare full output. Run import tests that still replace ClockResolver.TimeProvider in one nonparallel xUnit collection.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use an explicit version-specific model provider so prior tests cannot replace the indexer context through global model state.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI added 2 commits November 19, 2026 21:17
Restore the original provider when vector tests finish. Select import payloads and embedded fixtures for the test assembly FHIR version, not the global provider.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Register one raw resource factory for PersistenceWrite. Share the Ignixa schema context with import and retain the Firely writer for non-native carriers.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

public void WriteObject(JsonObject node, IType type, string path, bool root = false, bool editVersion = false)
{
bool resource = root || type.Info.Name is "Resource" or "DomainResource";
}
else
{
Output.Append(metadataWriter.Output, slot.MetadataStart, slot.MetadataLength);
Comment on lines +527 to +534
foreach (ITypeReference candidate in metadata.Types)
{
string code = candidate.Code;
if (suffix.Length == code.Length && suffix[0] == char.ToUpperInvariant(code[0]) && suffix[1..].SequenceEqual(code.AsSpan(1)))
{
return (metadata, schema.GetTypeDefinition(code));
}
}
Copilot AI added 3 commits November 19, 2026 22:28
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the Firely delegate private and verify that it writes the same bytes for Firely carriers. Fail host startup if the selected writer cannot activate.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Activate the selected persistence writer in a hosted service owned by PersistenceModule. Keep the provider logger independent of writer construction.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI added 10 commits November 19, 2026 23:06
Verify SQL import outcomes, version history, and raw stored JSON using both production parser and writer pairs. Keep the four cases that require AB#206676 explicit and skipped.

Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject conflicting singleton choice arms and unreadable temporal values before persistence. Emit root Meta version and timestamp before metadata children without changing nested Meta.

Refs AB#198707
Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs AB#198707

Agent: Kestrel
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment on lines +121 to +122
if ((root && name is "resourceType" or "id" or "_id" or "meta")
|| ((removeVersion || replaceVersion) && name is "versionId" or "_versionId"))
Comment on lines +112 to +117
if ((nativeError is not null && (nativeError is not FormatException || !nativeError.Message.Contains(path, StringComparison.Ordinal)))
|| nativeReadError is not null
|| mixedReadable != nativeReadable
|| unreadableTemporal != (mixedReadError is not null)
|| (unreadableTemporal && mixedReadError is not StructuralTypeException)
|| (mixedReadable && !JsonNode.DeepEquals(JsonNode.Parse(mixed.Data), JsonNode.Parse(native.Data))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ADR-Included ADR Included in the PR Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Enhancement Enhancement on existing functionality. No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants