use of org.hl7.fhir.r4.model.RelatedArtifact in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveTask.
private Task resolveTask(ActivityDefinition activityDefinition, String patientId) {
Task task = new Task();
task.setStatus(Task.TaskStatus.DRAFT);
task.setIntent(Task.TaskIntent.PROPOSAL);
task.setFor(new Reference(patientId));
Task.ParameterComponent input = new Task.ParameterComponent();
if (activityDefinition.hasCode()) {
task.setCode(activityDefinition.getCode());
input.setType(activityDefinition.getCode());
}
// Extension defined by CPG-on-FHIR for Questionnaire canonical URI
Extension collectsWith = activityDefinition.getExtensionByUrl("http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-collectWith");
if (collectsWith != null && collectsWith.getValueAsPrimitive().toString() != null) {
CanonicalType uri = new CanonicalType(collectsWith.getValueAsPrimitive().toString());
input.setValue(uri);
}
if (activityDefinition.hasRelatedArtifact()) {
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
if (artifact.hasUrl()) {
Attachment attachment = new Attachment().setUrl(artifact.getUrl());
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
input.setValue(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
}
// TODO - other relatedArtifact types
}
}
// If input has been populated, then add it to the Task.
if (input.getType() != null || input.getValue() != null) {
task.addInput(input);
}
return task;
}
use of org.hl7.fhir.r4.model.RelatedArtifact in project cqf-ruler by DBCG.
the class Session method resolveCdsHooksPlanDefinition.
// For library use
public CarePlan resolveCdsHooksPlanDefinition(Context context, PlanDefinition planDefinition, String patientId, RequestDetails theRequest) {
CarePlanBuilder carePlanBuilder = new CarePlanBuilder();
RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
// links
if (planDefinition.hasRelatedArtifact()) {
List<Extension> extensions = new ArrayList<>();
for (RelatedArtifact relatedArtifact : planDefinition.getRelatedArtifact()) {
AttachmentBuilder attachmentBuilder = new AttachmentBuilder();
ExtensionBuilder extensionBuilder = new ExtensionBuilder();
if (relatedArtifact.hasDisplay()) {
// label
attachmentBuilder.buildTitle(relatedArtifact.getDisplay());
}
if (relatedArtifact.hasUrl()) {
// url
attachmentBuilder.buildUrl(relatedArtifact.getUrl());
}
if (relatedArtifact.hasExtension()) {
// type
attachmentBuilder.buildExtension(relatedArtifact.getExtension());
}
extensionBuilder.buildUrl("http://example.org");
extensionBuilder.buildValue(attachmentBuilder.build());
extensions.add(extensionBuilder.build());
}
requestGroupBuilder.buildExtension(extensions);
}
resolveActions(planDefinition.getAction(), context, patientId, requestGroupBuilder, new ArrayList<>(), theRequest);
CarePlanActivityBuilder carePlanActivityBuilder = new CarePlanActivityBuilder();
carePlanActivityBuilder.buildReferenceTarget(requestGroupBuilder.build());
carePlanBuilder.buildActivity(carePlanActivityBuilder.build());
return carePlanBuilder.build();
}
use of org.hl7.fhir.r4.model.RelatedArtifact in project cqf-ruler by DBCG.
the class STU3CarePlanToCdsCard method convert.
private static List<CdsCard> convert(RequestGroup requestGroup) {
List<CdsCard> cards = new ArrayList<>();
// links
List<CdsCard.Links> links = new ArrayList<>();
if (requestGroup.hasExtension()) {
for (Extension extension : requestGroup.getExtension()) {
CdsCard.Links link = new CdsCard.Links();
if (extension.getValue() instanceof Attachment) {
Attachment attachment = (Attachment) extension.getValue();
if (attachment.hasUrl()) {
link.setUrl(attachment.getUrl());
}
if (attachment.hasTitle()) {
link.setLabel(attachment.getTitle());
}
if (attachment.hasExtension()) {
link.setType(attachment.getExtensionFirstRep().getValue().primitiveValue());
}
} else {
throw new RuntimeException("Invalid link extension type: " + extension.getValue().fhirType());
}
links.add(link);
}
}
if (requestGroup.hasAction()) {
for (RequestGroup.RequestGroupActionComponent action : requestGroup.getAction()) {
IParser jsonParser = FhirContext.forCached(FhirVersionEnum.DSTU3).newJsonParser().setPrettyPrint(true);
CdsCard card = new CdsCard(jsonParser);
// basic
if (action.hasTitle()) {
card.setSummary(action.getTitle());
}
if (action.hasDescription()) {
card.setDetail(action.getDescription());
}
if (action.hasExtension()) {
card.setIndicator(action.getExtensionFirstRep().getValue().toString());
}
// source
if (action.hasDocumentation()) {
// Assuming first related artifact has everything
RelatedArtifact documentation = action.getDocumentationFirstRep();
CdsCard.Source source = new CdsCard.Source();
if (documentation.hasDisplay()) {
source.setLabel(documentation.getDisplay());
}
if (documentation.hasUrl()) {
source.setUrl(documentation.getUrl());
}
if (documentation.hasDocument() && documentation.getDocument().hasUrl()) {
source.setIcon(documentation.getDocument().getUrl());
}
card.setSource(source);
}
if (action.hasSelectionBehavior()) {
card.setSelectionBehavior(action.getSelectionBehavior().toCode());
}
// suggestions
// TODO - uuid
boolean hasSuggestions = false;
CdsCard.Suggestions suggestions = new CdsCard.Suggestions();
CdsCard.Suggestions.Action actions = new CdsCard.Suggestions.Action();
if (action.hasLabel()) {
suggestions.setLabel(action.getLabel());
hasSuggestions = true;
if (action.hasDescription()) {
actions.setDescription(action.getDescription());
}
if (action.hasType() && !action.getType().getCode().equals("fire-event")) {
String code = action.getType().getCode();
actions.setType(CdsCard.Suggestions.Action.ActionType.valueOf(code.equals("remove") ? "delete" : code));
}
if (action.hasResource()) {
if (actions.getType().name().equalsIgnoreCase("create")) {
action.getResourceTarget().setId((String) null);
}
actions.setResource(action.getResourceTarget());
}
}
if (hasSuggestions) {
suggestions.addAction(actions);
card.addSuggestion(suggestions);
}
if (!links.isEmpty()) {
card.setLinks(links);
}
cards.add(card);
}
}
return cards;
}
use of org.hl7.fhir.r4.model.RelatedArtifact in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainFHIRLibrariesWithDependencies.
@Test
public void testMainFHIRLibrariesWithDependencies() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
mockFhirResourceRetrieval(patient);
Library root = getLibrary("Breast-Cancer-Screening", DEFAULT_RESOURCE_VERSION, "cql/includes/Breast-Cancer-Screening.cql");
Library helpers = getLibrary("FHIRHelpers", "4.0.0", "cql/fhir-helpers/FHIRHelpers.cql", "text/cql", "cql/fhir-helpers/FHIRHelpers.xml", "application/elm+json");
RelatedArtifact related = new RelatedArtifact();
related.setType(RelatedArtifactType.DEPENDSON);
related.setResource("/Library/" + helpers.getId());
root.addRelatedArtifact(related);
mockFhirResourceRetrieval(root);
mockFhirSingletonBundleRetrieval(helpers);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", root.getId(), "-l", root.getName(), "-v", root.getVersion(), "-c", patient.getId(), "-s", "CQL" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
String[] lines = output.split("\r?\n");
assertEquals(output, 12, lines.length);
System.out.println(output);
verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_format=json")));
} finally {
tmpFile.delete();
}
}
use of org.hl7.fhir.r4.model.RelatedArtifact in project quality-measure-and-cohort-service by Alvearie.
the class R4LibraryDependencyGatherer method recurse.
private List<Library> recurse(Library library, Set<String> loadedCanonicalUrls) {
String canonicalUrl = CanonicalHelper.toCanonicalUrl(library.getUrl(), library.getVersion());
if (loadedCanonicalUrls.contains(canonicalUrl)) {
return Collections.emptyList();
}
List<Library> retVal = new ArrayList<>();
retVal.add(library);
loadedCanonicalUrls.add(canonicalUrl);
if (library.hasRelatedArtifact()) {
for (RelatedArtifact related : library.getRelatedArtifact()) {
if (related.hasType() && related.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON) && related.hasResource()) {
String relatedIdentifier = related.getResource();
Library relatedLibrary = resolveLibrary(relatedIdentifier);
if (relatedLibrary != null) {
retVal.addAll(recurse(relatedLibrary, loadedCanonicalUrls));
}
}
}
}
return retVal;
}
Aggregations