Fixing issues and preparing for release (#225)
* Issue #189 - improve Questionnaire error message * fix for issue #187 * more work on comparison * Fix for NamingSystem display
This commit is contained in:
parent
94cca87107
commit
4a4ca9a804
|
@ -226,7 +226,6 @@ public class CodeSystemComparer extends CanonicalResourceComparer {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasDesignation(ConceptDefinitionDesignationComponent td, List<ConceptDefinitionDesignationComponent> designation) {
|
||||
for (ConceptDefinitionDesignationComponent t : designation) {
|
||||
if (designationsMatch(td, t)) {
|
||||
|
@ -303,7 +302,6 @@ public class CodeSystemComparer extends CanonicalResourceComparer {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public XhtmlNode renderConcepts(CodeSystemComparison comparison, String id, String prefix) throws FHIRException, IOException {
|
||||
// columns: code, display (left|right), properties (left|right)
|
||||
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(Utilities.path("[tmp]", "compare"), false);
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
package org.hl7.fhir.r5.comparison;
|
||||
|
||||
import java.awt.image.renderable.RenderContext;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.exceptions.PathEngineException;
|
||||
import org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison;
|
||||
import org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison;
|
||||
import org.hl7.fhir.r5.comparison.ResourceComparer.ResourceComparison;
|
||||
import org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||
import org.hl7.fhir.r5.model.Base;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.ExpressionNode.CollectionStatus;
|
||||
import org.hl7.fhir.r5.model.StringType;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.TypeDetails;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
||||
import org.hl7.fhir.r5.utils.LiquidEngine;
|
||||
import org.hl7.fhir.r5.utils.LiquidEngine.LiquidDocument;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
|
||||
|
||||
public class ComparisonRenderer implements IEvaluationContext {
|
||||
|
||||
private IWorkerContext context;
|
||||
private ComparisonSession session;
|
||||
private Map<String, String> templates = new HashMap<>();
|
||||
private String folder;
|
||||
|
||||
public ComparisonRenderer(IWorkerContext context, String folder) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public Map<String, String> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
public void render() throws IOException {
|
||||
for (String id : session.getCompares().keySet()) {
|
||||
renderComparison(id, session.getCompares().get(id));
|
||||
}
|
||||
}
|
||||
|
||||
private void renderComparison(String id, ResourceComparison comp) throws IOException {
|
||||
if (comp instanceof ProfileComparison) {
|
||||
renderProfile(id, (ProfileComparison) comp);
|
||||
} else if (comp instanceof ValueSetComparison) {
|
||||
renderValueSet(id, (ValueSetComparison) comp);
|
||||
} else if (comp instanceof CodeSystemComparison) {
|
||||
renderCodeSystem(id, (CodeSystemComparison) comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderCodeSystem(String id, CodeSystemComparison comp) throws IOException {
|
||||
String template = templates.get("CodeSystem");
|
||||
Map<String, Base> vars = new HashMap<>();
|
||||
CodeSystemComparer cs = new CodeSystemComparer(session);
|
||||
vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp))));
|
||||
vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", ""))));
|
||||
vars.put("concepts", new StringType(new XhtmlComposer(true).compose(cs.renderConcepts(comp, "", ""))));
|
||||
String cnt = processTemplate(template, "CodeSystem", vars);
|
||||
TextFile.stringToFile(cnt, file(id+".html"));
|
||||
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", id + "-union.json")), comp.getUnion());
|
||||
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", id + "-intersection.json")), comp.getIntersection());
|
||||
}
|
||||
|
||||
private String file(String name) throws IOException {
|
||||
return Utilities.path(folder, name);
|
||||
}
|
||||
|
||||
private void renderValueSet(String id, ValueSetComparison comp) throws FHIRException, IOException {
|
||||
String template = templates.get("ValueSet");
|
||||
Map<String, Base> vars = new HashMap<>();
|
||||
ValueSetComparer cs = new ValueSetComparer(session);
|
||||
vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp))));
|
||||
vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", ""))));
|
||||
vars.put("compose", new StringType(new XhtmlComposer(true).compose(cs.renderCompose(comp, "", ""))));
|
||||
vars.put("expnsion", new StringType(new XhtmlComposer(true).compose(cs.renderExpansion(comp, "", ""))));
|
||||
String cnt = processTemplate(template, "ValueSet", vars);
|
||||
TextFile.stringToFile(cnt, file(id+".html"));
|
||||
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", id + "-union.json")), comp.getUnion());
|
||||
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", id + "-intersection.json")), comp.getIntersection());
|
||||
}
|
||||
|
||||
private void renderProfile(String id, ProfileComparison comp) throws IOException {
|
||||
String template = templates.get("Profile");
|
||||
Map<String, Base> vars = new HashMap<>();
|
||||
ProfileComparer cs = new ProfileComparer(session);
|
||||
vars.put("errors", new StringType(new XhtmlComposer(true).compose(cs.renderErrors(comp))));
|
||||
vars.put("metadata", new StringType(new XhtmlComposer(true).compose(cs.renderMetadata(comp, "", ""))));
|
||||
// vars.put("concepts", new StringType(new XhtmlComposer(true).compose(cs.renderConcepts(comp, "", ""))));
|
||||
String cnt = processTemplate(template, "CodeSystem", vars);
|
||||
TextFile.stringToFile(cnt, file(id+".html"));
|
||||
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", id + "-union.json")), comp.getUnion());
|
||||
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", id + "-intersection.json")), comp.getIntersection());
|
||||
}
|
||||
|
||||
private String processTemplate(String template, String name, Map<String, Base> vars) {
|
||||
LiquidEngine engine = new LiquidEngine(context, this);
|
||||
LiquidDocument doc = engine.parse(template, name+".template");
|
||||
return engine.evaluate(doc, null, vars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Base resolveConstant(Object appContext, String name, boolean beforeContext) throws PathEngineException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Base> vars = (Map<String, Base>) appContext;
|
||||
return vars.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDetails resolveConstantType(Object appContext, String name) throws PathEngineException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Base> vars = (Map<String, Base>) appContext;
|
||||
Base b = vars.get(name);
|
||||
return new TypeDetails(CollectionStatus.SINGLETON, b == null ? "Base" : b.fhirType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean log(String argument, List<Base> focus) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionDetails resolveFunction(String functionName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDetails checkFunction(Object appContext, String functionName, List<TypeDetails> parameters) throws PathEngineException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Base> executeFunction(Object appContext, String functionName, List<List<Base>> parameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Base resolveReference(Object appContext, String url, Base refContext) throws FHIRException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conformsToProfile(Object appContext, Base item, String url) throws FHIRException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueSet resolveValueSet(Object appContext, String url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -25,6 +25,7 @@ public class ComparisonSession {
|
|||
private IWorkerContext context;
|
||||
private String sessiondId;
|
||||
private int count;
|
||||
private boolean debug;
|
||||
|
||||
public ComparisonSession(IWorkerContext context) {
|
||||
super();
|
||||
|
@ -90,6 +91,22 @@ public class ComparisonSession {
|
|||
public void identify(ResourceComparison res) {
|
||||
count++;
|
||||
res.setId(sessiondId+"-"+count);
|
||||
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public Map<String, ResourceComparison> getCompares() {
|
||||
return compares;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -113,6 +113,10 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
assert(right != null);
|
||||
assert(left.path().equals(right.path()));
|
||||
|
||||
if (session.isDebug()) {
|
||||
System.out.println("Compare elements at "+path);
|
||||
}
|
||||
|
||||
// not allowed to be different:
|
||||
ruleEqual(comp, res, left.current().getDefaultValue(), right.current().getDefaultValue(), "defaultValue", path);
|
||||
ruleEqual(comp, res, left.current().getMeaningWhenMissingElement(), right.current().getMeaningWhenMissingElement(), "meaningWhenMissing", path);
|
||||
|
@ -256,7 +260,7 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
matchR.add(r);
|
||||
StructuralMatch<ElementDefinition> sm = new StructuralMatch<ElementDefinition>(l.current(), r.current());
|
||||
res.getChildren().add(sm);
|
||||
compareElements(comp, sm, l.path(), null, left, right);
|
||||
compareElements(comp, sm, l.path(), null, l, r);
|
||||
}
|
||||
}
|
||||
for (DefinitionNavigator r : rc) {
|
||||
|
@ -332,7 +336,6 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
return "left: "+left+"; right: "+right;
|
||||
}
|
||||
|
||||
|
||||
private List<Coding> mergeCodings(List<Coding> left, List<Coding> right) {
|
||||
List<Coding> result = new ArrayList<Coding>();
|
||||
result.addAll(left);
|
||||
|
@ -347,7 +350,6 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
private List<StringType> mergeStrings(List<StringType> left, List<StringType> right) {
|
||||
List<StringType> result = new ArrayList<StringType>();
|
||||
result.addAll(left);
|
||||
|
@ -434,7 +436,6 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
return Integer.toString(defn.current().getMin())+".."+defn.current().getMax();
|
||||
}
|
||||
|
||||
|
||||
private Collection<? extends TypeRefComponent> unionTypes(ProfileComparison comp, StructuralMatch<ElementDefinition> res, String path, List<TypeRefComponent> left, List<TypeRefComponent> right) throws DefinitionException, IOException, FHIRFormatError {
|
||||
List<TypeRefComponent> result = new ArrayList<TypeRefComponent>();
|
||||
for (TypeRefComponent l : left)
|
||||
|
@ -514,14 +515,12 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
results.add(nw);
|
||||
}
|
||||
|
||||
|
||||
private boolean derivesFrom(StructureDefinition left, StructureDefinition right) {
|
||||
// left derives from right if it's base is the same as right
|
||||
// todo: recursive...
|
||||
return left.hasBaseDefinition() && left.getBaseDefinition().equals(right.getUrl());
|
||||
}
|
||||
|
||||
|
||||
private Collection<? extends TypeRefComponent> intersectTypes(ProfileComparison comp, StructuralMatch<ElementDefinition> res, ElementDefinition ed, String path, List<TypeRefComponent> left, List<TypeRefComponent> right) throws DefinitionException, IOException, FHIRFormatError {
|
||||
List<TypeRefComponent> result = new ArrayList<TypeRefComponent>();
|
||||
for (TypeRefComponent l : left) {
|
||||
|
@ -601,7 +600,6 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
return b.toString();
|
||||
}
|
||||
|
||||
|
||||
private boolean compareBindings(ProfileComparison comp, StructuralMatch<ElementDefinition> res, ElementDefinition subset, ElementDefinition superset, String path, ElementDefinition lDef, ElementDefinition rDef) throws FHIRFormatError, DefinitionException, IOException {
|
||||
assert(lDef.hasBinding() || rDef.hasBinding());
|
||||
if (!lDef.hasBinding()) {
|
||||
|
@ -746,8 +744,6 @@ public class ProfileComparer extends CanonicalResourceComparer {
|
|||
return sd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean isPreferredOrExample(ElementDefinitionBindingComponent binding) {
|
||||
return binding.getStrength() == BindingStrength.EXAMPLE || binding.getStrength() == BindingStrength.PREFERRED;
|
||||
}
|
||||
|
|
|
@ -231,6 +231,9 @@ public class DataRenderer {
|
|||
}
|
||||
|
||||
public String display(DataType type) {
|
||||
if (type.isEmpty())
|
||||
return "";
|
||||
|
||||
if (type instanceof Coding) {
|
||||
return displayCoding((Coding) type);
|
||||
} else if (type instanceof CodeableConcept) {
|
||||
|
@ -693,7 +696,7 @@ public class DataRenderer {
|
|||
}
|
||||
|
||||
public static String displayPeriod(Period p) {
|
||||
String s = !p.hasStart() ? "?ngen-5?" : p.getStartElement().toHumanDisplay();
|
||||
String s = !p.hasStart() ? "(?)" : p.getStartElement().toHumanDisplay();
|
||||
s = s + " --> ";
|
||||
return s + (!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
|||
if (!CACHE_VERSION.equals(v)) {
|
||||
clearCache();
|
||||
ini.setStringProperty("cache", "version", CACHE_VERSION, null);
|
||||
save = true;
|
||||
ini.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ Questionnaire_QR_Q_NotFound = The questionnaire "{0}" could not be resolved, so
|
|||
Questionnaire_Q_EnableWhen_After = The target of this enableWhen rule ({0}) comes after the question itself
|
||||
Questionnaire_Q_EnableWhen_IsInner = Questions with an enableWhen cannot refer to an inner question for it''s enableWhen condition
|
||||
Questionnaire_Q_EnableWhen_NoLink = Questions with an enableWhen must have a value for the question link
|
||||
Questionnaire_Q_EnableWhen_NoTarget = Unable to find target "{0}" for this question enableWhen
|
||||
Questionnaire_Q_EnableWhen_NoTarget = Unable to find an item with the linkId "{0}" which is referenced in the enableWhen for "{1}"
|
||||
Questionnaire_Q_EnableWhen_Self = Target for this question enableWhen can''t reference itself
|
||||
Reference_REF_Aggregation = Reference is {0} which isn''t supported by the specified aggregation mode(s) for the reference
|
||||
Reference_REF_BadTargetType = Invalid Resource target type. Found {0}, but expected one of ({1})
|
||||
|
|
|
@ -95,7 +95,7 @@ public class QuestionnaireValidator extends BaseValidator {
|
|||
Element tgt = getQuestionById(item, ql);
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), tgt == null, I18nConstants.QUESTIONNAIRE_Q_ENABLEWHEN_ISINNER)) {
|
||||
tgt = getQuestionById(questionnaire, ql);
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), tgt != null, I18nConstants.QUESTIONNAIRE_Q_ENABLEWHEN_NOTARGET, ql)) {
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), tgt != null, I18nConstants.QUESTIONNAIRE_Q_ENABLEWHEN_NOTARGET, ql, item.getChildValue("linkId"))) {
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), tgt != item, I18nConstants.QUESTIONNAIRE_Q_ENABLEWHEN_SELF)) {
|
||||
if (!isBefore(item, tgt, parents)) {
|
||||
warning(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_Q_ENABLEWHEN_AFTER, ql);
|
||||
|
|
Loading…
Reference in New Issue