Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/1.0.3.0'
Browse files Browse the repository at this point in the history
* origin/release/1.0.3.0:
  release 1.0.3.0
  update dependencies
  added missing try-catch and harmonized error messages
  local_role before remote_role
  allow dic and dms to be same organization for dataset status message
  add TORCH export demo data
  sort method parameters
  search for exisiting DocumentReferences and update if exists
  add demo bundle for evaluation report
  start development cycle 1.0.3.0
  • Loading branch information
wetret committed Nov 8, 2024
2 parents 6b0678a + 6a890bf commit 083c468
Show file tree
Hide file tree
Showing 19 changed files with 5,299 additions and 75 deletions.
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

<groupId>de.medizininformatik-initiative</groupId>
<artifactId>mii-process-data-transfer</artifactId>
<version>1.0.2.1</version>
<version>1.0.3.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compileSource>17</compileSource>
<compileTarget>17</compileTarget>

<dsf.version>1.5.2</dsf.version>
<dsf.version>1.6.0</dsf.version>
<testSetup.location>../mii-processes-test-setup</testSetup.location>
</properties>

Expand Down Expand Up @@ -45,13 +45,13 @@
<dependency>
<groupId>de.medizininformatik-initiative</groupId>
<artifactId>mii-processes-common</artifactId>
<version>1.0.2.1</version>
<version>1.0.3.0</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
<version>2.0.16</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -91,7 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.1</version>
<version>3.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -141,7 +141,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.7.1</version>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -177,7 +177,7 @@
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.11.0</version>
<version>1.12.0</version>
<configuration>
<compliance>17</compliance>
<groups>java.,javax.,org.,com.</groups>
Expand All @@ -204,22 +204,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
<version>3.21.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.2</version>
<version>3.8.0</version>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.6.2</version>
<version>4.8.6.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.24.0</version>
<version>3.26.0</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

public class DataTransferProcessPluginDefinition implements ProcessPluginDefinition
{
public static final String VERSION = "1.0.2.1";
public static final LocalDate RELEASE_DATE = LocalDate.of(2024, 8, 1);
public static final String VERSION = "1.0.3.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2024, 11, 8);

@Override
public String getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hl7.fhir.r4.model.DocumentReference;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.ResourceType;
import org.hl7.fhir.r4.model.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
Expand Down Expand Up @@ -48,6 +49,7 @@ public void afterPropertiesSet() throws Exception
@Override
protected void doExecute(DelegateExecution execution, Variables variables)
{
Task task = variables.getStartTask();
String projectIdentifier = variables
.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER);
String dmsIdentifier = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DMS_IDENTIFIER);
Expand All @@ -56,14 +58,26 @@ protected void doExecute(DelegateExecution execution, Variables variables)
"Creating transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'",
dmsIdentifier, projectIdentifier, variables.getStartTask().getId());

DocumentReference documentReference = variables
.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DOCUMENT_REFERENCE);
Resource resource = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RESOURCE);
Bundle bundle = createTransactionBundle(variables, projectIdentifier, documentReference, resource);

dataLogger.logResource("Created Transfer Bundle", bundle);

variables.setResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET, bundle);
try
{
DocumentReference documentReference = variables
.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DOCUMENT_REFERENCE);
Resource resource = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RESOURCE);

Bundle bundle = createTransactionBundle(variables, projectIdentifier, documentReference, resource);
dataLogger.logResource("Created Transfer Bundle", bundle);

variables.setResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET, bundle);
}
catch (Exception exception)
{
logger.warn(
"Could not create transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());

String error = "Create transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

private Bundle createTransactionBundle(Variables variables, String projectIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,16 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Decrypt data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Decrypt data-set failed");

logger.warn(
"Could not decrypt data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_REFERENCE),
task.getRequester().getIdentifier().getValue(),
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER), task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Decrypt data-set - " + exception.getMessage());

String error = "Decrypt data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
logger.warn(
"Could not permanently delete data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());
throw new RuntimeException("Could not permanently delete data-set for DMS '" + dmsIdentifier
+ "' and project-identifier '" + projectIdentifier + "' referenced in Task with id '" + task.getId()
+ "' - " + exception.getMessage(), exception);

String error = "Permanently deleting encrypted transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Download data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Download data-set failed");

logger.warn(
"Could not download data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dataSetReference.getValue(), sendingOrganization, projectIdentifier, task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Download data-set - " + exception.getMessage());

String error = "Download data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ protected void doExecute(DelegateExecution execution, Variables variables)
String projectIdentifier = variables
.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER);
String dmsIdentifier = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DMS_IDENTIFIER);
Bundle toEncrypt = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET);
String localOrganizationIdentifier = api.getOrganizationProvider().getLocalOrganizationIdentifierValue()
.orElseThrow(() -> new RuntimeException("LocalOrganizationIdentifierValue is null"));

logger.info(
"Encrypting transferable data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}'",
dmsIdentifier, projectIdentifier, task.getId());

try
{
Bundle toEncrypt = variables.getResource(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET);
String localOrganizationIdentifier = api.getOrganizationProvider().getLocalOrganizationIdentifierValue()
.orElseThrow(() -> new RuntimeException("LocalOrganizationIdentifierValue is null"));

PublicKey publicKey = readPublicKey(dmsIdentifier);
byte[] encrypted = encrypt(publicKey, toEncrypt, localOrganizationIdentifier, dmsIdentifier);

Expand All @@ -76,9 +77,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
logger.warn(
"Could not encrypt data-set for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
dmsIdentifier, projectIdentifier, task.getId(), exception.getMessage());
throw new RuntimeException("Could not encrypt data-set for DMS '" + dmsIdentifier
+ "' and project-identifier '" + projectIdentifier + "' referenced in Task with id '" + task.getId()
+ "' - " + exception.getMessage(), exception);

String error = "Encrypt transferable data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ protected void doExecute(DelegateExecution delegateExecution, Variables variable
String error = variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE);

sendMail(task, projectIdentifier, error);

task.setStatus(Task.TaskStatus.FAILED);
api.getFhirWebserviceClientProvider().getLocalWebserviceClient()
.withRetry(ConstantsBase.DSF_CLIENT_RETRY_6_TIMES, ConstantsBase.DSF_CLIENT_RETRY_INTERVAL_5MIN)
.update(task);
variables.updateTask(task);
}

private void sendMail(Task task, String projectIdentifier, String error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.DocumentReference;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.ResourceType;
import org.hl7.fhir.r4.model.Task;
Expand All @@ -23,6 +25,7 @@
import de.medizininformatik_initiative.processes.common.util.DataSetStatusGenerator;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractServiceDelegate;
import dev.dsf.bpe.v1.constants.NamingSystems;
import dev.dsf.bpe.v1.variables.Variables;

public class InsertData extends AbstractServiceDelegate implements InitializingBean
Expand Down Expand Up @@ -66,7 +69,7 @@ protected void doExecute(DelegateExecution execution, Variables variables)

try
{
List<IdType> createdIds = storeData(variables, fhirClient, bundle, sendingOrganization, projectIdentifier);
List<IdType> createdIds = storeData(fhirClient, bundle, sendingOrganization, projectIdentifier, variables);

task.addOutput(
statusGenerator.createDataSetStatusOutput(ConstantsBase.CODESYSTEM_DATA_SET_STATUS_VALUE_RECEIVE_OK,
Expand All @@ -85,24 +88,25 @@ protected void doExecute(DelegateExecution execution, Variables variables)
ConstantsDataTransfer.CODESYSTEM_DATA_TRANSFER_VALUE_DATA_SET_STATUS, "Insert data-set failed"));
variables.updateTask(task);

variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE,
"Insert data-set failed");

logger.warn(
"Could not insert data-set with id '{}' from organization '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_SET_REFERENCE),
task.getRequester().getIdentifier().getValue(),
variables.getString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_PROJECT_IDENTIFIER), task.getId(),
exception.getMessage());
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR,
"Insert data-set - " + exception.getMessage());

String error = "Insert data-set failed - " + exception.getMessage();
variables.setString(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR_MESSAGE, error);
throw new BpmnError(ConstantsDataTransfer.BPMN_EXECUTION_VARIABLE_DATA_RECEIVE_ERROR, error, exception);
}
}

private List<IdType> storeData(Variables variables, FhirClient fhirClient, Bundle bundle,
String sendingOrganization, String projectIdentifier)
private List<IdType> storeData(FhirClient fhirClient, Bundle bundle, String sendingOrganization,
String projectIdentifier, Variables variables)
{
Bundle stored = fhirClient.executeTransaction(bundle);
Bundle transactionBundle = checkAndAdaptBundleForExistingData(fhirClient, bundle, sendingOrganization,
projectIdentifier, variables.getStartTask());
Bundle stored = fhirClient.executeTransaction(transactionBundle);

List<IdType> idsOfCreatedResources = stored.getEntry().stream().filter(Bundle.BundleEntryComponent::hasResponse)
.map(Bundle.BundleEntryComponent::getResponse).map(Bundle.BundleEntryResponseComponent::getLocation)
Expand All @@ -116,6 +120,48 @@ private List<IdType> storeData(Variables variables, FhirClient fhirClient, Bundl
return idsOfCreatedResources;
}

private Bundle checkAndAdaptBundleForExistingData(FhirClient fhirClient, Bundle bundle, String sendingOrganization,
String projectIdentifier, Task task)
{
Bundle searchResult = fhirClient.getGenericFhirClient().search().forResource(DocumentReference.class)
.where(DocumentReference.IDENTIFIER.exactly()
.systemAndCode(ConstantsBase.NAMINGSYSTEM_MII_PROJECT_IDENTIFIER, projectIdentifier))
.and(DocumentReference.AUTHOR.hasChainedProperty(Organization.IDENTIFIER.exactly()
.systemAndCode(NamingSystems.OrganizationIdentifier.SID, sendingOrganization)))
.returnBundle(Bundle.class).execute();

List<DocumentReference> existingDocumentReferences = searchResult.getEntry().stream()
.filter(Bundle.BundleEntryComponent::hasResource).map(Bundle.BundleEntryComponent::getResource)
.filter(r -> r instanceof DocumentReference).map(r -> (DocumentReference) r).toList();

if (existingDocumentReferences.size() < 1)
return bundle;

if (existingDocumentReferences.size() > 1)
logger.warn(
"Found more than one DocumentReference for project-identifier '{}' authored by '{}', using the first",
projectIdentifier, sendingOrganization);

DocumentReference existingDocumentReference = existingDocumentReferences.get(0);
String existingDocumentReferenceId = existingDocumentReference.getIdElement().getIdPart();

logger.info(
"DocumentReference for project-identifier '{}' authored by '{}' already exists, updating data-set on FHIR server with baseUrl '{}' in Task with id '{}'",
projectIdentifier, sendingOrganization, fhirClient.getFhirBaseUrl(), task.getId());

bundle.getEntry().stream().filter(Bundle.BundleEntryComponent::hasResource)
.filter(e -> e.getResource() instanceof DocumentReference)
.filter(Bundle.BundleEntryComponent::hasRequest).filter(Bundle.BundleEntryComponent::hasResource)
.forEach(e ->
{
e.getRequest().setMethod(Bundle.HTTPVerb.PUT)
.setUrl(ResourceType.DocumentReference.name() + "/" + existingDocumentReferenceId);
e.getResource().setId(existingDocumentReferenceId);
});

return bundle;
}

private void sendMail(Task task, List<IdType> createdIds, String sendingOrganization, String projectIdentifier)
{
String subject = "New data-set received in process '" + ConstantsDataTransfer.PROCESS_NAME_FULL_DATA_RECEIVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ protected void doExecute(DelegateExecution execution, Variables variables)
"Could not read data-set on FHIR server with baseUrl '{}' for DMS '{}' and project-identifier '{}' referenced in Task with id '{}' - {}",
fhirClient.getFhirBaseUrl(), dmsIdentifier, projectIdentifier, task.getId(),
exception.getMessage());
throw new RuntimeException(
"Could not read data-set on FHIR server with baseUrl '" + fhirClient.getFhirBaseUrl()
+ "' for DMS '" + dmsIdentifier + "' and project-identifier '" + projectIdentifier
+ "' referenced in Task with id '" + task.getId() + "' - " + exception.getMessage());

String error = "Read data-set failed - " + exception.getMessage();
throw new RuntimeException(error, exception);
}
}

Expand Down
Loading

0 comments on commit 083c468

Please sign in to comment.