Skip to content

Commit

Permalink
feat: add configuration for patient id pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
pcvolkmer committed Aug 28, 2024
1 parent 02a3a5e commit 6b026b3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
app:
version: 2.1.3
enableCheckDigitConv: ${CHECK_DIGIT_CONVERSION:false}
localPatientIdPattern: "\\w*"

fhir:
extensions:
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 6b026b3

Please sign in to comment.