make ProfileUtilities methods not static

This commit is contained in:
Grahame Grieve 2020-03-03 07:41:34 +11:00
parent f1d81dde81
commit 09e3816d37
11 changed files with 56 additions and 33 deletions

View File

@ -315,7 +315,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public static List<ElementDefinition> getChildMap(StructureDefinition profile, ElementDefinition element) throws DefinitionException {
public List<ElementDefinition> getChildMap(StructureDefinition profile, ElementDefinition element) throws DefinitionException {
if (element.getContentReference()!=null) {
for (ElementDefinition e : profile.getSnapshot().getElement()) {
if (element.getContentReference().equals("#"+e.getId()))
@ -341,7 +341,7 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public static List<ElementDefinition> getSliceList(StructureDefinition profile, ElementDefinition element) throws DefinitionException {
public List<ElementDefinition> getSliceList(StructureDefinition profile, ElementDefinition element) throws DefinitionException {
if (!element.hasSlicing())
throw new Error("getSliceList should only be called when the element has slicing");
@ -368,11 +368,11 @@ public class ProfileUtilities extends TranslatingUtilities {
* @param path The path of the element within the structure to get the children for
* @return A List containing the element children (all of them are Elements)
*/
public static List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id) {
public List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id) {
return getChildList(profile, path, id, false);
}
public static List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id, boolean diff) {
public List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id, boolean diff) {
List<ElementDefinition> res = new ArrayList<ElementDefinition>();
boolean capturing = id==null;
@ -415,11 +415,11 @@ public class ProfileUtilities extends TranslatingUtilities {
return res;
}
public static List<ElementDefinition> getChildList(StructureDefinition structure, ElementDefinition element, boolean diff) {
public List<ElementDefinition> getChildList(StructureDefinition structure, ElementDefinition element, boolean diff) {
return getChildList(structure, element.getPath(), element.getId(), diff);
}
public static List<ElementDefinition> getChildList(StructureDefinition structure, ElementDefinition element) {
public List<ElementDefinition> getChildList(StructureDefinition structure, ElementDefinition element) {
return getChildList(structure, element.getPath(), element.getId(), false);
}

View File

@ -188,6 +188,7 @@ public class ShExGenerator {
* this makes internal metadata services available to the generator - retrieving structure definitions, and value set expansion etc
*/
private IWorkerContext context;
private ProfileUtilities profileUtilities;
/**
* innerTypes -- inner complex types. Currently flattened in ShEx (doesn't have to be, btw)
@ -208,6 +209,7 @@ public class ShExGenerator {
public ShExGenerator(IWorkerContext context) {
super();
this.context = context;
profileUtilities = new ProfileUtilities(context, null, null);
innerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>();
emittedInnerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>();
datatypes = new HashSet<String>();
@ -486,7 +488,7 @@ public class ShExGenerator {
element_def.add("id", "fhir:" + (id.charAt(0) == id.toLowerCase().charAt(0)? shortId : id) + " ");
}
List<ElementDefinition> children = ProfileUtilities.getChildList(sd, ed);
List<ElementDefinition> children = profileUtilities.getChildList(sd, ed);
if (children.size() > 0) {
innerTypes.add(new ImmutablePair<StructureDefinition, ElementDefinition>(sd, ed));
defn = simpleElement(sd, ed, id);
@ -571,7 +573,7 @@ public class ShExGenerator {
if(typ.hasProfile()) {
if(typ.getWorkingCode().equals("Reference"))
return genReference("", typ);
else if(ProfileUtilities.getChildList(sd, ed).size() > 0) {
else if(profileUtilities.getChildList(sd, ed).size() > 0) {
// inline anonymous type - give it a name and factor it out
innerTypes.add(new ImmutablePair<StructureDefinition, ElementDefinition>(sd, ed));
return simpleElement(sd, ed, id);
@ -704,7 +706,7 @@ public class ShExGenerator {
element_reference.add("comment", comment == null? " " : "# " + comment);
List<String> elements = new ArrayList<String>();
for (ElementDefinition child: ProfileUtilities.getChildList(sd, path, null))
for (ElementDefinition child: profileUtilities.getChildList(sd, path, null))
elements.add(genElementDefinition(sd, child));
element_reference.add("elements", StringUtils.join(elements, "\n"));

View File

@ -107,10 +107,12 @@ public class XmlSchemaGenerator {
private String genDate;
private String license;
private boolean annotations;
private ProfileUtilities profileUtilities;
public XmlSchemaGenerator(String folder, IWorkerContext context) {
this.folder = folder;
this.context = context;
this.profileUtilities = new ProfileUtilities(context, null, null);
}
public boolean isSingle() {
@ -325,12 +327,12 @@ public class XmlSchemaGenerator {
ln(" <xs:sequence>");
// hack....
for (ElementDefinition edc : ProfileUtilities.getChildList(sd, ed)) {
for (ElementDefinition edc : profileUtilities.getChildList(sd, ed)) {
if (!(edc.hasRepresentation(PropertyRepresentation.XMLATTR) || edc.hasRepresentation(PropertyRepresentation.XMLTEXT)) && !inheritedElement(edc))
produceElement(sd, ed, edc, lang);
}
ln(" </xs:sequence>");
for (ElementDefinition edc : ProfileUtilities.getChildList(sd, ed)) {
for (ElementDefinition edc : profileUtilities.getChildList(sd, ed)) {
if ((edc.hasRepresentation(PropertyRepresentation.XMLATTR) || edc.hasRepresentation(PropertyRepresentation.XMLTEXT)) && !inheritedElement(edc))
produceAttribute(sd, ed, edc, lang);
}

View File

@ -46,9 +46,11 @@ import org.hl7.fhir.r5.model.DataType;
public class ObjectConverter {
private IWorkerContext context;
private ProfileUtilities profileUtilities;
public ObjectConverter(IWorkerContext context) {
this.context = context;
profileUtilities = new ProfileUtilities(context, null, null);
}
public Element convert(Resource ig) throws IOException, FHIRException {
@ -76,7 +78,7 @@ public class ObjectConverter {
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
res.setValue(((PrimitiveType) base).asStringValue());
List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
List<ElementDefinition> children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
for (ElementDefinition child : children) {
String n = tail(child.getPath());
if (sd.getKind() != StructureDefinitionKind.PRIMITIVETYPE || !"value".equals(n)) {

View File

@ -44,12 +44,14 @@ public class Property {
private IWorkerContext context;
private ElementDefinition definition;
private StructureDefinition structure;
private Boolean canBePrimitive;
private Boolean canBePrimitive;
private ProfileUtilities profileUtilities;
public Property(IWorkerContext context, ElementDefinition definition, StructureDefinition structure) {
this.context = context;
this.definition = definition;
this.structure = structure;
profileUtilities = new ProfileUtilities(context, null, null);
}
public String getName() {
@ -248,7 +250,7 @@ public class Property {
protected List<Property> getChildProperties(String elementName, String statedType) throws FHIRException {
ElementDefinition ed = definition;
StructureDefinition sd = structure;
List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, ed);
List<ElementDefinition> children = profileUtilities.getChildMap(sd, ed);
String url = null;
if (children.isEmpty() || isElementWithOnlyExtension(ed, children)) {
// ok, find the right definitions
@ -313,7 +315,7 @@ public class Property {
sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null)
throw new DefinitionException("Unable to find type '"+t+"' for name '"+elementName+"' on property "+definition.getPath());
children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
}
}
List<Property> properties = new ArrayList<Property>();
@ -326,7 +328,7 @@ public class Property {
protected List<Property> getChildProperties(TypeDetails type) throws DefinitionException {
ElementDefinition ed = definition;
StructureDefinition sd = structure;
List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, ed);
List<ElementDefinition> children = profileUtilities.getChildMap(sd, ed);
if (children.isEmpty()) {
// ok, find the right definitions
String t = null;
@ -352,7 +354,7 @@ public class Property {
sd = context.fetchResource(StructureDefinition.class, t);
if (sd == null)
throw new DefinitionException("Unable to find class '"+t+"' for name '"+ed.getPath()+"' on property "+definition.getPath());
children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
}
}
List<Property> properties = new ArrayList<Property>();

View File

@ -152,6 +152,7 @@ public class FHIRPathEngine {
private Map<String, StructureDefinition> allTypes = new HashMap<String, StructureDefinition>();
private boolean legacyMode; // some R2 and R3 constraints assume that != is valid for emptty sets, so when running for R2/R3, this is set ot true
private ValidationOptions terminologyServiceOptions = new ValidationOptions();
private ProfileUtilities profileUtilities;
// if the fhir path expressions are allowed to use constants beyond those defined in the specification
// the application can implement them by providing a constant resolver
@ -249,6 +250,7 @@ public class FHIRPathEngine {
public FHIRPathEngine(IWorkerContext worker) {
super();
this.worker = worker;
profileUtilities = new ProfileUtilities(worker, null, null);
for (StructureDefinition sd : worker.getStructures()) {
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() != StructureDefinitionKind.LOGICAL)
allTypes.put(sd.getName(), sd);
@ -4204,14 +4206,14 @@ public class FHIRPathEngine {
focus = element;
} else {
List<ElementDefinition> childDefinitions;
childDefinitions = ProfileUtilities.getChildMap(sd, element);
childDefinitions = profileUtilities.getChildMap(sd, element);
// if that's empty, get the children of the type
if (childDefinitions.isEmpty()) {
sd = fetchStructureByType(element);
if (sd == null)
throw new DefinitionException("Problem with use of resolve() - profile '"+element.getType().get(0).getProfile()+"' on "+element.getId()+" could not be resolved");
childDefinitions = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
childDefinitions = profileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
}
for (ElementDefinition t : childDefinitions) {
if (tailMatches(t, expr.getName())) {
@ -4237,14 +4239,14 @@ public class FHIRPathEngine {
} else if ("extension".equals(expr.getName())) {
String targetUrl = expr.getParameters().get(0).getConstant().primitiveValue();
// targetUrl = targetUrl.substring(1,targetUrl.length()-1);
List<ElementDefinition> childDefinitions = ProfileUtilities.getChildMap(sd, element);
List<ElementDefinition> childDefinitions = profileUtilities.getChildMap(sd, element);
for (ElementDefinition t : childDefinitions) {
if (t.getPath().endsWith(".extension") && t.hasSliceName()) {
StructureDefinition exsd = worker.fetchResource(StructureDefinition.class, t.getType().get(0).getProfile().get(0).getValue());
while (exsd!=null && !exsd.getBaseDefinition().equals("http://hl7.org/fhir/StructureDefinition/Extension"))
exsd = worker.fetchResource(StructureDefinition.class, exsd.getBaseDefinition());
if (exsd.getUrl().equals(targetUrl)) {
if (ProfileUtilities.getChildMap(sd, t).isEmpty())
if (profileUtilities.getChildMap(sd, t).isEmpty())
sd = exsd;
focus = t;
break;
@ -4269,7 +4271,7 @@ public class FHIRPathEngine {
}
private ElementDefinition pickMandatorySlice(StructureDefinition sd, ElementDefinition element) throws DefinitionException {
List<ElementDefinition> list = ProfileUtilities.getSliceList(sd, element);
List<ElementDefinition> list = profileUtilities.getSliceList(sd, element);
for (ElementDefinition ed : list) {
if (ed.getMin() > 0)
return ed;

View File

@ -56,10 +56,12 @@ public class GraphQLSchemaGenerator {
private static final String INNER_TYPE_NAME = "gql.type.name";
IWorkerContext context;
private ProfileUtilities profileUtilities;
public GraphQLSchemaGenerator(IWorkerContext context) {
super();
this.context = context;
profileUtilities = new ProfileUtilities(context, null, null);
}
public void generateTypes(OutputStream stream) throws IOException, FHIRException {
@ -265,7 +267,7 @@ public class GraphQLSchemaGenerator {
}
private void generateProperties(List<StringBuilder> list, StringBuilder b, String typeName, StructureDefinition sd, ElementDefinition ed, String mode, String suffix) throws IOException {
List<ElementDefinition> children = ProfileUtilities.getChildList(sd, ed);
List<ElementDefinition> children = profileUtilities.getChildList(sd, ed);
for (ElementDefinition child : children) {
if (child.hasContentReference()) {
ElementDefinition ref = resolveContentReference(sd, child.getContentReference());

View File

@ -482,7 +482,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
@Override
public List<PropertyWrapper> children() {
if (list == null) {
children = ProfileUtilities.getChildList(structure, definition);
children = profileUtilities.getChildList(structure, definition);
list = new ArrayList<NarrativeGenerator.PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
@ -632,7 +632,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
@Override
public List<PropertyWrapper> children() {
if (list == null) {
children = ProfileUtilities.getChildList(structure, definition);
children = profileUtilities.getChildList(structure, definition);
list = new ArrayList<NarrativeGenerator.PropertyWrapper>();
for (ElementDefinition child : children) {
List<org.hl7.fhir.r5.elementmodel.Element> elements = new ArrayList<org.hl7.fhir.r5.elementmodel.Element>();
@ -703,7 +703,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
@Override
public List<PropertyWrapper> children() {
if (list2 == null) {
List<ElementDefinition> children = ProfileUtilities.getChildList(definition, definition.getSnapshot().getElement().get(0));
List<ElementDefinition> children = profileUtilities.getChildList(definition, definition.getSnapshot().getElement().get(0));
list2 = new ArrayList<NarrativeGenerator.PropertyWrapper>();
for (ElementDefinition child : children) {
List<org.hl7.fhir.r5.elementmodel.Element> elements = new ArrayList<org.hl7.fhir.r5.elementmodel.Element>();
@ -841,7 +841,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
@Override
public List<PropertyWrapper> children() {
if (list2 == null) {
List<ElementDefinition> children = ProfileUtilities.getChildList(definition, definition.getSnapshot().getElement().get(0));
List<ElementDefinition> children = profileUtilities.getChildList(definition, definition.getSnapshot().getElement().get(0));
list2 = new ArrayList<NarrativeGenerator.PropertyWrapper>();
for (ElementDefinition child : children) {
List<Element> elements = new ArrayList<Element>();
@ -1044,6 +1044,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
private ValidationOptions terminologyServiceOptions = new ValidationOptions();
private boolean noSlowLookup;
private List<String> codeSystemPropList = new ArrayList<>();
private ProfileUtilities profileUtilities;
public NarrativeGenerator(String prefix, String basePath, IWorkerContext context) {
super();
@ -1077,6 +1078,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
private void init() {
profileUtilities = new ProfileUtilities(context, null, null);
renderingMaps.add(new ConceptMapRenderInstructions("Canonical Status", "http://hl7.org/fhir/ValueSet/resource-status", false));
}

View File

@ -136,10 +136,12 @@ public class QuestionnaireBuilder {
// processing the response. for technical reasons, we still go through the process, but
// we don't do the intensive parts of the work (save time)
private Questionnaire prebuiltQuestionnaire;
private ProfileUtilities profileUtilities;
public QuestionnaireBuilder(IWorkerContext context) {
super();
this.context = context;
profileUtilities = new ProfileUtilities(context, null, null);
}
public Resource getReference() {
@ -291,7 +293,7 @@ public class QuestionnaireBuilder {
}
// now, we iterate the children
List<ElementDefinition> list = ProfileUtilities.getChildList(profile, element);
List<ElementDefinition> list = profileUtilities.getChildList(profile, element);
for (ElementDefinition child : list) {
if (!isExempt(element, child) && !parents.contains(child)) {

View File

@ -229,7 +229,8 @@ public class StructureMapUtilities {
private ITransformerServices services;
private ProfileKnowledgeProvider pkp;
private Map<String, Integer> ids = new HashMap<String, Integer>();
private ValidationOptions terminologyServiceOptions = new ValidationOptions();
private ValidationOptions terminologyServiceOptions = new ValidationOptions();
private ProfileUtilities profileUtilities;
public StructureMapUtilities(IWorkerContext worker, ITransformerServices services, ProfileKnowledgeProvider pkp) {
super();
@ -238,6 +239,7 @@ public class StructureMapUtilities {
this.pkp = pkp;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null);
}
public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) {
@ -246,6 +248,7 @@ public class StructureMapUtilities {
this.services = services;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null);
}
public StructureMapUtilities(IWorkerContext worker) {
@ -253,6 +256,8 @@ public class StructureMapUtilities {
this.worker = worker;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null);
}
public static String render(StructureMap map) {
@ -2934,7 +2939,7 @@ public class StructureMapUtilities {
private void addChildMappings(StringBuilder b, String id, String indent, StructureDefinition sd, ElementDefinition ed, boolean inner) throws DefinitionException {
boolean first = true;
List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, ed);
List<ElementDefinition> children = profileUtilities.getChildMap(sd, ed);
for (ElementDefinition child : children) {
if (first && inner) {
b.append(" then {\r\n");

View File

@ -369,11 +369,13 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
private ValidatorHostServices validatorServices;
private boolean assumeValidRestReferences;
private boolean allowExamples;
private ProfileUtilities profileUtilities;
public InstanceValidator(IWorkerContext theContext, IEvaluationContext hostServices) {
super(theContext);
this.context = theContext;
this.externalHostServices = hostServices;
this.profileUtilities = new ProfileUtilities(theContext, null, null);
fpe = new FHIRPathEngine(context);
validatorServices = new ValidatorHostServices();
fpe.setHostServices(validatorServices);
@ -4570,7 +4572,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
checkFixedValue(errors, stack.getLiteralPath(), element, definition.getFixed(), profile.getUrl(), definition.getSliceName(), null);
// get the list of direct defined children, including slices
List<ElementDefinition> childDefinitions = ProfileUtilities.getChildMap(profile, definition);
List<ElementDefinition> childDefinitions = profileUtilities.getChildMap(profile, definition);
if (childDefinitions.isEmpty()) {
if (actualType == null)
return; // there'll be an error elsewhere in this case, and we're going to stop.
@ -4625,7 +4627,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
throw new DefinitionException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_ACTUAL_TYPE_, actualType));
trackUsage(dt, hostContext, element);
childDefinitions = ProfileUtilities.getChildMap(dt, dt.getSnapshot().getElement().get(0));
childDefinitions = profileUtilities.getChildMap(dt, dt.getSnapshot().getElement().get(0));
return childDefinitions;
}
@ -4926,7 +4928,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
int count = 0;
List<ElementDefinition> slices = null;
if (ed.hasSlicing())
slices = ProfileUtilities.getSliceList(profile, ed);
slices = profileUtilities.getSliceList(profile, ed);
for (ElementInfo ei : children)
if (ei.definition == ed)
count++;