From 777de5b8bafce0d59b687f48cf3d11293c9dc519 Mon Sep 17 00:00:00 2001 From: smals-jy <143497095+smals-jy@users.noreply.github.com> Date: Thu, 5 Sep 2024 08:16:00 +0200 Subject: [PATCH] feat: backport logCommunicationType from evs (#462) * feat: backport logCommunicationType from evs added the ability to also log encrypted incoming and outgoing communication via argument `logCommunicationType`. Possible values: WITHOUT_SECURITY, WITH_SECURITY, ALL. Default: WITHOUT_SECURITY * Create LogCommunicationTypeConverter.java * Create LogCommunicationType.java * feat: sumehr - display items with nullflavor in visualization * Update VaultExporterArguments.java * Update VaultExporterFromIde.java * Update VaultExporterRunner.java * Update UploaderArguments.java * Update UploaderFromIde.java * Update UploaderRunner.java * Create Kind.java * Update HubService.java * Update HubService.java * Update CommunicationLoggerAfterSecurity.java * Update CommunicationLoggerBeforeSecurity.java * Update MessageWriter.java * Update start EVS.cmd * Update start EVS RSW.cmd * Update start EVS RSB.cmd * Update start EVS exporter.cmd * Update start EVS.sh * Update MessageWriter.java * Update VaultExporterFromIde.java * Update Problem.java * Update SumehrMapper.java --------- Co-authored-by: Jacques Yakoub --- .../delivery_output/exe/start EVS RSB.cmd | 2 +- .../delivery_output/exe/start EVS RSW.cmd | 2 +- .../exe/start EVS exporter.cmd | 2 +- .../delivery_output/exe/start EVS.cmd | 2 +- .../delivery_output/exe/start EVS.sh | 2 +- .../imec/ivlab/core/config/EVSProperties.java | 1 + .../LogCommunicationTypeConverter.java | 17 ++++++ .../core/model/hub/LogCommunicationType.java | 18 ++++++ .../model/internal/parser/sumehr/Problem.java | 9 +-- .../parser/sumehr/mapper/SumehrMapper.java | 11 ++++ .../exporter/VaultExporterArguments.java | 5 ++ .../exporter/VaultExporterFromIde.java | 7 ++- .../exporter/VaultExporterRunner.java | 1 + .../uploader/UploaderArguments.java | 5 ++ .../uploader/UploaderFromIde.java | 5 +- .../uploader/UploaderRunner.java | 1 + .../ivlab/ehconnector/hub/HubService.java | 15 +++-- .../CommunicationLoggerAfterSecurity.java | 53 +++++++++++------ .../CommunicationLoggerBeforeSecurity.java | 57 +++++++++++++------ .../ivlab/ehconnector/hub/logging/Kind.java | 5 ++ .../hub/logging/MessageWriter.java | 22 ++++++- 21 files changed, 185 insertions(+), 57 deletions(-) create mode 100644 core/src/main/java/org/imec/ivlab/core/jcommander/LogCommunicationTypeConverter.java create mode 100644 core/src/main/java/org/imec/ivlab/core/model/hub/LogCommunicationType.java create mode 100644 ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/Kind.java diff --git a/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSB.cmd b/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSB.cmd index a49b0496..fd9b2fb3 100644 --- a/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSB.cmd +++ b/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSB.cmd @@ -1 +1 @@ -../system/vault-uploader.cmd -rootDir="..\exe\interaction" -writeAsIs=false -exportAfterUpload=true -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=RSB -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true +../system/vault-uploader.cmd -rootDir="..\exe\interaction" -writeAsIs=false -exportAfterUpload=true -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=RSB -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true -logCommunicationType=WITHOUT_SECURITY diff --git a/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSW.cmd b/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSW.cmd index 1b1aa9fb..cb028c76 100644 --- a/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSW.cmd +++ b/builder/src/main/resources-filtered/delivery_output/exe/start EVS RSW.cmd @@ -1 +1 @@ -../system/vault-uploader.cmd -rootDir="..\exe\interaction" -writeAsIs=false -exportAfterUpload=true -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=RSW -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true +../system/vault-uploader.cmd -rootDir="..\exe\interaction" -writeAsIs=false -exportAfterUpload=true -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=RSW -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true -logCommunicationType=WITHOUT_SECURITY diff --git a/builder/src/main/resources-filtered/delivery_output/exe/start EVS exporter.cmd b/builder/src/main/resources-filtered/delivery_output/exe/start EVS exporter.cmd index 35c971a7..56f5912e 100644 --- a/builder/src/main/resources-filtered/delivery_output/exe/start EVS exporter.cmd +++ b/builder/src/main/resources-filtered/delivery_output/exe/start EVS exporter.cmd @@ -1 +1 @@ -../system/vault-exporter.cmd -transactionType=medicationscheme -patients=patient_template -actor=gp_van_Doe -exportDir="..\exe\exports" -validate=true -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -hub=VITALINK -searchType=LOCAL -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true \ No newline at end of file +../system/vault-exporter.cmd -transactionType=medicationscheme -patients=patient_template -actor=gp_van_Doe -exportDir="..\exe\exports" -validate=true -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -hub=VITALINK -searchType=LOCAL -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true -logCommunicationType=WITHOUT_SECURITY diff --git a/builder/src/main/resources-filtered/delivery_output/exe/start EVS.cmd b/builder/src/main/resources-filtered/delivery_output/exe/start EVS.cmd index 7d682249..907de674 100644 --- a/builder/src/main/resources-filtered/delivery_output/exe/start EVS.cmd +++ b/builder/src/main/resources-filtered/delivery_output/exe/start EVS.cmd @@ -1 +1 @@ -../system/vault-uploader.cmd -rootDir="..\exe\interaction" -writeAsIs=false -exportAfterUpload=true -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=VITALINK -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true \ No newline at end of file +../system/vault-uploader.cmd -rootDir="..\exe\interaction" -writeAsIs=false -exportAfterUpload=true -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=VITALINK -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true -logCommunicationType=WITHOUT_SECURITY diff --git a/builder/src/main/resources-filtered/delivery_output/exe/start EVS.sh b/builder/src/main/resources-filtered/delivery_output/exe/start EVS.sh index 4766a765..d15712d8 100644 --- a/builder/src/main/resources-filtered/delivery_output/exe/start EVS.sh +++ b/builder/src/main/resources-filtered/delivery_output/exe/start EVS.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash cd "$(dirname "$0")" -../system/vault-uploader.sh -rootDir="../exe/interaction/" -writeAsIs=false -exportAfterUpload=false -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=VITALINK -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true \ No newline at end of file +../system/vault-uploader.sh -rootDir="../exe/interaction/" -writeAsIs=false -exportAfterUpload=false -validateExportAfterUpload=false -generateGlobalMedicationScheme=true -generateDailyMedicationScheme=false -generateSumehrOverview=true -generateGatewayMedicationScheme=true -startTransactonId=100 -shiftAction=no_tag_and_no_shift -hub=VITALINK -searchType=LOCAL -autoGenerateMSTransactionAuthor=true -generateDiaryNoteVisualization=true -generateVaccinationVisualization=true -generateChildPreventionVisualization=true -generatePopulationBasedScreeningVisualization=true -logCommunicationType=WITHOUT_SECURITY diff --git a/core/src/main/java/org/imec/ivlab/core/config/EVSProperties.java b/core/src/main/java/org/imec/ivlab/core/config/EVSProperties.java index 9c8fb130..c41a8bbf 100644 --- a/core/src/main/java/org/imec/ivlab/core/config/EVSProperties.java +++ b/core/src/main/java/org/imec/ivlab/core/config/EVSProperties.java @@ -4,6 +4,7 @@ public class EVSProperties { public static final String CHOSEN_HUB = "HUB"; public static final String SEARCH_TYPE = "SEARCHTYPE"; + public static final String LOG_COMMUNICATION_TYPE = "LOG_COMMUNICATION_TYPE"; public static final String AUTO_GENERATE_KMEHR_MS_TRANSACTION_AUTHOR = "GENERATE_KMEHR_MS_TRANSACTION_AUTHOR"; public static final String FILTER_OUT_TRANSACTIONS_HAVING_PATIENT_ACCESS_NO = "FILTER_OUT_TRANSACTIONS_HAVING_PATIENT_ACCESS_NO"; diff --git a/core/src/main/java/org/imec/ivlab/core/jcommander/LogCommunicationTypeConverter.java b/core/src/main/java/org/imec/ivlab/core/jcommander/LogCommunicationTypeConverter.java new file mode 100644 index 00000000..66c6cfec --- /dev/null +++ b/core/src/main/java/org/imec/ivlab/core/jcommander/LogCommunicationTypeConverter.java @@ -0,0 +1,17 @@ +package org.imec.ivlab.core.jcommander; + +import com.beust.jcommander.IStringConverter; +import org.imec.ivlab.core.model.hub.Hub; +import org.imec.ivlab.core.model.hub.LogCommunicationType; + + +public class LogCommunicationTypeConverter implements IStringConverter +{ + //@Override + public LogCommunicationType convert(String logCommunicationType) { + + return LogCommunicationType.valueOf(logCommunicationType); + + } + +} diff --git a/core/src/main/java/org/imec/ivlab/core/model/hub/LogCommunicationType.java b/core/src/main/java/org/imec/ivlab/core/model/hub/LogCommunicationType.java new file mode 100644 index 00000000..03d4f5a7 --- /dev/null +++ b/core/src/main/java/org/imec/ivlab/core/model/hub/LogCommunicationType.java @@ -0,0 +1,18 @@ +package org.imec.ivlab.core.model.hub; + +public enum LogCommunicationType { + + WITHOUT_SECURITY, WITH_SECURITY, ALL; + + public static LogCommunicationType fromValue(String input) { + for (LogCommunicationType logCommunicationType : values()) { + if (logCommunicationType.name().equalsIgnoreCase(input)) { + return logCommunicationType; + } + } + + throw new IllegalArgumentException("Invalid LogCommunicationType value: " + input); + + } + +} diff --git a/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/Problem.java b/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/Problem.java index 82109bf8..cb34ecc8 100644 --- a/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/Problem.java +++ b/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/Problem.java @@ -2,18 +2,15 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import org.imec.ivlab.core.model.internal.parser.ItemParsedItem; -@Getter -@Setter +@Data public class Problem extends ItemParsedItem { private LocalDateTime recordDateTime; private LocalDate beginmoment; private LocalDate endmoment; - - + private boolean noKnownTreatment; } diff --git a/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/mapper/SumehrMapper.java b/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/mapper/SumehrMapper.java index 1e2a0c75..113cb0c4 100644 --- a/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/mapper/SumehrMapper.java +++ b/core/src/main/java/org/imec/ivlab/core/model/internal/parser/sumehr/mapper/SumehrMapper.java @@ -268,6 +268,8 @@ public static Treatment toTreatment(ItemType itemType) { toItem(itemType, tm); + tm.setNoKnownTreatment(hasNullFlavor(itemType)); + if (itemType.getBeginmoment() != null) { tm.setBeginmoment(itemType.getBeginmoment().getDate().toLocalDate()); tm.getUnparsed().getBeginmoment().setDate(null); @@ -286,6 +288,8 @@ public static Problem toProblem(ItemType itemType) { toItem(itemType, pb); + pb.setNoKnownTreatment(hasNullFlavor(itemType)); + if (itemType.getBeginmoment() != null) { pb.setBeginmoment(itemType.getBeginmoment().getDate().toLocalDate()); pb.getUnparsed().getBeginmoment().setDate(null); @@ -306,6 +310,13 @@ public static Problem toProblem(ItemType itemType) { return pb; } + private static boolean hasNullFlavor(ItemType itemType) { + return CDItemUtil + .getCDItems(itemType.getCds(), CDITEMschemes.CD_ITEM) + .stream() + .anyMatch(cdItem -> org.apache.commons.lang3.StringUtils.equalsIgnoreCase(cdItem.getNullFlavor(), "NA")); + } + public static PatientWill toPatientWill(ItemType itemType) { PatientWill patientWill = new PatientWill(); diff --git a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterArguments.java b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterArguments.java index f0cfdc41..130cc124 100644 --- a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterArguments.java +++ b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterArguments.java @@ -5,7 +5,9 @@ import lombok.Getter; import lombok.Setter; import org.imec.ivlab.core.jcommander.HubConverter; +import org.imec.ivlab.core.jcommander.LogCommunicationTypeConverter; import org.imec.ivlab.core.jcommander.SearchTypeConverter; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.imec.ivlab.core.model.upload.TransactionType; import org.imec.ivlab.core.authentication.AuthenticationConfigReader; import org.imec.ivlab.core.jcommander.LocalDateConverter; @@ -78,4 +80,7 @@ public class VaultExporterArguments { @Parameter(names = "-filterOutTransactionsHavingPatientAccessNo", description = "Do not attempt to get hub transactions that are marked as PatientAccess=no", arity = 1) private boolean filterOutTransactionsHavingPatientAccessNo; + @Parameter(names = "-logCommunicationType", description = "What kind communication to log", converter = LogCommunicationTypeConverter.class) + private LogCommunicationType logCommunicationType = LogCommunicationType.WITHOUT_SECURITY; + } diff --git a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterFromIde.java b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterFromIde.java index 33613d19..86e47f81 100644 --- a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterFromIde.java +++ b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterFromIde.java @@ -8,6 +8,7 @@ import org.imec.ivlab.core.authentication.AuthenticationConfigReader; import org.imec.ivlab.core.data.PatientKey; import org.imec.ivlab.core.model.hub.Hub; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.imec.ivlab.core.model.hub.SearchType; import org.imec.ivlab.core.model.upload.TransactionType; @@ -40,8 +41,10 @@ public static void main(String[] args) throws TechnicalConnectorException { arguments.setGenerateGatewayMedicationScheme(true); arguments.setDailyMedicationSchemeDate(LocalDate.now().plusYears(4)); arguments.setFilterOutTransactionsHavingPatientAccessNo(false); - - arguments.setHub(Hub.RSB); + + arguments.setLogCommunicationType(LogCommunicationType.WITHOUT_SECURITY); + + arguments.setHub(Hub.VITALINK); arguments.setSearchType(SearchType.LOCAL); // arguments.setBreakTheGlassIfTRMissing(true); diff --git a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterRunner.java b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterRunner.java index 185050e0..854ef5ef 100644 --- a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterRunner.java +++ b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/exporter/VaultExporterRunner.java @@ -83,6 +83,7 @@ public void start(VaultExporterArguments arguments) { EVSConfig.getInstance().setProperty(EVSProperties.CHOSEN_HUB, arguments.getHub().name()); EVSConfig.getInstance().setProperty(EVSProperties.SEARCH_TYPE, arguments.getSearchType().name()); + EVSConfig.getInstance().setProperty(EVSProperties.LOG_COMMUNICATION_TYPE, arguments.getLogCommunicationType().name()); EVSConfig.getInstance().setProperty(EVSProperties.FILTER_OUT_TRANSACTIONS_HAVING_PATIENT_ACCESS_NO, String.valueOf(arguments.isFilterOutTransactionsHavingPatientAccessNo())); for (int patientKeyIndex = 0; patientKeyIndex < patientKeys.size(); patientKeyIndex++) { diff --git a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderArguments.java b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderArguments.java index 7aa1f4d1..01e76ccf 100644 --- a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderArguments.java +++ b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderArguments.java @@ -7,9 +7,11 @@ import lombok.ToString; import org.imec.ivlab.core.jcommander.HubConverter; import org.imec.ivlab.core.jcommander.LocalDateConverter; +import org.imec.ivlab.core.jcommander.LogCommunicationTypeConverter; import org.imec.ivlab.core.jcommander.PathToFileConverter; import org.imec.ivlab.core.jcommander.SearchTypeConverter; import org.imec.ivlab.core.model.hub.Hub; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.imec.ivlab.core.model.hub.SearchType; import org.imec.ivlab.datagenerator.uploader.dateshift.ShiftAction; import org.imec.ivlab.datagenerator.uploader.dateshift.ShiftActionConverter; @@ -80,4 +82,7 @@ public class UploaderArguments { @Parameter(names = "-filterOutTransactionsHavingPatientAccessNo", description = "Do not attempt to get hub transactions that are marked as PatientAccess=no", arity = 1) private boolean filterOutTransactionsHavingPatientAccessNo; + @Parameter(names = "-logCommunicationType", description = "What kind communication to log", converter = LogCommunicationTypeConverter.class) + private LogCommunicationType logCommunicationType = LogCommunicationType.WITHOUT_SECURITY; + } diff --git a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderFromIde.java b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderFromIde.java index 8ce22468..b8619c39 100644 --- a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderFromIde.java +++ b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderFromIde.java @@ -4,6 +4,7 @@ import org.joda.time.LocalDate; import org.imec.ivlab.core.exceptions.VitalinkException; import org.imec.ivlab.core.model.hub.Hub; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.imec.ivlab.core.model.hub.SearchType; import org.imec.ivlab.datagenerator.uploader.dateshift.ShiftAction; import org.imec.ivlab.datagenerator.uploader.exception.ScannerException; @@ -35,6 +36,8 @@ public static void main(String[] args) throws ScannerException, VitalinkExceptio arguments.setAutoGenerateMSTransactionAuthor(true); arguments.setFilterOutTransactionsHavingPatientAccessNo(false); + arguments.setLogCommunicationType(LogCommunicationType.WITHOUT_SECURITY); + arguments.setStartTransactionId("100"); arguments.setShiftAction(ShiftAction.NO_TAG_AND_NO_SHIFT); @@ -46,4 +49,4 @@ public static void main(String[] args) throws ScannerException, VitalinkExceptio } -} \ No newline at end of file +} diff --git a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderRunner.java b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderRunner.java index c3721a3e..e42ca4c3 100644 --- a/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderRunner.java +++ b/datagenerator/src/main/java/org/imec/ivlab/datagenerator/uploader/UploaderRunner.java @@ -44,6 +44,7 @@ public void start(UploaderArguments arguments) throws ScannerException, Vitalink EVSConfig.getInstance().setProperty(EVSProperties.CHOSEN_HUB, arguments.getHub().name()); EVSConfig.getInstance().setProperty(EVSProperties.SEARCH_TYPE, arguments.getSearchType().name()); + EVSConfig.getInstance().setProperty(EVSProperties.LOG_COMMUNICATION_TYPE, arguments.getLogCommunicationType().name()); EVSConfig.getInstance().setProperty(EVSProperties.AUTO_GENERATE_KMEHR_MS_TRANSACTION_AUTHOR, String.valueOf(arguments.isAutoGenerateMSTransactionAuthor())); EVSConfig.getInstance().setProperty(EVSProperties.FILTER_OUT_TRANSACTIONS_HAVING_PATIENT_ACCESS_NO, String.valueOf(arguments.isFilterOutTransactionsHavingPatientAccessNo())); diff --git a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/HubService.java b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/HubService.java index 6afa2ec2..c8ae285e 100644 --- a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/HubService.java +++ b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/HubService.java @@ -1,5 +1,7 @@ package org.imec.ivlab.ehconnector.hub; +import static org.imec.ivlab.ehconnector.hub.logging.Kind.WITHOUT_SECURITY; + import be.ehealth.business.intrahubcommons.exception.IntraHubBusinessConnectorException; import be.ehealth.businessconnector.hubv3.session.HubSessionServiceFactory; import be.ehealth.technicalconnector.exception.ConnectorException; @@ -54,6 +56,7 @@ import org.imec.ivlab.ehconnector.hub.exception.incurable.NoNodeFoundMatchingTheURI; import org.imec.ivlab.ehconnector.hub.exception.incurable.RemoveNotAllowedIfDataEntryAlreadyDeleted; import org.imec.ivlab.ehconnector.hub.exception.incurable.SubjectWithSSINUnknownException; +import org.imec.ivlab.ehconnector.hub.logging.Kind; import org.imec.ivlab.ehconnector.hub.logging.MessageWriter; public class HubService { @@ -230,7 +233,7 @@ public GetTransactionListResponse getTransactionListOnce(PatientIdType patientId private PutTransactionSetResponse putTransactionSetOnce(Kmehrmessage kmehrmessage) throws VitalinkException, GatewaySpecificErrorException { try { - writeKmehrmessage(kmehrmessage, "PutTransactionSetRequest-kmehrmessage"); + writeKmehrmessage(kmehrmessage, "PutTransactionSetRequest-kmehrmessage", WITHOUT_SECURITY); PutTransactionSetResponse putTransactionSetResponse = hubService.putTransactionSet(kmehrmessage); verifyResponse(putTransactionSetResponse.getAcknowledge()); return putTransactionSetResponse; @@ -241,8 +244,8 @@ private PutTransactionSetResponse putTransactionSetOnce(Kmehrmessage kmehrmessag } - private void writeKmehrmessage(Kmehrmessage kmehrmessage, String operation) { - MessageWriter.logMessage(kmehrToString(kmehrmessage), operation); + private void writeKmehrmessage(Kmehrmessage kmehrmessage, String operation, Kind kind) { + MessageWriter.logMessage(kmehrToString(kmehrmessage), operation, kind); } private String kmehrToString(Kmehrmessage kmehrmessage) { @@ -259,7 +262,7 @@ private String kmehrToString(Kmehrmessage kmehrmessage) { private PutTransactionResponse putTransactionOnce(Kmehrmessage kmehrmessage) throws VitalinkException, GatewaySpecificErrorException { try { - writeKmehrmessage(kmehrmessage, "PutTransactionRequest-kmehrmessage"); + writeKmehrmessage(kmehrmessage, "PutTransactionRequest-kmehrmessage", WITHOUT_SECURITY); PutTransactionResponse putTransactionSetResponse = hubService.putTransaction(kmehrmessage); verifyResponse(putTransactionSetResponse.getAcknowledge()); return putTransactionSetResponse; @@ -299,7 +302,7 @@ private GetTransactionSetResponse getTransactionSetOnce(PatientIdType patientIdT try { GetTransactionSetResponse getTransactionSetResponse = hubService.getTransactionSet(patientIdType, transactionBaseType); - writeKmehrmessage(getTransactionSetResponse.getKmehrmessage(), "GetTransactionSetResponse-kmehrmessage"); + writeKmehrmessage(getTransactionSetResponse.getKmehrmessage(), "GetTransactionSetResponse-kmehrmessage", WITHOUT_SECURITY); verifyResponse(getTransactionSetResponse.getAcknowledge()); return getTransactionSetResponse; } catch (TechnicalConnectorException | IntraHubBusinessConnectorException | GatewayListOfErrorsException e) { @@ -313,7 +316,7 @@ private GetTransactionResponse getTransactionOnce(PatientIdType patientIdType, T try { GetTransactionResponse getTransactionResponse = hubService.getTransaction(patientIdType, transactionBaseType); - writeKmehrmessage(getTransactionResponse.getKmehrmessage(), "GetTransactionResponse-kmehrmessage"); + writeKmehrmessage(getTransactionResponse.getKmehrmessage(), "GetTransactionResponse-kmehrmessage", WITHOUT_SECURITY); verifyResponse(getTransactionResponse.getAcknowledge()); return getTransactionResponse; } catch (TechnicalConnectorException | IntraHubBusinessConnectorException | GatewayListOfErrorsException e) { diff --git a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerAfterSecurity.java b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerAfterSecurity.java index 6c324d9d..50b6e526 100644 --- a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerAfterSecurity.java +++ b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerAfterSecurity.java @@ -1,9 +1,16 @@ package org.imec.ivlab.ehconnector.hub.logging; +import static org.imec.ivlab.ehconnector.hub.logging.Kind.WITH_SECURITY; + import be.ehealth.technicalconnector.exception.TechnicalConnectorException; import be.ehealth.technicalconnector.handler.AbstractSOAPHandler; import be.ehealth.technicalconnector.utils.ConnectorXmlUtils; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.imec.ivlab.core.config.EVSConfig; +import org.imec.ivlab.core.config.EVSProperties; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,43 +24,57 @@ public class CommunicationLoggerAfterSecurity extends AbstractSOAPHandler { public boolean handleOutbound(SOAPMessageContext context) { - + if (getLogCommunicationType().equals(LogCommunicationType.WITH_SECURITY) || getLogCommunicationType().equals(LogCommunicationType.ALL)) { + logMessage(getMessageText(context.getMessage()), getAction(context.getMessage()), WITH_SECURITY); + } return true; } public boolean handleInbound(SOAPMessageContext context) { - - SOAPMessage msg = context.getMessage(); - String messageText; - try { - messageText = ConnectorXmlUtils.format(ConnectorXmlUtils.toString(msg.getSOAPPart().getEnvelope())); - } catch (TechnicalConnectorException | SOAPException e) { - LOG.error("Failed to log incoming message", e); - messageText = ExceptionUtils.getStackTrace(e); + if (getLogCommunicationType().equals(LogCommunicationType.WITH_SECURITY) || getLogCommunicationType().equals(LogCommunicationType.ALL)) { + logMessage(getMessageText(context.getMessage()), getAction(context.getMessage()), WITH_SECURITY); } + return true; + } + private static String getAction(SOAPMessage msg) { String action = null; try { - action = msg.getSOAPPart().getEnvelope().getBody().getFirstChild().getLocalName(); + action = msg + .getSOAPPart().getEnvelope().getBody().getFirstChild().getLocalName(); } catch (SOAPException e) { action = "unknown"; } + return action; + } - logMessage(messageText, action); - - return true; - + private static String getMessageText(SOAPMessage msg) { + String messageText; + try { + messageText = ConnectorXmlUtils.format(ConnectorXmlUtils.toString(msg + .getSOAPPart().getEnvelope())); + } catch (TechnicalConnectorException | SOAPException e) { + LOG.error("Failed to log outgoing message", e); + messageText = ExceptionUtils.getStackTrace(e); + } + return messageText; } - private void logMessage(String messageText, String action) { + private void logMessage(String messageText, String action, Kind kind) { CommunicationLoggerConfiguration instance = CommunicationLoggerConfiguration.getInstance(); if (!instance.isIgnored(action)) { - MessageWriter.logMessage(messageText, action); + MessageWriter.logMessage(messageText, action, kind); } } + @Override public boolean handleFault(SOAPMessageContext c) { this.handleMessage(c); return true; } + + private LogCommunicationType getLogCommunicationType() { + return LogCommunicationType.fromValue(StringUtils.lowerCase(EVSConfig + .getInstance().getProperty(EVSProperties.LOG_COMMUNICATION_TYPE))); + } } diff --git a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerBeforeSecurity.java b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerBeforeSecurity.java index 870b09f9..3c1b6b50 100644 --- a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerBeforeSecurity.java +++ b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/CommunicationLoggerBeforeSecurity.java @@ -1,9 +1,16 @@ package org.imec.ivlab.ehconnector.hub.logging; +import static org.imec.ivlab.ehconnector.hub.logging.Kind.WITHOUT_SECURITY; + import be.ehealth.technicalconnector.exception.TechnicalConnectorException; import be.ehealth.technicalconnector.handler.AbstractSOAPHandler; import be.ehealth.technicalconnector.utils.ConnectorXmlUtils; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.imec.ivlab.core.config.EVSConfig; +import org.imec.ivlab.core.config.EVSProperties; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,43 +24,57 @@ public class CommunicationLoggerBeforeSecurity extends AbstractSOAPHandler { public boolean handleOutbound(SOAPMessageContext context) { + if (getLogCommunicationType().equals(LogCommunicationType.WITHOUT_SECURITY) || getLogCommunicationType().equals(LogCommunicationType.ALL)) { + logMessage(getMessageText(context.getMessage()), getAction(context.getMessage()), WITHOUT_SECURITY); + } + return true; + } - SOAPMessage msg = context.getMessage(); - String messageText; - try { - messageText = ConnectorXmlUtils.format(ConnectorXmlUtils.toString(msg.getSOAPPart().getEnvelope())); - } catch (TechnicalConnectorException | SOAPException e) { - LOG.error("Failed to log outgoing message", e); - messageText = ExceptionUtils.getStackTrace(e); + public boolean handleInbound(SOAPMessageContext context) { + if (getLogCommunicationType().equals(LogCommunicationType.WITHOUT_SECURITY) || getLogCommunicationType().equals(LogCommunicationType.ALL)) { + logMessage(getMessageText(context.getMessage()), getAction(context.getMessage()), WITHOUT_SECURITY); } + return true; + } + private static String getAction(SOAPMessage msg) { String action = null; try { - action = msg.getSOAPPart().getEnvelope().getBody().getFirstChild().getLocalName(); + action = msg + .getSOAPPart().getEnvelope().getBody().getFirstChild().getLocalName(); } catch (SOAPException e) { action = "unknown"; } - - logMessage(messageText, action); - - return true; + return action; } - public boolean handleInbound(SOAPMessageContext context) { - - return true; - + private static String getMessageText(SOAPMessage msg) { + String messageText; + try { + messageText = ConnectorXmlUtils.format(ConnectorXmlUtils.toString(msg + .getSOAPPart().getEnvelope())); + } catch (TechnicalConnectorException | SOAPException e) { + LOG.error("Failed to log outgoing message", e); + messageText = ExceptionUtils.getStackTrace(e); + } + return messageText; } - private void logMessage(String messageText, String action) { + private void logMessage(String messageText, String action, Kind kind) { CommunicationLoggerConfiguration instance = CommunicationLoggerConfiguration.getInstance(); if (!instance.isIgnored(action)) { - MessageWriter.logMessage(messageText, action); + MessageWriter.logMessage(messageText, action, kind); } } + @Override public boolean handleFault(SOAPMessageContext c) { this.handleMessage(c); return true; } + + private LogCommunicationType getLogCommunicationType() { + return LogCommunicationType.fromValue(StringUtils.lowerCase(EVSConfig + .getInstance().getProperty(EVSProperties.LOG_COMMUNICATION_TYPE))); + } } diff --git a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/Kind.java b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/Kind.java new file mode 100644 index 00000000..7fe25bc8 --- /dev/null +++ b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/Kind.java @@ -0,0 +1,5 @@ +package org.imec.ivlab.ehconnector.hub.logging; + +public enum Kind { + WITH_SECURITY, WITHOUT_SECURITY +} diff --git a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/MessageWriter.java b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/MessageWriter.java index 2c41ba77..b5c5809c 100644 --- a/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/MessageWriter.java +++ b/ehconnector/src/main/java/org/imec/ivlab/ehconnector/hub/logging/MessageWriter.java @@ -1,6 +1,10 @@ package org.imec.ivlab.ehconnector.hub.logging; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.imec.ivlab.core.config.EVSConfig; +import org.imec.ivlab.core.config.EVSProperties; +import org.imec.ivlab.core.model.hub.LogCommunicationType; import org.imec.ivlab.core.util.FileUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,15 +18,21 @@ public class MessageWriter { private static final Logger LOG = LoggerFactory.getLogger(MessageWriter.class); + private static LogCommunicationType getLogCommunicationType() { + return LogCommunicationType.fromValue(StringUtils.lowerCase(EVSConfig + .getInstance().getProperty(EVSProperties.LOG_COMMUNICATION_TYPE))); + } - public static void logMessage(String message, String operation) { + public static void logMessage(String message, String operation, Kind kind) { + if (!isAllowedToLog(kind, getLogCommunicationType())) { + return; + } String rootLocation = System.getProperty("user.dir"); String exportDir = rootLocation + File.separator + ".." + File.separator + "logs" + File.separator + "communication"; FileUtil.createDirectoriesRecursively(exportDir); LocalDateTime localDateTime = LocalDateTime.now(); - String date = DateTimeFormat.forPattern("yyyy-MM-dd_HH-mm-ss-SSS").print(localDateTime); - String fileName = exportDir + File.separator + date + "_" + operation + ".xml"; + String fileName = exportDir + File.separator + localDateTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd_HH-mm-ss-SSS")) + "_" + kind.name() + "_" + operation + ".xml"; try { FileUtils.writeStringToFile(new File(fileName), message, "UTF-8"); @@ -32,4 +42,10 @@ public static void logMessage(String message, String operation) { } + private static boolean isAllowedToLog(Kind kind, LogCommunicationType logCommunicationType) { + return logCommunicationType == LogCommunicationType.ALL || + (logCommunicationType == LogCommunicationType.WITHOUT_SECURITY && kind == Kind.WITHOUT_SECURITY) || + (logCommunicationType == LogCommunicationType.WITH_SECURITY && kind == Kind.WITH_SECURITY); + } + }