use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class CanonicalResourceComparer method compareCodeableConceptList.
protected void compareCodeableConceptList(String name, List<CodeableConcept> left, List<CodeableConcept> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CodeableConcept> union, List<CodeableConcept> intersection) {
List<CodeableConcept> matchR = new ArrayList<>();
StructuralMatch<String> combined = new StructuralMatch<String>();
for (CodeableConcept l : left) {
CodeableConcept r = findCodeableConceptInList(right, l);
if (r == null) {
union.add(l);
combined.getChildren().add(new StructuralMatch<String>(gen(l), vm(IssueSeverity.INFORMATION, "Removed the item '" + gen(l) + "'", fhirType() + "." + name, res.getMessages())));
} else {
matchR.add(r);
union.add(r);
intersection.add(r);
StructuralMatch<String> sm = new StructuralMatch<String>(gen(l), gen(r));
combined.getChildren().add(sm);
}
}
for (CodeableConcept r : right) {
if (!matchR.contains(r)) {
union.add(r);
combined.getChildren().add(new StructuralMatch<String>(vm(IssueSeverity.INFORMATION, "Added the item '" + gen(r) + "'", fhirType() + "." + name, res.getMessages()), gen(r)));
}
}
comp.put(name, combined);
}
use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class CanonicalResourceComparer method compareCanonicalList.
protected void compareCanonicalList(String name, List<CanonicalType> left, List<CanonicalType> right, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res, List<CanonicalType> union, List<CanonicalType> intersection) {
List<CanonicalType> matchR = new ArrayList<>();
StructuralMatch<String> combined = new StructuralMatch<String>();
for (CanonicalType l : left) {
CanonicalType r = findCanonicalInList(right, l);
if (r == null) {
union.add(l);
combined.getChildren().add(new StructuralMatch<String>(l.getValue(), vm(IssueSeverity.INFORMATION, "Removed the item '" + l.getValue() + "'", fhirType() + "." + name, res.getMessages())));
} else {
matchR.add(r);
union.add(r);
intersection.add(r);
StructuralMatch<String> sm = new StructuralMatch<String>(l.getValue(), r.getValue());
combined.getChildren().add(sm);
}
}
for (CanonicalType r : right) {
if (!matchR.contains(r)) {
union.add(r);
combined.getChildren().add(new StructuralMatch<String>(vm(IssueSeverity.INFORMATION, "Added the item '" + r.getValue() + "'", fhirType() + "." + name, res.getMessages()), r.getValue()));
}
}
comp.put(name, combined);
}
use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class ComparisonSession method compare.
public ResourceComparison compare(String left, String right) throws DefinitionException, FHIRFormatError, IOException {
CanonicalResource l = (CanonicalResource) contextLeft.fetchResource(Resource.class, left);
if (l == null) {
throw new DefinitionException("Unable to resolve " + left);
}
CanonicalResource r = (CanonicalResource) contextRight.fetchResource(Resource.class, right);
if (r == null) {
throw new DefinitionException("Unable to resolve " + right);
}
return compare(l, r);
}
use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method isCorrectCanonicalType.
private boolean isCorrectCanonicalType(Resource r, CanonicalType p) {
String url = p.getValue();
String t = null;
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
if (sd != null) {
t = sd.getType();
} else if (url.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
t = url.substring("http://hl7.org/fhir/StructureDefinition/".length());
} else {
return false;
}
return Utilities.existsInList(t, "Resource", "CanonicalResource") || t.equals(r.fhirType());
}
use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpansionCache method loadCache.
private void loadCache() throws FHIRFormatError, IOException {
File[] files = new File(cacheFolder).listFiles();
for (File f : files) {
if (f.getName().endsWith(".xml")) {
final FileInputStream is = new FileInputStream(f);
try {
Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
if (r instanceof OperationOutcome) {
OperationOutcome oo = (OperationOutcome) r;
expansions.put(ToolingExtensions.getExtension(oo, VS_ID_EXT).getValue().toString(), new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
} else if (r instanceof ValueSet) {
ValueSet vs = (ValueSet) r;
if (vs.hasExpansion())
expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
else {
canonicals.put(vs.getUrl(), vs);
if (vs.hasVersion())
canonicals.put(vs.getUrl() + "|" + vs.getVersion(), vs);
}
} else if (r instanceof CanonicalResource) {
CanonicalResource md = (CanonicalResource) r;
canonicals.put(md.getUrl(), md);
if (md.hasVersion())
canonicals.put(md.getUrl() + "|" + md.getVersion(), md);
}
} finally {
IOUtils.closeQuietly(is);
}
}
}
}
Aggregations