use of org.hl7.fhir.r5.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.r5.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project pathling by aehrc.
the class ConformanceProvider method buildResources.
@Nonnull
private List<CapabilityStatementRestResourceComponent> buildResources() {
final List<CapabilityStatementRestResourceComponent> resources = new ArrayList<>();
final Set<ResourceType> supported = FhirServer.supportedResourceTypes();
final Set<ResourceType> supportedResourceTypes = supported.isEmpty() ? EnumSet.noneOf(ResourceType.class) : EnumSet.copyOf(supported);
for (final ResourceType resourceType : supportedResourceTypes) {
final CapabilityStatementRestResourceComponent resource = new CapabilityStatementRestResourceComponent(new CodeType(resourceType.toCode()));
resource.setProfile(FHIR_RESOURCE_BASE + resourceType.toCode());
// Add the search operation to all resources.
final ResourceInteractionComponent search = new ResourceInteractionComponent();
search.setCode(TypeRestfulInteraction.SEARCHTYPE);
resource.getInteraction().add(search);
// Add the create and update operations to all resources.
final ResourceInteractionComponent create = new ResourceInteractionComponent();
final ResourceInteractionComponent update = new ResourceInteractionComponent();
create.setCode(TypeRestfulInteraction.CREATE);
update.setCode(TypeRestfulInteraction.UPDATE);
resource.getInteraction().add(create);
resource.getInteraction().add(update);
// Add the `aggregate` operation to all resources.
final CanonicalType aggregateOperationUri = new CanonicalType(getOperationUri("aggregate"));
final CapabilityStatementRestResourceOperationComponent aggregateOperation = new CapabilityStatementRestResourceOperationComponent(new StringType("aggregate"), aggregateOperationUri);
resource.addOperation(aggregateOperation);
// Add the `fhirPath` search parameter to all resources.
final CapabilityStatementRestResourceOperationComponent searchOperation = new CapabilityStatementRestResourceOperationComponent();
searchOperation.setName("fhirPath");
searchOperation.setDefinition(getOperationUri("search"));
resource.addOperation(searchOperation);
resources.add(resource);
}
// Add the read operation to the OperationDefinition resource.
final String opDefCode = ResourceType.OPERATIONDEFINITION.toCode();
final CapabilityStatementRestResourceComponent opDefResource = new CapabilityStatementRestResourceComponent(new CodeType(opDefCode));
opDefResource.setProfile(FHIR_RESOURCE_BASE + opDefCode);
final ResourceInteractionComponent readInteraction = new ResourceInteractionComponent();
readInteraction.setCode(TypeRestfulInteraction.READ);
opDefResource.addInteraction(readInteraction);
resources.add(opDefResource);
return resources;
}
use of org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project beneficiary-fhir-data by CMSgov.
the class ServerCapabilityStatementIT method getCapabilities.
/**
* Verifies that the server responds as expected to the <code>GET [base]/_metadata</code>
* endpoint.
*/
@Test
public void getCapabilities() {
IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
CapabilityStatement capabilities = fhirClient.capabilities().ofType(CapabilityStatement.class).execute();
assertNotNull(capabilities);
// Verify that our custom server metadata is correct.
assertEquals(V1Server.CAPABILITIES_PUBLISHER, capabilities.getPublisher());
assertEquals(V1Server.CAPABILITIES_SERVER_NAME, capabilities.getSoftware().getName());
assertEquals("gov.cms.bfd:bfd-server-war", capabilities.getImplementation().getDescription());
assertNotEquals(null, capabilities.getSoftware().getVersion());
assertNotEquals("", capabilities.getSoftware().getVersion());
// The default for this field is HAPI's version but we don't use that.
assertNotEquals(VersionUtil.getVersion(), capabilities.getSoftware().getVersion());
assertEquals(1, capabilities.getRest().size());
CapabilityStatementRestComponent restCapabilities = capabilities.getRestFirstRep();
assertEquals(RestfulCapabilityMode.SERVER, restCapabilities.getMode());
// Verify that Patient resource support looks like expected.
CapabilityStatementRestResourceComponent patientCapabilities = restCapabilities.getResource().stream().filter(r -> r.getType().equals(Patient.class.getSimpleName())).findAny().get();
assertTrue(patientCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.READ).findAny().isPresent());
assertTrue(patientCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.SEARCHTYPE).findAny().isPresent());
assertFalse(patientCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.CREATE).findAny().isPresent());
// Verify that Coverage resource support looks like expected.
CapabilityStatementRestResourceComponent coverageCapabilities = restCapabilities.getResource().stream().filter(r -> r.getType().equals(Coverage.class.getSimpleName())).findAny().get();
assertTrue(coverageCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.READ).findAny().isPresent());
assertTrue(coverageCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.SEARCHTYPE).findAny().isPresent());
// Verify that EOB resource support looks like expected.
CapabilityStatementRestResourceComponent eobCapabilities = restCapabilities.getResource().stream().filter(r -> r.getType().equals(ExplanationOfBenefit.class.getSimpleName())).findAny().get();
assertTrue(eobCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.READ).findAny().isPresent());
assertTrue(eobCapabilities.getInteraction().stream().filter(i -> i.getCode() == TypeRestfulInteraction.SEARCHTYPE).findAny().isPresent());
// Spot check that an arbitrary unsupported resource isn't listed.
assertFalse(restCapabilities.getResource().stream().filter(r -> r.getType().equals(DiagnosticReport.class.getSimpleName())).findAny().isPresent());
}
use of org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project kindling by HL7.
the class Publisher method genConfInteraction.
private void genConfInteraction(CapabilityStatement conf, CapabilityStatementRestResourceComponent res, TypeRestfulInteraction op, String doco) {
ResourceInteractionComponent t = new ResourceInteractionComponent();
t.setCode(op);
t.setDocumentation(doco);
res.getInteraction().add(t);
}
use of org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResourceComponent in project kindling by HL7.
the class Publisher method generateConformanceStatement.
private void generateConformanceStatement(boolean full, String name, boolean register) throws Exception {
pgen = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc());
CapabilityStatement cpbs = new CapabilityStatement();
cpbs.setId(FormatUtilities.makeId(name));
cpbs.setUrl("http://hl7.org/fhir/CapabilityStatement/" + name);
cpbs.setVersion(page.getVersion().toCode());
cpbs.setName("Base FHIR Capability Statement " + (full ? "(Full)" : "(Empty)"));
cpbs.setStatus(PublicationStatus.DRAFT);
cpbs.setExperimental(true);
cpbs.setDate(page.getGenDate().getTime());
cpbs.setPublisher("FHIR Project Team");
cpbs.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
cpbs.setKind(CapabilityStatementKind.CAPABILITY);
cpbs.setSoftware(new CapabilityStatementSoftwareComponent());
cpbs.getSoftware().setName("Insert your software name here...");
cpbs.setFhirVersion(page.getVersion());
cpbs.getFormat().add(Factory.newCode("xml"));
cpbs.getFormat().add(Factory.newCode("json"));
CapabilityStatementRestComponent rest = new CapabilityStatement.CapabilityStatementRestComponent();
cpbs.getRest().add(rest);
rest.setMode(RestfulCapabilityMode.SERVER);
if (full) {
rest.setDocumentation("All the functionality defined in FHIR");
cpbs.setDescription("This is the base Capability Statement for FHIR. It represents a server that provides the full set of functionality defined by FHIR. It is provided to use as a template for system designers to build their own Capability Statements from");
} else {
rest.setDocumentation("An empty Capability Statement");
cpbs.setDescription("This is the base Capability Statement for FHIR. It represents a server that provides the none of the functionality defined by FHIR. It is provided to use as a template for system designers to build their own Capability Statements from. A capability statement has to contain something, so this contains a read of a Capability Statement");
}
rest.setSecurity(new CapabilityStatementRestSecurityComponent());
rest.getSecurity().setCors(true);
rest.getSecurity().addService().setText("See http://docs.smarthealthit.org/").addCoding().setSystem("http://terminology.hl7.org/CodeSystem/restful-security-service").setCode("SMART-on-FHIR").setDisplay("SMART-on-FHIR");
rest.getSecurity().setDescription("This is the Capability Statement to declare that the server supports SMART-on-FHIR. See the SMART-on-FHIR docs for the extension that would go with such a server");
if (full) {
for (String rn : page.getDefinitions().sortedResourceNames()) {
ResourceDefn rd = page.getDefinitions().getResourceByName(rn);
CapabilityStatementRestResourceComponent res = new CapabilityStatement.CapabilityStatementRestResourceComponent();
rest.getResource().add(res);
res.setType(rn);
res.setProfile("http://hl7.org/fhir/StructureDefinition/" + rn);
genConfInteraction(cpbs, res, TypeRestfulInteraction.READ, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.VREAD, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.UPDATE, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.DELETE, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.HISTORYINSTANCE, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.HISTORYTYPE, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.CREATE, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, res, TypeRestfulInteraction.SEARCHTYPE, "Implemented per the specification (or Insert other doco here)");
res.setConditionalCreate(true);
res.setConditionalUpdate(true);
res.setConditionalDelete(ConditionalDeleteStatus.MULTIPLE);
res.addReferencePolicy(ReferenceHandlingPolicy.LITERAL);
res.addReferencePolicy(ReferenceHandlingPolicy.LOGICAL);
for (SearchParameterDefn i : rd.getSearchParams().values()) {
res.getSearchParam().add(makeSearchParam(rn, i));
if (i.getType().equals(SearchType.reference))
res.getSearchInclude().add(new StringType(rn + "." + i.getCode()));
}
for (String rni : page.getDefinitions().sortedResourceNames()) {
ResourceDefn rdi = page.getDefinitions().getResourceByName(rni);
for (SearchParameterDefn ii : rdi.getSearchParams().values()) {
if (ii.getType().equals(SearchType.reference) && ii.getTargets().contains(rn))
res.getSearchRevInclude().add(new StringType(rni + "." + ii.getCode()));
}
}
}
genConfInteraction(cpbs, rest, SystemRestfulInteraction.TRANSACTION, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, rest, SystemRestfulInteraction.BATCH, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, rest, SystemRestfulInteraction.HISTORYSYSTEM, "Implemented per the specification (or Insert other doco here)");
genConfInteraction(cpbs, rest, SystemRestfulInteraction.SEARCHSYSTEM, "Implemented per the specification (or Insert other doco here)");
for (ResourceDefn rd : page.getDefinitions().getBaseResources().values()) {
for (SearchParameterDefn i : rd.getSearchParams().values()) rest.getSearchParam().add(makeSearchParam(rd.getName(), i));
rest.getSearchParam().add(makeSearchParam("something", SearchParamType.STRING, "id", "some doco"));
rest.getSearchParam().add(makeSearchParam("_list", SearchParamType.TOKEN, "Resource-list", "Retrieval of resources that are referenced by a List resource"));
rest.getSearchParam().add(makeSearchParam("_has", SearchParamType.COMPOSITE, "Resource-has", "Provides support for reverse chaining"));
rest.getSearchParam().add(makeSearchParam("_type", SearchParamType.TOKEN, "Resource-type", "Type of resource (when doing cross-resource search"));
rest.getSearchParam().add(makeSearchParam("_sort", SearchParamType.TOKEN, "Resource-source", "How to sort the resources when returning"));
rest.getSearchParam().add(makeSearchParam("_count", SearchParamType.NUMBER, "Resource-count", "How many resources to return"));
rest.getSearchParam().add(makeSearchParam("_include", SearchParamType.TOKEN, "Resource-include", "Control over returning additional resources (see spec)"));
rest.getSearchParam().add(makeSearchParam("_revinclude", SearchParamType.TOKEN, "Resource-revinclude", "Control over returning additional resources (see spec)"));
rest.getSearchParam().add(makeSearchParam("_summary", SearchParamType.TOKEN, "Resource-summary", "What kind of information to return"));
rest.getSearchParam().add(makeSearchParam("_elements", SearchParamType.STRING, "Resource-elements", "What kind of information to return"));
rest.getSearchParam().add(makeSearchParam("_contained", SearchParamType.TOKEN, "Resource-contained", "Managing search into contained resources"));
rest.getSearchParam().add(makeSearchParam("_containedType", SearchParamType.TOKEN, "Resource-containedType", "Managing search into contained resources"));
for (Operation op : rd.getOperations()) rest.addOperation().setName(op.getName()).setDefinition("http://hl7.org/fhir/OperationDefinition/" + rd.getName().toLowerCase() + "-" + op.getName());
}
for (String rn : page.getDefinitions().sortedResourceNames()) {
ResourceDefn r = page.getDefinitions().getResourceByName(rn);
for (Operation op : r.getOperations()) rest.addOperation().setName(op.getName()).setDefinition("http://hl7.org/fhir/OperationDefinition/" + r.getName().toLowerCase() + "-" + op.getName());
}
} else {
// don't add anything - the metadata operation is implicit
// CapabilityStatementRestResourceComponent res = new CapabilityStatement.CapabilityStatementRestResourceComponent();
// rest.getResource().add(res);
// res.setType("CapabilityStatement");
// genConfInteraction(cpbs, res, TypeRestfulInteraction.READ, "Read CapabilityStatement Resource");
}
if (register) {
RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
RendererFactory.factory(cpbs, lrc).render(cpbs);
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpbs);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".canonical.xml");
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpbs);
s.close();
cloneToXhtml("capabilitystatement-" + name + "", "Basic Capability Statement", true, "resource-instance:CapabilityStatement", "Capability Statement", null, wg("fhir"));
s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpbs);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".canonical.json");
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpbs);
s.close();
jsonToXhtml("capabilitystatement-" + name, "Base Capability Statement", resource2Json(cpbs), "resource-instance:CapabilityStatement", "Capability Statement", null, wg("fhir"));
s = new FileOutputStream(page.getFolders().dstDir + "capabilitystatement-" + name + ".ttl");
new RdfParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpbs);
s.close();
ttlToXhtml("capabilitystatement-" + name, "Base Capability Statement", resource2Ttl(cpbs), "resource-instance:CapabilityStatement", "Capability Statement", null, wg("fhir"));
Utilities.copyFile(new CSFile(page.getFolders().dstDir + "capabilitystatement-" + name + ".xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + "capabilitystatement-" + name + ".xml"));
}
if (buildFlags.get("all")) {
RenderingContext lrc = page.getRc().copy().setLocalPrefix("");
RendererFactory.factory(cpbs, lrc).render(cpbs);
deletefromFeed(ResourceType.CapabilityStatement, name, page.getResourceBundle());
addToResourceFeed(cpbs, page.getResourceBundle());
}
}
Aggregations