use of org.hl7.fhir.r4.model.ActivityDefinition in project kindling by HL7.
the class SpreadSheetReloader method parseType.
private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
ed.getType().clear();
ed.setContentReferenceElement(null);
if (ed.getPath().equals("Resource.id")) {
ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
} else {
if (Utilities.noString(value)) {
if (ed.getPath().contains(".")) {
ed.addType().setCode("BackboneElement");
}
} else if (value.startsWith("#")) {
ed.setContentReference(value);
} else {
List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
for (TypeRef tr : tl) {
TypeRefComponent t = ed.addType().setCode(tr.getName());
if ("SimpleQuantity".equals(t.getCode())) {
t.setCode("Quantity");
t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
}
for (String p : tr.getParams()) {
if (p.equals("Definition")) {
t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
} else {
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
}
if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
}
}
}
}
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project kindling by HL7.
the class ResourceParser method parseED.
private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
ed.setMinCardinality(focus.getMin());
ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
ed.setIsModifier(focus.getIsModifier());
ed.setModifierReason(focus.getIsModifierReason());
ed.setMustSupport(focus.getMustSupport());
ed.setSummaryItem(focus.getIsSummary());
ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
}
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
if (svg.contains("w=")) {
ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
svg = svg.substring(0, svg.indexOf(";"));
}
ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
}
ed.setName(tail(focus.getPath()));
ed.setShortDefn(focus.getShort());
ed.setDefinition(focus.getDefinition());
ed.setRequirements(focus.getRequirements());
ed.setComments(focus.getComment());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
}
if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
}
for (StringType t : focus.getAlias()) {
ed.getAliases().add(t.getValue());
}
if (focus.hasMaxLength()) {
ed.setMaxLength(Integer.toString(focus.getMaxLength()));
}
ed.setExample(focus.getExampleFirstRep().getValue());
ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
}
ed.setOrderMeaning(focus.getOrderMeaning());
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
}
if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
}
for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
Invariant inv = new Invariant();
inv.setContext(focus.getPath());
inv.setEnglish(cst.getHuman());
if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
}
inv.setXpath(cst.getXpath());
inv.setId(cst.getKey());
if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
}
inv.setSeverity(cst.getSeverity().toCode());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
inv.setSeverity("best-practice");
}
if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
}
inv.setRequirements(cst.getRequirements());
inv.setExpression(cst.getExpression());
if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
}
ed.getInvariants().put(inv.getId(), inv);
invariants.put(inv.getId(), inv);
}
for (IdType cnd : focus.getCondition()) {
Invariant inv = invariants.get(cnd.primitiveValue());
if (inv == null) {
System.out.println("Unable to find invariant " + cnd.primitiveValue());
} else {
ed.getStatedInvariants().add(inv);
}
}
for (ElementDefinitionMappingComponent map : focus.getMapping()) {
String uri = getMappingUri(sd, map.getIdentity());
if ("http://hl7.org/fhir/fivews".equals(uri)) {
ed.setW5(reverseW5(map.getMap()));
} else {
ed.getMappings().put(uri, map.getMap());
}
}
if (focus.hasContentReference()) {
ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
} else {
for (TypeRefComponent tr : focus.getType()) {
if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
TypeRef t = new TypeRef();
ed.getTypes().add(t);
if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
} else {
t.setName(tr.getCode());
}
if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
}
for (CanonicalType u : tr.getProfile()) {
t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
}
for (CanonicalType u : tr.getTargetProfile()) {
String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
if ("Resource".equals(s)) {
t.getParams().add("Any");
} else {
t.getParams().add(s);
}
}
if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
t.setName("SimpleQuantity");
t.setProfile(null);
}
if ("Resource".equals(t.getProfile())) {
t.setProfile("Any");
}
if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
t.getParams().clear();
t.getParams().add("Definition");
}
}
}
if (ed.getTypes().size() == STAR_TYPES_COUNT) {
ed.getTypes().clear();
ed.getTypes().add(new TypeRef("*"));
}
}
String name = parentName + Utilities.capitalize(ed.getName());
if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
ed.setDeclaredTypeName(ed.getStatedType());
} else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
ed.setDeclaredTypeName(name + "Component");
}
if (focus.hasBinding()) {
ed.setBinding(parseBinding(focus.getBinding()));
}
for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
ElementDefn c = new ElementDefn();
ed.getElements().add(c);
parseED(pu, c, child, sd, name);
}
// todo:
// private ElementDefinition derivation;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class Session method resolveActions.
private void resolveActions(List<PlanDefinition.PlanDefinitionActionComponent> actions, Context context, String patientId, RequestGroupBuilder requestGroupBuilder, List<RequestGroup.RequestGroupActionComponent> actionComponents, RequestDetails theRequest) {
for (PlanDefinition.PlanDefinitionActionComponent action : actions) {
boolean conditionsMet = true;
for (PlanDefinition.PlanDefinitionActionConditionComponent condition : action.getCondition()) {
if (condition.getKind() == PlanDefinition.ActionConditionKind.APPLICABILITY) {
if (!condition.hasExpression()) {
continue;
}
if (condition.hasExpression() && !condition.getExpression().hasExpression()) {
continue;
}
Object result = context.resolveExpressionRef(condition.getExpression().getExpression()).getExpression().evaluate(context);
if (!(result instanceof Boolean)) {
continue;
}
if (!(Boolean) result) {
conditionsMet = false;
}
}
if (conditionsMet) {
RequestGroupActionBuilder actionBuilder = new RequestGroupActionBuilder();
if (action.hasTitle()) {
actionBuilder.buildTitle(action.getTitle());
}
if (action.hasDescription()) {
actionBuilder.buildDescripition(action.getDescription());
}
// source
if (action.hasDocumentation()) {
RelatedArtifact artifact = action.getDocumentationFirstRep();
RelatedArtifactBuilder artifactBuilder = new RelatedArtifactBuilder();
if (artifact.hasDisplay()) {
artifactBuilder.buildDisplay(artifact.getDisplay());
}
if (artifact.hasUrl()) {
artifactBuilder.buildUrl(artifact.getUrl());
}
if (artifact.hasDocument() && artifact.getDocument().hasUrl()) {
AttachmentBuilder attachmentBuilder = new AttachmentBuilder();
attachmentBuilder.buildUrl(artifact.getDocument().getUrl());
artifactBuilder.buildDocument(attachmentBuilder.build());
}
actionBuilder.buildDocumentation(Collections.singletonList(artifactBuilder.build()));
}
// TODO - uuid
if (action.hasPrefix()) {
actionBuilder.buildPrefix(action.getPrefix());
}
if (action.hasType()) {
actionBuilder.buildType(action.getType());
}
if (action.hasDefinition()) {
if (action.getDefinitionCanonicalType().getValue().contains("ActivityDefinition")) {
ActivityDefinition activityDefinition = this.activityDefinitionDao.read(new IdType("ActivityDefinition", action.getDefinitionCanonicalType().getId()));
if (activityDefinition.hasDescription()) {
actionBuilder.buildDescripition(activityDefinition.getDescription());
}
try {
this.activityDefinitionApplyProvider.apply(theRequest, new IdType(action.getDefinitionCanonicalType().getId()), patientId, null, null, null, null, null, null, null, null).setId(UUID.randomUUID().toString());
} catch (FHIRException e) {
throw new RuntimeException("Error applying ActivityDefinition " + e.getMessage());
}
Parameters inParams = new Parameters();
inParams.addParameter().setName("patient").setValue(new StringType(patientId));
Parameters outParams = this.fhirContext.newRestfulGenericClient(theRequest.getFhirServerBase()).operation().onInstance(new IdDt("ActivityDefinition", action.getDefinition().getId())).named("$apply").withParameters(inParams).useHttpGet().execute();
List<Parameters.ParametersParameterComponent> response = outParams.getParameter();
Resource resource = response.get(0).getResource().setId(UUID.randomUUID().toString());
actionBuilder.buildResourceTarget(resource);
actionBuilder.buildResource(new ReferenceBuilder().buildReference(resource.getId()).build());
}
}
// on here...
if (action.hasDynamicValue()) {
for (PlanDefinition.PlanDefinitionActionDynamicValueComponent dynamicValue : action.getDynamicValue()) {
if (dynamicValue.hasPath() && dynamicValue.hasExpression()) {
if (dynamicValue.getPath().endsWith("title")) {
// summary
String title = (String) context.resolveExpressionRef(dynamicValue.getExpression().getExpression()).evaluate(context);
actionBuilder.buildTitle(title);
} else if (dynamicValue.getPath().endsWith("description")) {
// detail
String description = (String) context.resolveExpressionRef(dynamicValue.getExpression().getExpression()).evaluate(context);
actionBuilder.buildDescripition(description);
} else if (dynamicValue.getPath().endsWith("extension")) {
// indicator
String extension = (String) context.resolveExpressionRef(dynamicValue.getExpression().getExpression()).evaluate(context);
actionBuilder.buildExtension(extension);
}
}
}
}
if (!actionBuilder.build().isEmpty()) {
actionComponents.add(actionBuilder.build());
}
if (action.hasAction()) {
resolveActions(action.getAction(), context, patientId, requestGroupBuilder, actionComponents, theRequest);
}
}
}
}
requestGroupBuilder.buildAction(new ArrayList<>(actionComponents));
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class Session method resolveDefinition.
private Resource resolveDefinition(RequestDetails theRequest, Session session, PlanDefinition.PlanDefinitionActionComponent action) {
Resource result = null;
if (action.hasDefinition()) {
logger.debug("Resolving definition: {}", action.getDefinition().getReference());
Reference definition = action.getDefinition();
if (definition.getId().contains(session.getPlanDefinition().fhirType())) {
IdType id = new IdType(definition.getId());
CarePlan plan;
try {
plan = applyPlanDefinition(theRequest, id, session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), session.getUserType(), session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
if (plan.getId() == null) {
plan.setId(UUID.randomUUID().toString());
}
// Add an action to the request group which points to this CarePlan
session.getRequestGroupBuilder().buildContained(plan).addAction(new RequestGroupActionBuilder().buildResource(new Reference("#" + plan.getId())).build());
for (Reference r : plan.getDefinition()) {
session.getCarePlanBuilder().buildDefinition(r);
}
result = plan;
} catch (IOException e) {
e.printStackTrace();
logger.error("nested plan failed");
}
} else {
try {
if (action.getDefinition().getReferenceElement().getIdPart().startsWith("#")) {
result = this.activityDefinitionApplyProvider.resolveActivityDefinition((ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinition().getReferenceElement().getIdPart()), session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest);
} else {
result = this.activityDefinitionApplyProvider.apply(theRequest, new IdType(action.getDefinition().getReferenceElement().getIdPart()), session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), null, session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
}
if (result.getId() == null) {
logger.warn("ActivityDefinition {} returned resource with no id, setting one", action.getDefinition().getReferenceElement().getIdPart());
result.setId(UUID.randomUUID().toString());
}
session.getRequestGroupBuilder().buildContained(result).addAction(new RequestGroupActionBuilder().buildResource(new Reference("#" + result.getId())).build());
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition {} could not be applied and threw exception {}", action.getDefinition(), e.toString());
}
}
}
return result;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProviderIT method testActivityDefinitionApply.
@Test
public void testActivityDefinitionApply() throws Exception {
DomainResource activityDefinition = (DomainResource) activityDefinitions.get("opioidcds-risk-assessment-request");
// Patient First
Map<String, IBaseResource> resources = uploadTests("test/activitydefinition/Patient");
IBaseResource patient = resources.get("ExamplePatient");
Resource applyResult = activityDefinitionApplyProvider.apply(new SystemRequestDetails(), activityDefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
assertTrue(applyResult instanceof ProcedureRequest);
assertEquals("454281000124100", ((ProcedureRequest) applyResult).getCode().getCoding().get(0).getCode());
}
Aggregations