Skip to content

Commit

Permalink
Merge pull request #1246 from mozzy11/develop
Browse files Browse the repository at this point in the history
Add suport for an asterisk when defining a remote source Identifier
  • Loading branch information
mozzy11 authored Aug 22, 2024
2 parents 6a31d09 + 35f793e commit cd8e11a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ public void processRequest(HttpServletRequest request, HttpServletResponse respo
}
}

if (!GenericValidator.isBlankOrNull(serviceRequest.getRequester().getReferenceElement().getIdPart())
&& serviceRequest.getRequester().getReference().contains(ResourceType.Practitioner.toString())) {
if (!GenericValidator.isBlankOrNull(task.getOwner().getReferenceElement().getIdPart())
&& task.getOwner().getReference().contains(ResourceType.Practitioner.toString())) {
try {
requesterPerson = localFhirClient.read() //
.resource(Practitioner.class) //
.withId(serviceRequest.getRequester().getReferenceElement().getIdPart()) //
.withId(task.getOwner().getReferenceElement().getIdPart()) //
.execute();
LogEvent.logDebug(this.getClass().getSimpleName(), "processRequest",
"found matching requester " + requesterPerson.getIdElement().getIdPart());
Expand All @@ -245,6 +245,24 @@ public void processRequest(HttpServletRequest request, HttpServletResponse respo
}
}

if (requesterPerson == null) {
if (!GenericValidator.isBlankOrNull(serviceRequest.getRequester().getReferenceElement().getIdPart())
&& serviceRequest.getRequester().getReference()
.contains(ResourceType.Practitioner.toString())) {
try {
requesterPerson = localFhirClient.read() //
.resource(Practitioner.class) //
.withId(serviceRequest.getRequester().getReferenceElement().getIdPart()) //
.execute();
LogEvent.logDebug(this.getClass().getSimpleName(), "processRequest",
"found matching requester " + requesterPerson.getIdElement().getIdPart());
} catch (ResourceNotFoundException e) {
LogEvent.logWarn(this.getClass().getSimpleName(), "processRequest", "no matching requester");
}
}

}

if (specimen != null && !GenericValidator
.isBlankOrNull(specimen.getCollection().getCollector().getReferenceElement().getIdPart())) {
try {
Expand Down Expand Up @@ -389,6 +407,14 @@ private void addRequester(StringBuilder xml) {
}
requesterValuesMap.put(PROVIDER_LAST_NAME, requesterPerson.getNameFirstRep().getFamily());
requesterValuesMap.put(PROVIDER_FIRST_NAME, requesterPerson.getNameFirstRep().getGivenAsSingleString());
} else {
Provider provider = providerService
.getProviderByFhirId(UUID.fromString(task.getOwner().getReferenceElement().getIdPart()));
if (provider != null) {
requesterValuesMap.put(PROVIDER_ID, provider.getId());
requesterValuesMap.put(PROVIDER_PERSON_ID, provider.getPerson().getId());
}

}
xml.append("<requester>");
XMLUtil.appendKeyValue(PROVIDER_ID, requesterValuesMap.get(PROVIDER_ID), xml);
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/openelisglobal/dataexchange/fhir/FhirConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory;
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.IRestfulClientFactory;
import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.validator.GenericValidator;
import org.apache.http.impl.client.CloseableHttpClient;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.ResourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -29,6 +40,9 @@ public class FhirConfig {
@Value("${org.openelisglobal.fhirstore.password:}")
private String password;

@Value("${org.openelisglobal.remote.source.identifier:}#{T(java.util.Collections).emptyList()}")
private List<String> remoteStoreIdentifier;

@Autowired
CloseableHttpClient httpClient;

Expand Down Expand Up @@ -65,4 +79,40 @@ public String getPassword() {
public String[] getRemoteStorePaths() {
return remoteStorePaths;
}

public List<String> getRemoteStoreIdentifier() {
if (remoteStoreIdentifier.get(0).equals(ResourceType.Practitioner + "/*")) {
remoteStoreIdentifier = new ArrayList<>();
for (String remoteStorePath : getRemoteStorePaths()) {
IGenericClient fhirClient = fhirContext().newRestfulGenericClient(remoteStorePath);
if (!GenericValidator.isBlankOrNull(getUsername())
&& !getLocalFhirStorePath().equals(remoteStorePath)) {
IClientInterceptor authInterceptor = new BasicAuthInterceptor(getUsername(), getPassword());
fhirClient.registerInterceptor(authInterceptor);
}
List<Bundle> allBundles = new ArrayList<>();
Bundle practitionerBundle = fhirClient.search().forResource(Practitioner.class)
.returnBundle(Bundle.class).execute();
allBundles.add(practitionerBundle);

while (practitionerBundle.getLink(IBaseBundle.LINK_NEXT) != null) {
practitionerBundle = fhirClient.loadPage().next(practitionerBundle).execute();
allBundles.add(practitionerBundle);
}

for (Bundle bundle : allBundles) {
for (BundleEntryComponent bundleComponent : bundle.getEntry()) {
if (bundleComponent.hasResource()
&& ResourceType.Practitioner.equals(bundleComponent.getResource().getResourceType())) {

remoteStoreIdentifier.add(ResourceType.Practitioner + "/"
+ bundleComponent.getResource().getIdElement().getIdPart());
}
}
}
}
}
return remoteStoreIdentifier;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public class FhirApiWorkFlowServiceImpl implements FhirApiWorkflowService {
@Value("${org.openelisglobal.remote.source.updateStatus}")
private Optional<Boolean> remoteStoreUpdateStatus;

@Value("${org.openelisglobal.remote.source.identifier:}#{T(java.util.Collections).emptyList()}")
private List<String> remoteStoreIdentifier;

@Scheduled(initialDelay = 10 * 1000, fixedRate = 2 * 60 * 1000)
@Override
public void pollForRemoteTasks() {
Expand Down Expand Up @@ -127,7 +124,7 @@ public void processWorkflow(ResourceType resourceType) {
}

private void beginTaskCheckIfAcceptedPath(String remoteStorePath) throws FhirLocalPersistingException {
if (remoteStoreIdentifier.isEmpty()) {
if (fhirConfig.getRemoteStoreIdentifier().isEmpty()) {
return;
}

Expand Down Expand Up @@ -208,7 +205,7 @@ private void beginTaskCheckIfAcceptedPath(String remoteStorePath) throws FhirLoc
}

private void beginTaskImportResultsPath(String remoteStorePath) {
if (remoteStoreIdentifier.isEmpty()) {
if (fhirConfig.getRemoteStoreIdentifier().isEmpty()) {
return;
}

Expand Down Expand Up @@ -369,7 +366,7 @@ private void addResultImportObject(BundleEntryComponent bundleEntry,
}

private void beginTaskImportOrderPath(String remoteStorePath) {
if (remoteStoreIdentifier.isEmpty()) {
if (fhirConfig.getRemoteStoreIdentifier().isEmpty()) {
return;
}

Expand All @@ -383,7 +380,7 @@ private void beginTaskImportOrderPath(String remoteStorePath) {
// .include(Task.INCLUDE_PATIENT)//
// .include(Task.INCLUDE_BASED_ON)//
.where(Task.STATUS.exactly().code(TaskStatus.REQUESTED.toCode())) //
.where(Task.OWNER.hasAnyOfIds(remoteStoreIdentifier));
.where(Task.OWNER.hasAnyOfIds(fhirConfig.getRemoteStoreIdentifier()));
Bundle importBundle = searchQuery.execute();
importBundles.add(importBundle);
if (importBundle.hasEntry()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.openelisglobal.testresult.valueholder.TestResult;
import org.openelisglobal.typeoftestresult.service.TypeOfTestResultServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -121,9 +120,6 @@ public class FhirReferralServiceImpl implements FhirReferralService {
@Autowired
private FhirConfig fhirConfig;

@Value("${org.openelisglobal.remote.source.identifier:}#{T(java.util.Collections).emptyList()}")
private List<String> remoteStoreIdentifier;

private final String RESULT_SUBJECT = "Result Note";
private String RESULT_TABLE_ID;
private String RESULT_REPORT_ID;
Expand Down Expand Up @@ -246,9 +242,9 @@ public Task createReferralTask(Organization referralOrganization, Patient patien
if (requester.isPresent()) {
task.setRequester(fhirTransformService.createReferenceFor(requester.get()));
}
if (!remoteStoreIdentifier.isEmpty()) {
if (!fhirConfig.getRemoteStoreIdentifier().isEmpty()) {
task.setRestriction(new TaskRestrictionComponent()
.setRecipient(Arrays.asList(new Reference(remoteStoreIdentifier.get(0)))));
.setRecipient(Arrays.asList(new Reference(fhirConfig.getRemoteStoreIdentifier().get(0)))));
}
task.setAuthoredOn(new Date());
task.setStatus(TaskStatus.REQUESTED);
Expand Down

0 comments on commit cd8e11a

Please sign in to comment.