#466: fix problem checking types on logical models

This commit is contained in:
Grahame Grieve 2021-05-05 09:54:22 +10:00
parent 9ae04aed03
commit c6f392b7e0
4 changed files with 27 additions and 17 deletions

View File

@ -38,12 +38,6 @@ import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.r5.model.Device;
import org.hl7.fhir.r5.model.Group;
import org.hl7.fhir.r5.model.Location;
import org.hl7.fhir.r5.model.Patient;
import org.hl7.fhir.r5.model.Practitioner;
import org.hl7.fhir.r5.model.PractitionerRole;
import org.hl7.fhir.utilities.Utilities;
import ca.uhn.fhir.model.api.annotation.Block;

View File

@ -44,12 +44,6 @@ import ca.uhn.fhir.model.api.annotation.ChildOrder;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Block;
import org.hl7.fhir.instance.model.api.*;
import org.hl7.fhir.r5.model.Device;
import org.hl7.fhir.r5.model.Group;
import org.hl7.fhir.r5.model.Location;
import org.hl7.fhir.r5.model.Patient;
import org.hl7.fhir.r5.model.Practitioner;
import org.hl7.fhir.r5.model.PractitionerRole;
import org.hl7.fhir.exceptions.FHIRException;
/**
* A list is a curated collection of resources.

View File

@ -609,7 +609,8 @@ public class ProfileUtilities extends TranslatingUtilities {
derived.setSnapshot(new StructureDefinitionSnapshotComponent());
try {
checkDifferential(derived.getDifferential().getElement(), derived.getType(), derived.getUrl());
checkDifferential(derived.getDifferential().getElement(), typeName(derived.getType()), derived.getUrl());
checkDifferentialBaseType(derived);
// so we have two lists - the base list, and the differential list
// the differential list is only allowed to include things that are in the base list, but
@ -620,8 +621,6 @@ public class ProfileUtilities extends TranslatingUtilities {
int baseCursor = 0;
int diffCursor = 0; // we need a diff cursor because we can only look ahead, in the bound scoped by longer paths
if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty())
throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT));
for (ElementDefinition e : derived.getDifferential().getElement())
e.clearUserData(GENERATED_IN_SNAPSHOT);
@ -771,6 +770,29 @@ public class ProfileUtilities extends TranslatingUtilities {
derived.clearUserData("profileutils.snapshot.generating");
}
public void checkDifferentialBaseType(StructureDefinition derived) throws Error {
if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) {
if (typeMatchesAncestor(derived.getDifferential().getElementFirstRep().getType(), derived.getBaseDefinition())) {
derived.getDifferential().getElementFirstRep().getType().clear();
} else {
throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT));
}
}
}
private boolean typeMatchesAncestor(List<TypeRefComponent> type, String baseDefinition) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, baseDefinition);
return sd != null && type.size() == 1 && sd.getType().equals(type.get(0).getCode());
}
private String typeName(String type) {
if (Utilities.isAbsoluteUrl(type)) {
return type.substring(type.lastIndexOf("/")+1);
} else {
return type;
}
}
private void checkGroupConstraints(StructureDefinition derived) {
List<ElementDefinition> toRemove = new ArrayList<>();
// List<ElementDefinition> processed = new ArrayList<>();

View File

@ -485,9 +485,9 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
makeSnapshot(sd);
} catch (Exception e) {
System.out.println("Process Note: Unable to generate snapshot for " + sd.present() + ": " + e.getMessage());
if (debug) {
// if (debug) {
e.printStackTrace();
}
// }
}
}
}