From 02a3a5e5594ff196645d3c92a17c346ea77770b6 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 28 Aug 2024 21:13:45 +0200 Subject: [PATCH 1/9] test: add test for existing method This includes simple refac by returning early if match has been found --- .../ume/obdstofhir/mapper/ObdsToFhirMapper.java | 4 +--- .../obdstofhir/mapper/ObdsToFhirMapperTests.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java index 0261bdb7..cf4b1844 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java @@ -64,14 +64,12 @@ protected String computeResourceIdFromIdentifier(Identifier identifier) { protected static String convertId(String id) { Pattern pattern = Pattern.compile("[^0]\\d{8}"); Matcher matcher = pattern.matcher(id); - var convertedId = ""; if (matcher.find()) { - convertedId = matcher.group(); + return matcher.group(); } else { log.warn("Identifier to convert does not have 9 digits without leading '0': {}", id); return id; } - return convertedId; } public static List prioritiseLatestMeldungExports( diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java index 2c0f0612..86a3f120 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java @@ -99,4 +99,17 @@ void convertObdsDateToDateTimeTypeShouldThrowExceptionOnUnparsableDateString() { ObdsToFhirMapper.convertObdsDateToDateTimeType("some shiny day somewere"); }); } + + @ParameterizedTest + @CsvSource({ + "12345,12345", + "123456789,123456789", + "1234567890,123456789", // Max 9 digits, remove last digit '0' + "1234567891,123456789", // Max 9 digits, remove last digit '1' + "0000012345,0000012345", // Not mathching pattern - keep as is + }) + void convertPatientIdWithDefaultPattern(String input, String output) { + var actual = ObdsToFhirMapper.convertId(input); + assertThat(actual).isEqualTo(output); + } } From 6b026b3fe7369a2705fb59d4049c1d865fe86c1f Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 28 Aug 2024 21:56:35 +0200 Subject: [PATCH 2/9] feat: add configuration for patient id pattern --- .../obdstofhir/mapper/ObdsToFhirMapper.java | 15 +++++- src/main/resources/application.yml | 1 + .../mapper/ObdsToFhirIntegrationTest.java | 49 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java index cf4b1844..78357390 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java @@ -18,13 +18,25 @@ import org.miracum.streams.ume.obdstofhir.model.MeldungExportList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.util.StringUtils; public abstract class ObdsToFhirMapper { protected final FhirProperties fhirProperties; + static Pattern localPatientIdPattern = Pattern.compile("[^0]\\d{8}"); private static final Logger log = LoggerFactory.getLogger(ObdsToFhirMapper.class); + @Value("${app.localPatientIdPattern:[^0]\\d{8}}") + void setStringPattern(String value) { + try { + ObdsToFhirMapper.localPatientIdPattern = Pattern.compile(value); + } catch (Exception e) { + log.error("Not a valid patient ID pattern: {}. Use valid RegExp instead.", value); + throw e; + } + } + protected ObdsToFhirMapper(final FhirProperties fhirProperties) { this.fhirProperties = fhirProperties; } @@ -62,8 +74,7 @@ protected String computeResourceIdFromIdentifier(Identifier identifier) { } protected static String convertId(String id) { - Pattern pattern = Pattern.compile("[^0]\\d{8}"); - Matcher matcher = pattern.matcher(id); + Matcher matcher = ObdsToFhirMapper.localPatientIdPattern.matcher(id); if (matcher.find()) { return matcher.group(); } else { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3ddb7c79..5916e999 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,7 @@ app: version: 2.1.3 enableCheckDigitConv: ${CHECK_DIGIT_CONVERSION:false} + localPatientIdPattern: "\\w*" fhir: extensions: diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java new file mode 100644 index 00000000..a7136d67 --- /dev/null +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java @@ -0,0 +1,49 @@ +package org.miracum.streams.ume.obdstofhir.mapper; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.miracum.streams.ume.obdstofhir.FhirProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; +import org.springframework.stereotype.Component; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@Import({ObdsTestMapper.class}) +@MockBean(FhirProperties.class) +public class ObdsToFhirIntegrationTest { + + @Autowired ObdsTestMapper mapper; + + @Nested + @TestPropertySource(properties = {"app.localPatientIdPattern=\\\\w*"}) + class AllWordCharactersAllowed { + + @ParameterizedTest + @CsvSource({ + "12345,12345", + "123456789,123456789", + "1234567890,1234567890", + "1234567891,1234567891", + "0000012345,0000012345" + }) + void keepPatientIdWithLocalPatientIdPattern(String input, String output) { + var actual = ObdsToFhirMapper.convertId(input); + assertThat(actual).isEqualTo(output); + } + } +} + +@Component +class ObdsTestMapper extends ObdsToFhirMapper { + + protected ObdsTestMapper(FhirProperties fhirProperties) { + super(fhirProperties); + } +} From 6deb9983a6ff82f363bb15686e62113b352edeb0 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 28 Aug 2024 22:12:48 +0200 Subject: [PATCH 3/9] test: default pattern is used w/o config --- .../mapper/ObdsToFhirIntegrationTest.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java index a7136d67..1ebf9ade 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java @@ -23,7 +23,7 @@ public class ObdsToFhirIntegrationTest { @Nested @TestPropertySource(properties = {"app.localPatientIdPattern=\\\\w*"}) - class AllWordCharactersAllowed { + class AllWordCharactersAllowedPattern { @ParameterizedTest @CsvSource({ @@ -33,7 +33,24 @@ class AllWordCharactersAllowed { "1234567891,1234567891", "0000012345,0000012345" }) - void keepPatientIdWithLocalPatientIdPattern(String input, String output) { + void applyLocalPatientIdPattern(String input, String output) { + var actual = ObdsToFhirMapper.convertId(input); + assertThat(actual).isEqualTo(output); + } + } + + @Nested + class UseDefaultPatternWithoutConfig { + + @ParameterizedTest + @CsvSource({ + "12345,12345", + "123456789,123456789", + "1234567890,123456789", // Max 9 digits, remove last digit '0' + "1234567891,123456789", // Max 9 digits, remove last digit '1' + "0000012345,0000012345", // Not mathching pattern - keep as is + }) + void applyDefaultPattern(String input, String output) { var actual = ObdsToFhirMapper.convertId(input); assertThat(actual).isEqualTo(output); } From f9afc6afef0ce3d17408d6772c024b9745d99c3c Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 29 Aug 2024 07:20:47 +0200 Subject: [PATCH 4/9] docs: use config entry as usage example --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5916e999..ed16bd0c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,7 @@ app: version: 2.1.3 enableCheckDigitConv: ${CHECK_DIGIT_CONVERSION:false} - localPatientIdPattern: "\\w*" + #localPatientIdPattern: "[^0]\\d{8}" fhir: extensions: From 8528f01a30984f7e924ead04aa69afd520d1f6cf Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 29 Aug 2024 20:04:50 +0200 Subject: [PATCH 5/9] test: add test data for old PatIDs in Erlangen with first digit "G" --- .../streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java index 86a3f120..fb779a90 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java @@ -107,6 +107,9 @@ void convertObdsDateToDateTimeTypeShouldThrowExceptionOnUnparsableDateString() { "1234567890,123456789", // Max 9 digits, remove last digit '0' "1234567891,123456789", // Max 9 digits, remove last digit '1' "0000012345,0000012345", // Not mathching pattern - keep as is + "G1234,G1234", // Erlangen: Not mathching pattern - keep as is + "G123456,G123456", // Erlangen: Not mathching pattern - keep as is + "G123456789,G12345678", // Erlangen: return Non-zero and 8 digits }) void convertPatientIdWithDefaultPattern(String input, String output) { var actual = ObdsToFhirMapper.convertId(input); From 6d1b5cff2ae93afb3d5304bce295d7884ca9935d Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Fri, 30 Aug 2024 16:58:08 +0200 Subject: [PATCH 6/9] chore: update logging message This updates the logging message shown if the input does not match the pattern. Co-authored-by: chgl --- .../miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java index 78357390..478bbc89 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java @@ -78,7 +78,7 @@ protected static String convertId(String id) { if (matcher.find()) { return matcher.group(); } else { - log.warn("Identifier to convert does not have 9 digits without leading '0': {}", id); + log.warn("Identifier to convert does not match pattern: {}", matcher.pattern().toString()); return id; } } From fa79f434b47b98be28b89b8e4f78fc1f14fb77b3 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Fri, 30 Aug 2024 17:04:54 +0200 Subject: [PATCH 7/9] config: update config entry to lowercase kebab-case This also re enables this config option with a default value. Co-authored-by: chgl --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ed16bd0c..205de856 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,7 @@ app: version: 2.1.3 enableCheckDigitConv: ${CHECK_DIGIT_CONVERSION:false} - #localPatientIdPattern: "[^0]\\d{8}" + patient-id-pattern: "[^0]\\d{8}" fhir: extensions: From 954005c217cc35775542c09f3ecfcafb149bad71 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Fri, 30 Aug 2024 17:18:35 +0200 Subject: [PATCH 8/9] chore: change @Value to match lowercase kebab case Co-authored-by: chgl --- .../miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java | 2 +- .../ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java index 478bbc89..a730939a 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java @@ -27,7 +27,7 @@ public abstract class ObdsToFhirMapper { private static final Logger log = LoggerFactory.getLogger(ObdsToFhirMapper.class); - @Value("${app.localPatientIdPattern:[^0]\\d{8}}") + @Value("${app.patient-id-pattern:[^0]\\d{8}}") void setStringPattern(String value) { try { ObdsToFhirMapper.localPatientIdPattern = Pattern.compile(value); diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java index 1ebf9ade..d4ef821b 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java @@ -22,7 +22,7 @@ public class ObdsToFhirIntegrationTest { @Autowired ObdsTestMapper mapper; @Nested - @TestPropertySource(properties = {"app.localPatientIdPattern=\\\\w*"}) + @TestPropertySource(properties = {"app.patient-id-pattern=\\\\w*"}) class AllWordCharactersAllowedPattern { @ParameterizedTest From 8c3a45e7371bf4c0e339e5b032f77592225b1f38 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Fri, 30 Aug 2024 17:23:07 +0200 Subject: [PATCH 9/9] docs: change inline comments in unit tests Co-authored-by: chgl --- .../ume/obdstofhir/mapper/ObdsToFhirMapperTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java index fb779a90..0767d8d7 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapperTests.java @@ -107,9 +107,9 @@ void convertObdsDateToDateTimeTypeShouldThrowExceptionOnUnparsableDateString() { "1234567890,123456789", // Max 9 digits, remove last digit '0' "1234567891,123456789", // Max 9 digits, remove last digit '1' "0000012345,0000012345", // Not mathching pattern - keep as is - "G1234,G1234", // Erlangen: Not mathching pattern - keep as is - "G123456,G123456", // Erlangen: Not mathching pattern - keep as is - "G123456789,G12345678", // Erlangen: return Non-zero and 8 digits + "G1234,G1234", // Not mathching pattern - keep as is + "G123456,G123456", // Not matching pattern - keep as is + "G123456789,G12345678", // return Non-zero and 8 digits }) void convertPatientIdWithDefaultPattern(String input, String output) { var actual = ObdsToFhirMapper.convertId(input);