mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-09 06:14:45 +00:00
fix duplicate element generation in CDA.AD type snapshot generation
This commit is contained in:
parent
5a55f74a91
commit
1a144091c4
@ -676,14 +676,19 @@ public class ProfileUtilities extends TranslatingUtilities {
|
|||||||
if (derived.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
|
if (derived.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
|
||||||
for (ElementDefinition e : diff.getElement()) {
|
for (ElementDefinition e : diff.getElement()) {
|
||||||
if (!e.hasUserData(UD_GENERATED_IN_SNAPSHOT) && e.getPath().contains(".")) {
|
if (!e.hasUserData(UD_GENERATED_IN_SNAPSHOT) && e.getPath().contains(".")) {
|
||||||
ElementDefinition outcome = updateURLs(url, webUrl, e.copy());
|
ElementDefinition existing = getElementInCurrentContext(e.getPath(), derived.getSnapshot().getElement());
|
||||||
e.setUserData(UD_GENERATED_IN_SNAPSHOT, outcome);
|
if (existing != null) {
|
||||||
derived.getSnapshot().addElement(outcome);
|
updateFromDefinition(existing, e, profileName, false, url, base, derived);
|
||||||
if (walksInto(diff.getElement(), e)) {
|
} else {
|
||||||
if (e.getType().size() > 1) {
|
ElementDefinition outcome = updateURLs(url, webUrl, e.copy());
|
||||||
throw new DefinitionException("Unsupported scenario: specialization walks into multiple types at "+e.getId());
|
e.setUserData(UD_GENERATED_IN_SNAPSHOT, outcome);
|
||||||
} else {
|
derived.getSnapshot().addElement(outcome);
|
||||||
addInheritedElementsForSpecialization(derived.getSnapshot(), outcome, outcome.getTypeFirstRep().getWorkingCode(), outcome.getPath(), url, webUrl);
|
if (walksInto(diff.getElement(), e)) {
|
||||||
|
if (e.getType().size() > 1) {
|
||||||
|
throw new DefinitionException("Unsupported scenario: specialization walks into multiple types at "+e.getId());
|
||||||
|
} else {
|
||||||
|
addInheritedElementsForSpecialization(derived.getSnapshot(), outcome, outcome.getTypeFirstRep().getWorkingCode(), outcome.getPath(), url, webUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -877,6 +882,22 @@ public class ProfileUtilities extends TranslatingUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ElementDefinition getElementInCurrentContext(String path, List<ElementDefinition> list) {
|
||||||
|
for (int i = list.size() -1; i >= 0; i--) {
|
||||||
|
ElementDefinition t = list.get(i);
|
||||||
|
if (t.getPath().equals(path)) {
|
||||||
|
return t;
|
||||||
|
} else if (!path.startsWith(head(t.getPath()))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String head(String path) {
|
||||||
|
return path.contains(".") ? path.substring(0, path.lastIndexOf(".")+1) : path;
|
||||||
|
}
|
||||||
|
|
||||||
private void findInheritedObligationProfiles(StructureDefinition derived) {
|
private void findInheritedObligationProfiles(StructureDefinition derived) {
|
||||||
for (Extension ext : derived.getExtensionsByUrl(ToolingExtensions.EXT_OBLIGATION_INHERITS)) {
|
for (Extension ext : derived.getExtensionsByUrl(ToolingExtensions.EXT_OBLIGATION_INHERITS)) {
|
||||||
StructureDefinition op = context.fetchResource(StructureDefinition.class, ext.getValueCanonicalType().primitiveValue());
|
StructureDefinition op = context.fetchResource(StructureDefinition.class, ext.getValueCanonicalType().primitiveValue());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user