This repository was archived by the owner on Mar 18, 2026. It is now read-only.
feat: opt-in profile constraints and field documentation extraction#5
Open
Palid wants to merge 3 commits intofhir-clj:mainfrom
Open
feat: opt-in profile constraints and field documentation extraction#5Palid wants to merge 3 commits intofhir-clj:mainfrom
Palid wants to merge 3 commits intofhir-clj:mainfrom
Conversation
…on (v0.0.16)
Add two new optional features for type-schema generation, both disabled
by default to maintain backward compatibility:
**1. Profile Constraints Extraction** (`--include-profile-constraints`)
- Extracts FHIR profile URLs from StructureDefinition elements
- Adds `profileConstraints` field to output schema
- Example: Norwegian Basis profiles (no-basis-HumanName, no-basis-Address)
- Useful for: validation, code generation, profile-aware tooling
**2. Field Documentation Extraction** (`--include-field-docs`)
- Extracts element documentation from StructureDefinition
- Includes: short, definition, comment, requirements, mustSupport,
binding info, examples, and other metadata
- Useful for: documentation generation, tooltips, developer guidance
## API Changes
### Library API (translate-fhir-schema)
```clojure
;; Default behavior (backward compatible)
(translate-fhir-schema fhir-schema)
;; With profile constraints
(translate-fhir-schema fhir-schema {:include-profile-constraints? true})
;; With field documentation
(translate-fhir-schema fhir-schema {:include-field-docs? true})
;; Both features enabled
(translate-fhir-schema fhir-schema
{:include-profile-constraints? true
:include-field-docs? true})
```
### CLI Interface
```bash
# Include profile constraints
type-schema --include-profile-constraints hl7.fhir.no.basis@2.2.2
# Include field documentation
type-schema --include-field-docs hl7.fhir.r4.core
# Both flags together
type-schema --include-profile-constraints --include-field-docs \\
hl7.fhir.r4.core hl7.fhir.no.basis@2.2.2
```
## Implementation Details
**Core Functions Added:**
- `path->element-id`: Convert path to StructureDefinition element ID
- `extract-profile-constraints`: Extract profile URLs and names
- `extract-field-documentation`: Extract element documentation
**Updated Functions:**
- `build-field`: Accept and use feature flags
- `iterate-over-elements`: Pass options to build-field
- `iterate-over-backbone-element`: Pass options through
- `translate-fhir-schema`: Accept and propagate options map
- `process-packages` (CLI): Pass CLI flags to translate-fhir-schema
**CLI Options Added:**
- `--include-profile-constraints`: Enable profile constraint extraction
- `--include-field-docs`: Enable field documentation extraction
## Testing
**Library Tests** (test/type_schema/profile_test.clj):
- Backward compatibility tests (flags disabled by default)
- Profile constraints extraction with Norwegian Basis profiles
- Field documentation extraction from standard FHIR Patient
- Combined flags test
- 6 test suites, all passing
**CLI Integration Tests** (test/main_test.clj):
- CLI option parsing validation
- Profile constraints flag with multi-package support
- Field documentation flag integration
- Backward compatibility (no flags)
- 4 additional test suites, all passing
**Test Results**: 25 total tests, 138 assertions, all passing ✅
## Backward Compatibility
- Both features default to `false` - no breaking changes
- All existing tests pass without modification
- Output schema is additive-only (no removed fields)
- Clean JSON output (empty collections removed via remove-empty-vals)
- CLI maintains all existing functionality
## Version
Bumped to **v0.0.16** for this release
6 tasks
Version bump to support FHIR-compliant extension generation with discriminated unions in downstream fhir-schema-codegen. This version is compatible with the extension generation improvements that fix critical FHIR R4 spec violations where Extension profiles incorrectly inherited ALL 55+ value[x] types from base Extension type. No functional changes in type-schema itself - version bump enables coordinated release with fhir-schema-codegen@0.0.25 extension generation fix. Related changes: - fhir-schema-codegen: Extension generation with discriminated unions - medimind: Updated patch for @fhirschema/codegen@0.0.24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Problem
FHIR profiles define important metadata that wasn't being extracted by type-schema:
Profile Constraints: Profiles like Norwegian Basis define constrained complex types (e.g.,
NoBasisHumanNameextendingHumanName) with specific profile URLs that downstream generators need to generate correct TypeScript types.Field Documentation: FHIR elements contain rich documentation (short, definition, comment, requirements, etc.) that should be available as JSDoc comments in generated code for developer experience.
Without this metadata, TypeScript generators cannot:
💡 Solution
This PR introduces two opt-in CLI flags that extract additional metadata from FHIR schemas:
1.
--include-profile-constraintsflagExtracts profile URLs from constrained elements into a new
profileConstraintsfield:{:name "name" :type "HumanName" :profileConstraints [{:url "http://hl7.no/fhir/StructureDefinition/no-basis-HumanName" :kind "complex-type-constraint"}] ...}2.
--include-field-docsflagExtracts comprehensive documentation into field-level docs:
{:name "identifier" :short "A unique identifier for the patient" :definition "An identifier for this patient..." :comment "Patients are almost always assigned..." :requirements "Patients are often assigned specific..." :alias ["Medical Record Number" "MRN"] ...}📊 Evidence & Testing
Test Coverage
false)Real-World Example
Norwegian Basis Patient profile:
Without flags:
With
--include-profile-constraints:With
--include-field-docs:🔧 Implementation Details
Files Changed
src/type_schema/core.clj(+220 lines): Core extraction logicsrc/main.clj(+34 lines): CLI option definitionstest/type_schema/profile_test.clj(+137 lines): Profile constraint teststest/main_test.clj(+80 lines): CLI flag tests.gitignore(+1 line): Ignore generated filesBackward Compatibility
false- no changes to existing behavior🔗 Related Work
Companion PR: fhir-schema/fhir-schema-codegen#40 implements the TypeScript generator support for these new fields.
Release: Available at https://github.com/MEWB-AS/type-schema/releases/tag/v0.0.16 for immediate testing.
🧪 Testing Instructions
✅ Checklist