Add support for Base in logical models on any version of FHIR

This commit is contained in:
Grahame Grieve 2019-12-13 13:10:07 +11:00
parent 674432a8ad
commit 8c4b379806
2 changed files with 45 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -66,6 +67,7 @@ import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.BindingStrength;
import org.hl7.fhir.r5.model.Enumerations.FHIRVersion;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.IntegerType;
@ -5218,6 +5220,36 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public static StructureDefinition makeBaseDefinition(FHIRVersion fhirVersion) {
StructureDefinition base = new StructureDefinition();
base.setId("Base");
base.setUrl("http://hl7.org/fhir/StructureDefinition/Base");
base.setVersion(fhirVersion.toCode());
base.setName("Base");
base.setStatus(PublicationStatus.ACTIVE);
base.setDate(new Date());
base.setFhirVersion(fhirVersion);
base.setKind(StructureDefinitionKind.COMPLEXTYPE);
base.setAbstract(true);
base.setType("Base");
ElementDefinition e = base.getSnapshot().getElementFirstRep();
e.setId("Base");
e.setPath("Base");
e.setMin(0);
e.setMax("*");
e.getBase().setPath("Base");
e.getBase().setMin(0);
e.getBase().setMax("*");
e.setIsModifier(false);
e = base.getDifferential().getElementFirstRep();
e.setId("Base");
e.setPath("Base");
e.setMin(0);
e.setMax("*");
return base;
}
}

View File

@ -594,17 +594,27 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
}
public void generateSnapshot(StructureDefinition p) throws DefinitionException, FHIRException {
if (!p.hasSnapshot() && p.getKind() != StructureDefinitionKind.LOGICAL) {
generateSnapshot(p, false);
}
public void generateSnapshot(StructureDefinition p, boolean logical) throws DefinitionException, FHIRException {
if (!p.hasSnapshot() && (logical || p.getKind() != StructureDefinitionKind.LOGICAL)) {
if (!p.hasBaseDefinition())
throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") has no base and no snapshot");
StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
if (sd == null)
if (sd == null && "http://hl7.org/fhir/StructureDefinition/Base".equals(p.getBaseDefinition())) {
sd = ProfileUtilities.makeBaseDefinition(p.getFhirVersion());
}
if (sd == null) {
throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") base "+p.getBaseDefinition()+" could not be resolved");
}
List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
List<String> errors = new ArrayList<String>();
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.setThrowException(false);
pu.sortDifferential(sd, p, p.getUrl(), errors);
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) {
pu.sortDifferential(sd, p, p.getUrl(), errors);
}
pu.setDebug(false);
for (String err : errors)
msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION, p.getUserString("path"), "Error sorting Differential: "+err, ValidationMessage.IssueSeverity.ERROR));