|
2 | 2 |
|
3 | 3 | import ca.uhn.fhir.context.FhirContext;
|
4 | 4 | import ca.uhn.fhir.fhirpath.IFhirPath;
|
| 5 | +import ch.qos.logback.classic.Logger; |
| 6 | +import ch.qos.logback.classic.spi.ILoggingEvent; |
| 7 | +import ch.qos.logback.core.read.ListAppender; |
5 | 8 | import de.medizininformatikinitiative.torch.exceptions.ReferenceToPatientException;
|
6 | 9 | import de.medizininformatikinitiative.torch.model.crtdl.AttributeGroup;
|
7 | 10 | import de.medizininformatikinitiative.torch.model.crtdl.Code;
|
|
13 | 16 | import org.hl7.fhir.r4.model.Observation;
|
14 | 17 | import org.hl7.fhir.r4.model.Period;
|
15 | 18 | import org.hl7.fhir.r4.model.Questionnaire;
|
| 19 | +import org.hl7.fhir.r4.model.Resource; |
16 | 20 | import org.junit.jupiter.api.BeforeAll;
|
| 21 | +import org.junit.jupiter.api.DisplayName; |
17 | 22 | import org.junit.jupiter.api.Nested;
|
18 | 23 | import org.junit.jupiter.api.Test;
|
| 24 | +import org.slf4j.LoggerFactory; |
19 | 25 |
|
20 | 26 | import java.text.ParseException;
|
21 | 27 | import java.text.SimpleDateFormat;
|
@@ -71,21 +77,32 @@ public void test_compile_MultipleResources() {
|
71 | 77 | assertFalse(result_3);
|
72 | 78 | }
|
73 | 79 |
|
| 80 | + @Test |
| 81 | + @DisplayName("This tests for example the case of 'chained filters'.") |
| 82 | + public void testInvalidSearchParam() { |
| 83 | + Resource anyResource = new Observation(); |
| 84 | + Logger logger = (Logger) LoggerFactory.getLogger(FilterService.class); |
| 85 | + ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); |
| 86 | + listAppender.start(); |
| 87 | + logger.addAppender(listAppender); |
| 88 | + |
| 89 | + var compiledFilter = filterService.compileFilter(List.of(new Filter("none-existing-type", "some-code", |
| 90 | + List.of(new Code(SYS, CODE_1)))), OBSERVATION); |
| 91 | + |
| 92 | + assertThat(compiledFilter.test(anyResource)).isTrue(); |
| 93 | + assertThat(listAppender.list.size()).isEqualTo(1); |
| 94 | + assertThat((listAppender.list.getFirst()).getFormattedMessage()) |
| 95 | + .isEqualTo("Could not find search parameter for filter with name 'some-code' and type " + |
| 96 | + "'none-existing-type' for resource type 'Observation'. Ignoring this filter."); |
| 97 | + } |
| 98 | + |
74 | 99 | @Test
|
75 | 100 | public void testEmptyFilter() {
|
76 | 101 | assertThatThrownBy(() -> filterService.compileFilter(List.of(), OBSERVATION))
|
77 | 102 | .isInstanceOf(IllegalArgumentException.class)
|
78 | 103 | .hasMessageContaining("An empty list of filters can't be compiled.");
|
79 | 104 | }
|
80 | 105 |
|
81 |
| - @Test |
82 |
| - public void test_nonExistingSearchParam() { |
83 |
| - assertThatThrownBy(() -> filterService.compileFilter(List.of(new Filter("foo", "bar", List.of())), OBSERVATION)) |
84 |
| - .isInstanceOf(RuntimeException.class) |
85 |
| - .hasMessageContaining("Could not find any matching search parameter for filter. This can later " + |
86 |
| - "result in unexpected false negative results of the 'test' method of 'CompiledFilter'."); |
87 |
| - } |
88 |
| - |
89 | 106 | @Nested
|
90 | 107 | class TestCodeableConcept {
|
91 | 108 |
|
|
0 commit comments