use of org.hl7.fhir.r4b.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project org.hl7.fhir.core by hapifhir.
the class CapabilityStatementComparer method compareProfiles.
private void compareProfiles(String path, StructuralMatch<Element> combined, CanonicalType left, CanonicalType right, CapabilityStatementComparison res, CapabilityStatementRestResourceComponent union, CapabilityStatementRestResourceComponent intersection) {
if (!left.hasValue() && !right.hasValue()) {
// nothing in this case
} else if (!left.hasValue()) {
// the intersection is anything in right. The union is everything (or nothing, in this case)
intersection.setProfileElement(right.copy());
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.WARNING, "Added this profile", path), right).setName("profile"));
} else if (!right.hasValue()) {
// the intersection is anything in right. The union is everything (or nothing, in this case)
intersection.setProfileElement(left.copy());
combined.getChildren().add(new StructuralMatch<Element>(left, vmI(IssueSeverity.WARNING, "Removed this profile", path)).setName("profile"));
} else {
// profiles on both sides...
StructureDefinition sdLeft = session.getContextLeft().fetchResource(StructureDefinition.class, left.getValue());
StructureDefinition sdRight = session.getContextRight().fetchResource(StructureDefinition.class, right.getValue());
if (sdLeft == null && sdRight == null) {
combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.ERROR, "Cannot compare profiles because neither is known", path)).setName("profile"));
} else if (sdLeft == null) {
combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.ERROR, "Cannot compare profiles because '" + left.getValue() + "' is not known", path)).setName("profile"));
} else if (sdRight == null) {
combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.ERROR, "Cannot compare profiles because '" + right.getValue() + "' is not known", path)).setName("profile"));
} else if (sdLeft.getUrl().equals(sdRight.getUrl())) {
intersection.setProfileElement(left.copy());
union.setProfileElement(left.copy());
combined.getChildren().add(new StructuralMatch<Element>(left, right).setName("profile"));
} else if (profileInherits(sdLeft, sdRight, session.getContextLeft())) {
// if left inherits from right:
intersection.setProfileElement(left.copy());
union.setProfileElement(right.copy());
combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.WARNING, "Changed this profile to a broader profile", path)).setName("profile"));
} else if (profileInherits(sdRight, sdLeft, session.getContextRight())) {
intersection.setProfileElement(right.copy());
union.setProfileElement(left.copy());
combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.WARNING, "Changed this profile to a narrower one", path)).setName("profile"));
} else {
combined.getChildren().add(new StructuralMatch<Element>(left, right, vmI(IssueSeverity.WARNING, "Different", path)).setName("profile"));
throw new Error("Not done yet");
}
}
}
use of org.hl7.fhir.r4b.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project org.hl7.fhir.core by hapifhir.
the class CapabilityStatementComparer method intersectRestResource.
private CapabilityStatementRestResourceComponent intersectRestResource(CapabilityStatementRestResourceComponent l, CapabilityStatementRestResourceComponent r) {
CapabilityStatementRestResourceComponent res = new CapabilityStatementRestResourceComponent();
res.setType(l.getType());
// todo: compare profiles, not just copy
if (l.hasProfile() && l.getProfile().equals(r.getProfile())) {
res.setProfile(l.getProfile());
}
if (l.hasDocumentation() && l.getDocumentation().equals(r.getDocumentation())) {
res.setDocumentation(l.getDocumentation());
}
return res;
}
use of org.hl7.fhir.r4b.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project org.hl7.fhir.core by hapifhir.
the class OpenApiGenerator method generateSearch.
private void generateSearch(CapabilityStatementRestResourceComponent r) {
OperationWriter op = makePathResType(r).operation("get");
op.summary("Search all resources of type " + r.getType() + " based on a set of criteria");
op.operationId("search" + r.getType());
opOutcome(op.responses().defaultResponse());
ResponseObjectWriter resp = op.responses().httpResponse("200");
resp.description("the resource being returned");
if (isJson())
resp.content("application/fhir+json").schemaRef(specRef() + "/fhir.schema.json#/definitions/Bundle");
if (isXml())
resp.content("application/fhir+xml").schemaRef(specRef() + "/Bundle.xsd");
// todo: how do we know that these apply?
op.paramRef("#/components/parameters/format");
op.paramRef("#/components/parameters/pretty");
op.paramRef("#/components/parameters/summary");
op.paramRef("#/components/parameters/elements");
Set<String> set = new HashSet<>();
for (CapabilityStatementRestResourceSearchParamComponent spc : r.getSearchParam()) {
if (!set.contains(spc.getName())) {
set.add(spc.getName());
ParameterWriter p = op.parameter(spc.getName());
p.in(ParameterLocation.query).description(spc.getDocumentation());
p.schema().type(getSchemaType(spc.getType()));
if (spc.hasDefinition()) {
SearchParameter sp = context.fetchResource(SearchParameter.class, spc.getDefinition());
if (sp != null) {
p.description(sp.getDescription());
}
}
}
}
}
use of org.hl7.fhir.r4b.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project org.hl7.fhir.core by hapifhir.
the class CapabilityStatementComparer method compareRestResourceInteractions.
private void compareRestResourceInteractions(StructuralMatch<Element> combined, CapabilityStatementRestResourceComponent left, CapabilityStatementRestResourceComponent right, String path, CapabilityStatementComparison res, CapabilityStatementRestResourceComponent union, CapabilityStatementRestResourceComponent intersection) {
List<ResourceInteractionComponent> matchR = new ArrayList<>();
for (ResourceInteractionComponent l : left.getInteraction()) {
ResourceInteractionComponent r = findInList(right.getInteraction(), l);
if (r == null) {
union.getInteraction().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this item", path)));
} else {
matchR.add(r);
ResourceInteractionComponent cdM = mergeRestResourceInteractions(l, r);
ResourceInteractionComponent cdI = intersectRestResourceInteractions(l, r);
union.getInteraction().add(cdM);
intersection.getInteraction().add(cdI);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
compareStrings(path, sm.getMessages(), l.getDocumentation(), r.getDocumentation(), "documentation", IssueSeverity.INFORMATION, res);
compareExpectations(sm, l, r, path, res, union, intersection);
combined.getChildren().add(sm);
}
}
for (ResourceInteractionComponent r : right.getInteraction()) {
if (!matchR.contains(r)) {
union.getInteraction().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this concept", path), r));
}
}
}
use of org.hl7.fhir.r4b.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project org.hl7.fhir.core by hapifhir.
the class CapabilityStatementComparer method intersectRestResource.
private CapabilityStatementRestResourceComponent intersectRestResource(CapabilityStatementRestResourceComponent l, CapabilityStatementRestResourceComponent r) {
CapabilityStatementRestResourceComponent res = new CapabilityStatementRestResourceComponent();
res.setType(l.getType());
// todo: compare profiles, not just copy
if (l.hasProfile() && l.getProfile().equals(r.getProfile())) {
res.setProfile(l.getProfile());
}
if (l.hasDocumentation() && l.getDocumentation().equals(r.getDocumentation())) {
res.setDocumentation(l.getDocumentation());
}
return res;
}
Aggregations