Skip to content

Commit

Permalink
Fix profile for $apply response (#343)
Browse files Browse the repository at this point in the history
* Remove CPG Strategy profile from RequestGroups and only add to instantiatesCanonical the direct PlanDefinition that is being instantiated

* fix formatting
  • Loading branch information
barhodes committed Sep 15, 2023
1 parent a8a9106 commit d06bd1a
Show file tree
Hide file tree
Showing 34 changed files with 288 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.hl7.fhir.dstu3.model.Goal;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Library;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.MetadataResource;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Parameters;
Expand Down Expand Up @@ -197,7 +196,7 @@ public IBaseResource applyPlanDefinition(PlanDefinition planDefinition) {
.setSubject(new Reference(subjectId));
requestGroup.setId(new IdType(
requestGroup.fhirType(), planDefinition.getIdElement().getIdPart()));
requestGroup.setMeta(new Meta().addProfile(Constants.CPG_STRATEGY));
// requestGroup.setMeta(new Meta().addProfile(Constants.CPG_STRATEGY));
if (encounterId != null) {
requestGroup.setContext(new Reference(encounterId));
}
Expand Down Expand Up @@ -384,7 +383,7 @@ private RequestGroupActionComponent resolveAction(
}
IBaseResource resource = null;
if (action.hasDefinition()) {
resource = resolveDefinition(planDefinition, requestGroup, action);
resource = resolveDefinition(planDefinition, action);
if (resource != null) {
applyAction(requestGroup, resource, action);
requestAction.setResource(new Reference(resource.getIdElement()));
Expand Down Expand Up @@ -439,15 +438,13 @@ private RequestGroupActionComponent createRequestAction(PlanDefinitionActionComp
}

private IBaseResource resolveDefinition(
PlanDefinition planDefinition,
RequestGroup requestGroup,
PlanDefinition.PlanDefinitionActionComponent action) {
PlanDefinition planDefinition, PlanDefinition.PlanDefinitionActionComponent action) {
logger.debug("Resolving definition {}", action.getDefinition().getReference());
var definition = new StringType(action.getDefinition().getReference());
var resourceName = resolveResourceName(definition, planDefinition);
switch (FHIRAllTypes.fromCode(requireNonNull(resourceName))) {
case PLANDEFINITION:
return applyNestedPlanDefinition(requestGroup, definition);
return applyNestedPlanDefinition(planDefinition, definition);
case ACTIVITYDEFINITION:
return applyActivityDefinition(planDefinition, definition);
case QUESTIONNAIRE:
Expand Down Expand Up @@ -517,14 +514,15 @@ private IBaseResource applyActivityDefinition(PlanDefinition planDefinition, Str
return result;
}

private IBaseResource applyNestedPlanDefinition(RequestGroup requestGroup, StringType definition) {
private IBaseResource applyNestedPlanDefinition(PlanDefinition planDefinition, StringType definition) {
RequestGroup result = null;
try {
var planDefinition = (PlanDefinition) SearchHelper.searchRepositoryByCanonical(repository, definition);
result = (RequestGroup) applyPlanDefinition(planDefinition);
for (var c : result.getDefinition()) {
requestGroup.addDefinition(c);
}
var referenceToContained = definition.getValue().startsWith("#");
var nextPlanDefinition = (PlanDefinition)
(referenceToContained
? resolveContained(planDefinition, definition.getValue())
: SearchHelper.searchRepositoryByCanonical(repository, definition));
result = (RequestGroup) applyPlanDefinition(nextPlanDefinition);
} catch (Exception e) {
var message = String.format(
"ERROR: PlanDefinition %s could not be applied and threw exception %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.hl7.fhir.r4.model.Goal.GoalLifecycleStatus;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.Meta;
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Parameters;
Expand Down Expand Up @@ -202,7 +201,7 @@ public IBaseResource applyPlanDefinition(PlanDefinition planDefinition) {
.setSubject(new Reference(subjectId));
requestGroup.setId(new IdType(
requestGroup.fhirType(), planDefinition.getIdElement().getIdPart()));
requestGroup.setMeta(new Meta().addProfile(Constants.CPG_STRATEGY));
// requestGroup.setMeta(new Meta().addProfile(Constants.CPG_STRATEGY));
if (encounterId != null) {
requestGroup.setEncounter(new Reference(encounterId));
}
Expand Down Expand Up @@ -240,7 +239,8 @@ public IBaseResource applyPlanDefinition(PlanDefinition planDefinition) {
.setUrl(Constants.PERTAINS_TO_GOAL)
.setValue(new Reference(goal.getIdElement()));
}
// Always add goals to the resource list so they can be added to the CarePlan if needed
// Always add goals to the resource list so they can be added to the CarePlan if
// needed
requestResources.add(goal);
}

Expand Down Expand Up @@ -386,7 +386,8 @@ private RequestGroupActionComponent resolveAction(
// TODO: Figure out why this was here and what it was trying to do
// if (action.hasRelatedAction()) {
// for (var relatedActionComponent : action.getRelatedAction()) {
// if (relatedActionComponent.getRelationship().equals(ActionRelationshipType.AFTER)
// if
// (relatedActionComponent.getRelationship().equals(ActionRelationshipType.AFTER)
// && metConditions.containsKey(relatedActionComponent.getActionId())) {
// metConditions.put(action.getId(), action);
// resolveDefinition(planDefinition, requestGroup, action);
Expand All @@ -405,7 +406,7 @@ private RequestGroupActionComponent resolveAction(
}
IBaseResource resource = null;
if (action.hasDefinitionCanonicalType()) {
resource = resolveDefinition(planDefinition, requestGroup, action);
resource = resolveDefinition(planDefinition, action);
if (resource != null) {
applyAction(requestGroup, resource, action);
requestAction.setResource(new Reference(resource.getIdElement()));
Expand Down Expand Up @@ -469,16 +470,14 @@ private RequestGroupActionComponent createRequestAction(PlanDefinitionActionComp
}

private IBaseResource resolveDefinition(
PlanDefinition planDefinition,
RequestGroup requestGroup,
PlanDefinition.PlanDefinitionActionComponent action) {
PlanDefinition planDefinition, PlanDefinition.PlanDefinitionActionComponent action) {
logger.debug(
"Resolving definition {}", action.getDefinitionCanonicalType().getValue());
var definition = action.getDefinitionCanonicalType();
var resourceName = resolveResourceName(definition, planDefinition);
switch (FHIRAllTypes.fromCode(requireNonNull(resourceName))) {
case PLANDEFINITION:
return applyNestedPlanDefinition(requestGroup, definition);
return applyNestedPlanDefinition(planDefinition, definition);
case ACTIVITYDEFINITION:
return applyActivityDefinition(planDefinition, definition);
case QUESTIONNAIRE:
Expand Down Expand Up @@ -548,15 +547,15 @@ private IBaseResource applyActivityDefinition(PlanDefinition planDefinition, Can
return result;
}

private IBaseResource applyNestedPlanDefinition(RequestGroup requestGroup, CanonicalType definition) {
private IBaseResource applyNestedPlanDefinition(PlanDefinition planDefinition, CanonicalType definition) {
RequestGroup result = null;
try {
var planDefinition = (PlanDefinition) SearchHelper.searchRepositoryByCanonical(repository, definition);
result = (RequestGroup) applyPlanDefinition(planDefinition);

for (var c : result.getInstantiatesCanonical()) {
requestGroup.addInstantiatesCanonical(c.getValueAsString());
}
var referenceToContained = definition.getValue().startsWith("#");
var nextPlanDefinition = (PlanDefinition)
(referenceToContained
? resolveContained(planDefinition, definition.getValue())
: SearchHelper.searchRepositoryByCanonical(repository, definition));
result = (RequestGroup) applyPlanDefinition(nextPlanDefinition);
} catch (Exception e) {
var message = String.format(
"ERROR: PlanDefinition %s could not be applied and threw exception %s",
Expand All @@ -576,7 +575,8 @@ private void applyAction(
}

/*
* offset -> Duration timing -> Timing ( just our use case for connectathon period periodUnit
* offset -> Duration timing -> Timing ( just our use case for connectathon
* period periodUnit
* frequency count ) use task code
*/
private void resolveTask(
Expand Down Expand Up @@ -641,7 +641,8 @@ private void resolvePrepopulateAction(
for (var questionnaireBundle : questionnaireBundles) {
var toPopulate =
(Questionnaire) questionnaireBundle.getEntryFirstRep().getResource();
// Bundle should contain a Questionnaire and supporting Library and ValueSet resources
// Bundle should contain a Questionnaire and supporting Library and ValueSet
// resources
var libraries = questionnaireBundle.getEntry().stream()
.filter(e -> e.hasResource()
&& (e.getResource().fhirType().equals(Enumerations.FHIRAllTypes.LIBRARY.toCode())))
Expand Down Expand Up @@ -675,7 +676,8 @@ private void resolvePrepopulateAction(

private List<Bundle> getQuestionnairePackage(Extension prepopulateExtension) {
Bundle bundle = null;
// PlanDef action should provide endpoint for $questionnaire-for-order operation as well as
// PlanDef action should provide endpoint for $questionnaire-for-order operation
// as well as
// the order id to pass
var parameterExtension =
prepopulateExtension.getExtensionByUrl(Constants.SDC_QUESTIONNAIRE_PREPOPULATE_PARAMETER);
Expand Down Expand Up @@ -705,7 +707,8 @@ private List<Bundle> getQuestionnairePackage(Extension prepopulateExtension) {
bundle = new Bundle().addEntry(new Bundle.BundleEntryComponent().setResource(questionnaire));
}
} else if (questionnaireExtension.getValue().hasType(FHIRAllTypes.URL.toCode())) {
// Assuming package operation endpoint if the extension is using valueUrl instead of
// Assuming package operation endpoint if the extension is using valueUrl
// instead of
// valueCanonical
bundle =
callQuestionnairePackageOperation(((UrlType) questionnaireExtension.getValue()).getValueAsString());
Expand Down Expand Up @@ -734,7 +737,8 @@ private Bundle callQuestionnairePackageOperation(String url) {
IGenericClient client = Clients.forUrl(repository.fhirContext(), baseUrl);
// Clients.registerBasicAuth(client, user, password);
try {
// TODO: This is not currently in use, but if it ever is we will need to determine how the
// TODO: This is not currently in use, but if it ever is we will need to
// determine how the
// order and coverage resources are passed in
Type order = null;
Type coverage = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.hl7.fhir.r5.model.Goal.GoalLifecycleStatus;
import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.Library;
import org.hl7.fhir.r5.model.Meta;
import org.hl7.fhir.r5.model.MetadataResource;
import org.hl7.fhir.r5.model.OperationOutcome;
import org.hl7.fhir.r5.model.Parameters;
Expand Down Expand Up @@ -205,7 +204,7 @@ public IBaseResource applyPlanDefinition(PlanDefinition planDefinition) {
.setSubject(new Reference(subjectId));
requestOrchestration.setId(new IdType(
requestOrchestration.fhirType(), planDefinition.getIdElement().getIdPart()));
requestOrchestration.setMeta(new Meta().addProfile(Constants.CPG_STRATEGY));
// requestOrchestration.setMeta(new Meta().addProfile(Constants.CPG_STRATEGY));
if (encounterId != null) {
requestOrchestration.setEncounter(new Reference(encounterId));
}
Expand Down Expand Up @@ -356,7 +355,7 @@ private RequestOrchestrationActionComponent resolveAction(
}
IBaseResource resource = null;
if (action.hasDefinitionCanonicalType()) {
resource = resolveDefinition(planDefinition, requestOrchestration, action);
resource = resolveDefinition(planDefinition, action);
if (resource != null) {
applyAction(requestOrchestration, resource, action);
requestAction.setResource(new Reference(resource.getIdElement()));
Expand Down Expand Up @@ -417,16 +416,14 @@ private RequestOrchestrationActionComponent createRequestAction(PlanDefinitionAc
}

private IBaseResource resolveDefinition(
PlanDefinition planDefinition,
RequestOrchestration requestOrchestration,
PlanDefinition.PlanDefinitionActionComponent action) {
PlanDefinition planDefinition, PlanDefinition.PlanDefinitionActionComponent action) {
logger.debug(
"Resolving definition {}", action.getDefinitionCanonicalType().getValue());
var definition = action.getDefinitionCanonicalType();
var resourceName = resolveResourceName(definition, planDefinition);
switch (FHIRTypes.fromCode(requireNonNull(resourceName))) {
case PLANDEFINITION:
return applyNestedPlanDefinition(requestOrchestration, definition);
return applyNestedPlanDefinition(planDefinition, definition);
case ACTIVITYDEFINITION:
return applyActivityDefinition(planDefinition, definition);
case QUESTIONNAIRE:
Expand Down Expand Up @@ -496,16 +493,15 @@ private IBaseResource applyActivityDefinition(PlanDefinition planDefinition, Can
return result;
}

private IBaseResource applyNestedPlanDefinition(
RequestOrchestration requestOrchestration, CanonicalType definition) {
private IBaseResource applyNestedPlanDefinition(PlanDefinition planDefinition, CanonicalType definition) {
RequestOrchestration result = null;
try {
var planDefinition = (PlanDefinition) SearchHelper.searchRepositoryByCanonical(repository, definition);
result = (RequestOrchestration) applyPlanDefinition(planDefinition);

for (var c : result.getInstantiatesCanonical()) {
requestOrchestration.addInstantiatesCanonical(c.getValueAsString());
}
var referenceToContained = definition.getValue().startsWith("#");
var nextPlanDefinition = (PlanDefinition)
(referenceToContained
? resolveContained(planDefinition, definition.getValue())
: SearchHelper.searchRepositoryByCanonical(repository, definition));
result = (RequestOrchestration) applyPlanDefinition(nextPlanDefinition);
} catch (Exception e) {
var message = String.format(
"ERROR: PlanDefinition %s could not be applied and threw exception %s",
Expand Down
Loading

0 comments on commit d06bd1a

Please sign in to comment.