Implement CTerminologyCode.constraint as String#761
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 670_feature_archie_4_major_version #761 +/- ##
========================================================================
- Coverage 72.42% 72.20% -0.22%
- Complexity 7213 7241 +28
========================================================================
Files 678 679 +1
Lines 23312 23462 +150
Branches 3776 3817 +41
========================================================================
+ Hits 16883 16941 +58
- Misses 4701 4786 +85
- Partials 1728 1735 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Make it Constraint again instead of Object
| public abstract List<Constraint> getConstraint(); | ||
| public abstract Constraint getConstraint(); | ||
|
|
||
| public abstract void setConstraint(List<Constraint> constraint); |
There was a problem hiding this comment.
This abstract method can stay, but just with the parameter Constraint instead of List
... and use this in ADL14 related classes. Instead of the new CTerminologyCode with the pendingCodes object.
| * tests didn't catch because they only counted parse exceptions. | ||
| */ | ||
| @Test | ||
| public void testDemoArchetype() throws Exception { |
There was a problem hiding this comment.
I think we should also test that serialising a parsed ADL1.4 archetype results in the same ADL as it was in the file before. This can also be tested in the ADLArchetypeSerializerParserRoundtripTest maybe, but that file currently only tests ADL2 archetypes I think
There was a problem hiding this comment.
With this test I'm curious to know if serialising the ADL1.4 goes right as we know have a CTerminologyCodeSerializer class, but not one for the CTerminologyCodeADL14.
There was a problem hiding this comment.
Unfortunately, there is no ADL 1.4 serializer in Archie. So a full round trip test, the way you suggest, is not possible. But I've tried to simply add more things to the test to hopefully be more certain.. please take a look...
There was a problem hiding this comment.
The ADLArchetypeSerializer works for both ADL2 and ADL1.4. The reason the serializer is broken is because of it cannot serialize the new CTerminologyCodeADL14 yet. Just as we have a copy of the CTerminologyCode now, we also need a copy of the CTerminologyCodeSerializer and add it to the constraintSerializers in the ADLDefinitionSerializer class.
There was a problem hiding this comment.
During pairprogramming: serializer isn't suited for ADL1.4, so scrap this!
VeraPrinsen
left a comment
There was a problem hiding this comment.
One requested change about the Serializer
| * tests didn't catch because they only counted parse exceptions. | ||
| */ | ||
| @Test | ||
| public void testDemoArchetype() throws Exception { |
There was a problem hiding this comment.
The ADLArchetypeSerializer works for both ADL2 and ADL1.4. The reason the serializer is broken is because of it cannot serialize the new CTerminologyCodeADL14 yet. Just as we have a copy of the CTerminologyCode now, we also need a copy of the CTerminologyCodeSerializer and add it to the constraintSerializers in the ADLDefinitionSerializer class.
…y_contstraint_type_to_string
65bf163
into
670_feature_archie_4_major_version
Summary
This PR fixes #643. The openEHR specification has
CTerminologyCode.constraintas a singleString, but Archie modeled it asList<String>. This PR aligns Archie with the spec.Changes
Core model (
CTerminologyCode)constraintfield changed fromList<String>toString;getConstraint()now returnsStringaddConstraint(String)removed;setConstraint(String)takes a single valuegetConstraintAsList()added as a convenience method for call sites that need list semantics, returning a singleton list or an empty listAbstract primitive object interface (
CPrimitiveObject)getConstraint()return type is now theConstrainttype parameter, allowing each subclass to specify its own typegetConstraintAsList()added as abstract (returningList<?>), implemented in all subclasses; annotated@JsonIgnoreso it is not serialised as a separate propertyaddConstraint()removed from the abstract interfaceADL 1.4 → ADL 2 conversion
ADL 1.4 allows inline multi-code constraints (e.g.
[local::at0001, at0002]and[snomed-ct::12345, 67890]) which have no direct single-string ADL 2 equivalent. To keepCTerminologyCodealigned with the openEHR spec (single-string constraint) while still being able to parse ADL 1.4, a dedicated intermediatetype is introduced:
CTerminologyCodeADL14mirrors the pre-refactorCTerminologyCodeAPI (List<String> constraint,addConstraint(String), etc.). It exists only inside the ADL 1.4 parsing/conversion pipeline; the converter replaces it with aCTerminologyCodebefore any ADL 2 output is produced.(
ADLArchetypeSerializeris an ADL 2 serializer and has no serializer registered forCTerminologyCodeADL14— by design, since this type should never survive conversion.)Adl14PrimitivesConstraintParser,Adl14CComplexObjectParser,CDVOrdinalItem) now producesCTerminologyCodeADL14instead ofCTerminologyCode, preserving multi-code lists exactly as written.ADL14TermConstraintConverteroperates onCTerminologyCodeADL14, applying the existing multi-code logic (collapsing multiple at-codes into a synthesised ac-code value set, creating term bindings for external codes, etc.). When done, eachCTerminologyCodeADL14is replaced in its parent(
CAttribute.childrenorCPrimitiveTuple.members) with a properCTerminologyCodecarrying the single converted constraint string. Downstream code (serializer, validators) only ever sees ADL 2CTerminologyCode.PreviousConversionApplier.gatherUsedValueSetscontinues to useCTerminologyCodebecause it runs after the converter has performed the swap.Serialisation
"constraint": ["at1"]) is handled by the existingUNWRAP_SINGLE_VALUE_ARRAYSJackson featureTests
List<String>JSON formLargeSetOfADL14sTest.testDemoArchetype(), which parses a demo ADL 1.4 archetype exercising (almost) every constraint type and then: asserts everyCTerminologyCodeADL14in the parsed tree has a non-empty constraint (guarding against the silent multi-code parsing regression that bulk-parse tests miss,since they only count parse exceptions); and converts it to ADL 2, asserting serialize → reparse → serialize-again produces identical text
CTerminologyCode,CTerminologyCodeADL14, the converter'stoAdl2field-copy step, and the ADL 1.4 terminology-code parser branches