Skip to content

Commit 2ff73c9

Browse files
committed
Merge remote-tracking branch
'origin/issues/43_ping_pong_endpoints_same_org' into develop
2 parents bc3fc62 + 64f2cad commit 2ff73c9

File tree

6 files changed

+95
-28
lines changed

6 files changed

+95
-28
lines changed

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/message/SendPing.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.highmed.dsf.bpe.message;
22

3+
import static org.highmed.dsf.bpe.ConstantsBase.NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER;
34
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING;
45
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_ALLOWED;
56
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_REACHABLE;
67
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER;
78

9+
import java.util.Collections;
10+
import java.util.Map;
811
import java.util.Objects;
912
import java.util.stream.Stream;
1013

@@ -16,11 +19,14 @@
1619
import org.highmed.dsf.bpe.util.PingStatusGenerator;
1720
import org.highmed.dsf.fhir.authorization.read.ReadAccessHelper;
1821
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
19-
import org.highmed.dsf.fhir.organization.EndpointProvider;
2022
import org.highmed.dsf.fhir.organization.OrganizationProvider;
2123
import org.highmed.dsf.fhir.task.AbstractTaskMessageSend;
2224
import org.highmed.dsf.fhir.task.TaskHelper;
2325
import org.highmed.dsf.fhir.variables.Target;
26+
import org.hl7.fhir.r4.model.Bundle;
27+
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
28+
import org.hl7.fhir.r4.model.Endpoint;
29+
import org.hl7.fhir.r4.model.Identifier;
2430
import org.hl7.fhir.r4.model.Reference;
2531
import org.hl7.fhir.r4.model.ResourceType;
2632
import org.hl7.fhir.r4.model.Task;
@@ -30,17 +36,15 @@
3036

3137
public class SendPing extends AbstractTaskMessageSend
3238
{
33-
private final EndpointProvider endpointProvider;
3439
private final PingStatusGenerator statusGenerator;
3540
private final ErrorLogger errorLogger;
3641

3742
public SendPing(FhirWebserviceClientProvider clientProvider, TaskHelper taskHelper,
3843
ReadAccessHelper readAccessHelper, OrganizationProvider organizationProvider, FhirContext fhirContext,
39-
EndpointProvider endpointProvider, PingStatusGenerator statusGenerator, ErrorLogger errorLogger)
44+
PingStatusGenerator statusGenerator, ErrorLogger errorLogger)
4045
{
4146
super(clientProvider, taskHelper, readAccessHelper, organizationProvider, fhirContext);
4247

43-
this.endpointProvider = endpointProvider;
4448
this.statusGenerator = statusGenerator;
4549
this.errorLogger = errorLogger;
4650
}
@@ -50,18 +54,16 @@ public void afterPropertiesSet() throws Exception
5054
{
5155
super.afterPropertiesSet();
5256

53-
Objects.requireNonNull(endpointProvider, "endpointProvider");
5457
Objects.requireNonNull(statusGenerator, "statusGenerator");
5558
Objects.requireNonNull(errorLogger, "errorLogger");
5659
}
5760

5861
@Override
5962
protected Stream<ParameterComponent> getAdditionalInputParameters(DelegateExecution execution)
6063
{
61-
return Stream.of(
62-
getTaskHelper().createInput(CODESYSTEM_HIGHMED_PING, CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER,
63-
new Reference().setIdentifier(endpointProvider.getLocalEndpointIdentifier())
64-
.setType(ResourceType.Endpoint.name())));
64+
return Stream.of(getTaskHelper().createInput(CODESYSTEM_HIGHMED_PING,
65+
CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER,
66+
new Reference().setIdentifier(getLocalEndpointIdentifier()).setType(ResourceType.Endpoint.name())));
6567
}
6668

6769
@Override
@@ -108,4 +110,17 @@ private String createErrorMessage(Exception exception)
108110
? (": " + exception.getMessage())
109111
: "");
110112
}
113+
114+
private Identifier getLocalEndpointIdentifier()
115+
{
116+
Bundle bundle = getFhirWebserviceClientProvider().getLocalWebserviceClient().search(Endpoint.class,
117+
Map.of("address", Collections.singletonList(getFhirWebserviceClientProvider().getLocalBaseUrl())));
118+
return bundle.getEntry().stream().filter(BundleEntryComponent::hasResource)
119+
.filter(e -> e.getResource() instanceof Endpoint).map(e -> (Endpoint) e.getResource()).findFirst()
120+
.filter(e -> e.hasIdentifier())
121+
.flatMap(e -> e.getIdentifier().stream()
122+
.filter(i -> NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER.equals(i.getSystem())).findFirst())
123+
.orElseThrow(() -> new IllegalStateException("No Identifier for Endpoint or Endpoint with address "
124+
+ getFhirWebserviceClientProvider().getLocalBaseUrl() + " found"));
125+
}
111126
}

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/service/LogPing.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package org.highmed.dsf.bpe.service;
22

3+
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING;
4+
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER;
5+
36
import org.camunda.bpm.engine.delegate.DelegateExecution;
47
import org.highmed.dsf.bpe.delegate.AbstractServiceDelegate;
58
import org.highmed.dsf.fhir.authorization.read.ReadAccessHelper;
69
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
710
import org.highmed.dsf.fhir.task.TaskHelper;
11+
import org.hl7.fhir.r4.model.Identifier;
12+
import org.hl7.fhir.r4.model.Reference;
813
import org.hl7.fhir.r4.model.Task;
914
import org.slf4j.Logger;
1015
import org.slf4j.LoggerFactory;
@@ -24,6 +29,15 @@ public void doExecute(DelegateExecution execution) throws Exception
2429
{
2530
Task task = getCurrentTaskFromExecutionVariables(execution);
2631

27-
logger.info("PING from {}", task.getRequester().getIdentifier().getValue());
32+
logger.info("PING from {} (endpoint: {})", task.getRequester().getIdentifier().getValue(),
33+
getEndpointIdentifierValue(task));
34+
}
35+
36+
private String getEndpointIdentifierValue(Task task)
37+
{
38+
return getTaskHelper()
39+
.getFirstInputParameterReferenceValue(task, CODESYSTEM_HIGHMED_PING,
40+
CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER)
41+
.map(Reference::getIdentifier).map(Identifier::getValue).get();
2842
}
2943
}

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/service/SelectPingTargets.java

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Objects;
1616
import java.util.Optional;
1717
import java.util.UUID;
18+
import java.util.function.Predicate;
1819
import java.util.regex.Pattern;
1920
import java.util.stream.Collectors;
2021
import java.util.stream.Stream;
@@ -33,6 +34,7 @@
3334
import org.hl7.fhir.r4.model.Endpoint;
3435
import org.hl7.fhir.r4.model.Endpoint.EndpointStatus;
3536
import org.hl7.fhir.r4.model.Identifier;
37+
import org.hl7.fhir.r4.model.Organization;
3638
import org.hl7.fhir.r4.model.Resource;
3739
import org.hl7.fhir.r4.model.Task;
3840
import org.slf4j.Logger;
@@ -45,11 +47,11 @@ public class SelectPingTargets extends AbstractServiceDelegate implements Initia
4547
{
4648
private static final Logger logger = LoggerFactory.getLogger(SelectPingTargets.class);
4749

48-
private final OrganizationProvider organizationProvider;
49-
5050
private static final Pattern endpointResouceTypes = Pattern.compile(
5151
"Endpoint|HealthcareService|ImagingStudy|InsurancePlan|Location|Organization|OrganizationAffiliation|PractitionerRole");
5252

53+
private final OrganizationProvider organizationProvider;
54+
5355
public SelectPingTargets(FhirWebserviceClientProvider clientProvider, TaskHelper taskHelper,
5456
ReadAccessHelper readAccessHelper, OrganizationProvider organizationProvider)
5557
{
@@ -74,21 +76,10 @@ public void doExecute(DelegateExecution execution) throws Exception
7476
execution.getBusinessKey()));
7577
updateLeadingTaskInExecutionVariables(execution, task);
7678

77-
// String localAddress = endpointProvider.getLocalEndpoint().getAddress();
78-
// List<Target> targets = endpointProvider.getDefaultEndpointsByOrganizationIdentifier().entrySet().stream()
79-
// .filter(a -> !localAddress.equals(a.getValue().getAddress()))
80-
// .map(e -> Target.createBiDirectionalTarget(e.getKey(),
81-
// e.getValue().getIdentifier().stream()
82-
// .filter(i -> NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER.equals(i.getSystem())).findFirst()
83-
// .map(Identifier::getValue).get(),
84-
// e.getValue().getAddress(), UUID.randomUUID().toString()))
85-
// .collect(Collectors.toList());
86-
8779
Stream<Endpoint> targetEndpoints = getTargetEndpointsSearchParameter(execution).map(this::searchForEndpoints)
88-
.orElse(allEndpoints());
80+
.orElse(allEndpointsNotLocal());
8981

90-
Map<String, Identifier> organizationIdentifierByOrganizationId = organizationProvider.getRemoteOrganizations()
91-
.stream()
82+
Map<String, Identifier> organizationIdentifierByOrganizationId = getAllActiveOrganizations()
9283
.collect(Collectors.toMap(o -> o.getIdElement().getIdPart(),
9384
o -> o.getIdentifier().stream()
9485
.filter(i -> NAMINGSYSTEM_HIGHMED_ORGANIZATION_IDENTIFIER.equals(i.getSystem()))
@@ -167,9 +158,14 @@ private Optional<Class<? extends Resource>> getResourceType(UriComponents search
167158
}
168159
}
169160

170-
private Stream<Endpoint> allEndpoints()
161+
private Stream<Endpoint> allEndpointsNotLocal()
162+
{
163+
return allEndpoints(1, 0).filter(isLocalEndpoint().negate());
164+
}
165+
166+
private Predicate<? super Endpoint> isLocalEndpoint()
171167
{
172-
return allEndpoints(1, 0);
168+
return e -> Objects.equals(getFhirWebserviceClientProvider().getLocalBaseUrl(), e.getAddress());
173169
}
174170

175171
private Stream<Endpoint> allEndpoints(int page, int currentTotal)
@@ -217,4 +213,34 @@ private Optional<String> getEndpointAddress(Endpoint endpoint)
217213
{
218214
return endpoint.hasAddress() ? Optional.of(endpoint.getAddress()) : Optional.empty();
219215
}
216+
217+
private Stream<Organization> getAllActiveOrganizations()
218+
{
219+
return getActiveOrganizations(1, 0);
220+
}
221+
222+
private Stream<Organization> getActiveOrganizations(int page, int currentTotal)
223+
{
224+
Map<String, List<String>> queryParameters = new HashMap<String, List<String>>();
225+
queryParameters.put("active", Collections.singletonList("true"));
226+
queryParameters.put("_page", Collections.singletonList(String.valueOf(page)));
227+
228+
Bundle searchResult = getFhirWebserviceClientProvider().getLocalWebserviceClient()
229+
.searchWithStrictHandling(Organization.class, queryParameters);
230+
231+
if (searchResult.getTotal() > currentTotal + searchResult.getEntry().size())
232+
return Stream.concat(toOrganization(searchResult),
233+
getActiveOrganizations(page + 1, currentTotal + searchResult.getEntry().size()));
234+
else
235+
return toOrganization(searchResult);
236+
}
237+
238+
private Stream<Organization> toOrganization(Bundle searchResult)
239+
{
240+
Objects.requireNonNull(searchResult, "searchResult");
241+
242+
return searchResult.getEntry().stream().filter(BundleEntryComponent::hasResource)
243+
.filter(e -> e.getResource() instanceof Organization).map(e -> (Organization) e.getResource())
244+
.filter(e -> e.getActive());
245+
}
220246
}

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/spring/config/PingConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ErrorLogger errorLogger()
7272
public SendPing sendPing()
7373
{
7474
return new SendPing(clientProvider, taskHelper, readAccessHelper, organizationProvider, fhirContext,
75-
endpointProvider, responseGenerator(), errorLogger());
75+
responseGenerator(), errorLogger());
7676
}
7777

7878
@Bean

dsf-bpe-process-ping/src/main/resources/fhir/ActivityDefinition/highmed-ping.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<code value="REMOTE_ALL" />
3939
</valueCoding>
4040
</extension>
41+
<extension url="requester">
42+
<valueCoding>
43+
<system value="http://highmed.org/fhir/CodeSystem/process-authorization" />
44+
<code value="LOCAL_ALL" />
45+
</valueCoding>
46+
</extension>
4147
<extension url="recipient">
4248
<valueCoding>
4349
<system value="http://highmed.org/fhir/CodeSystem/process-authorization" />

dsf-bpe-process-ping/src/main/resources/fhir/ActivityDefinition/highmed-pong.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
<code value="REMOTE_ALL" />
1919
</valueCoding>
2020
</extension>
21+
<extension url="requester">
22+
<valueCoding>
23+
<system value="http://highmed.org/fhir/CodeSystem/process-authorization" />
24+
<code value="LOCAL_ALL" />
25+
</valueCoding>
26+
</extension>
2127
<extension url="recipient">
2228
<valueCoding>
2329
<system value="http://highmed.org/fhir/CodeSystem/process-authorization" />

0 commit comments

Comments
 (0)