summaryrefslogtreecommitdiff
path: root/src/test/java/dev/dnpm/oshelper/services/therapieplan/DefaultTherapieplanServiceTest.java
blob: 18865a83e549154325b55520f0d88a1acb39ea8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * This file is part of onkostar-plugin-dnpm
 *
 * Copyright (C) 2023-2026 the original author or authors.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package dev.dnpm.oshelper.services.therapieplan;

import de.itc.onkostar.api.IOnkostarApi;
import de.itc.onkostar.api.Item;
import de.itc.onkostar.api.Procedure;
import de.itc.onkostar.api.constants.JaNeinUnbekannt;
import dev.dnpm.oshelper.services.FormService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class DefaultTherapieplanServiceTest {

    private IOnkostarApi onkostarApi;

    private TherapieplanService service;

    @BeforeEach
    void setUp(
            @Mock IOnkostarApi onkostarApi,
            @Mock FormService formService
    ) {
        this.onkostarApi = onkostarApi;
        this.service = new DefaultTherapieplanService(onkostarApi, formService);
    }

    @Test
    void shouldNotUpdateSubformsOrSectionsIfMultipleMtbConfiguration() throws Exception {
        this.service.updateRequiredMtbEntries(new Procedure(onkostarApi));
        verify(onkostarApi, never()).saveProcedure(any(Procedure.class), anyBoolean());
    }

    @Test
    void shouldNotUpdateSectionsIfSectionsNotEnabled() throws Exception {
        var testProcedure = baseProcedure(onkostarApi);

        // Keine humangenetische Beratung und keine Reevaluation empfohlen
        testProcedure.setValue("humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.NEIN.getCode()));
        testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.NEIN.getCode()));

        this.service.updateRequiredMtbEntries(testProcedure);

        verify(onkostarApi, never()).saveProcedure(any(Procedure.class), anyBoolean());
    }

    @Test
    void shouldUpdateSectionsIfNoReevaluation() throws Exception {
        var testProcedure = baseProcedure(onkostarApi);

        // Humangenetische Beratung aber keine Reevaluation
        testProcedure.setValue("humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.JA.getCode()));
        testProcedure.setValue("humangenberbegruendung", new Item("humangen_ber_begruendung", "Das ist die Begründung"));
        testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.NEIN.getCode()));

        this.service.updateRequiredMtbEntries(testProcedure);

        var captor = ArgumentCaptor.forClass(Procedure.class);
        verify(onkostarApi, times(1)).saveProcedure(captor.capture(), anyBoolean());

        var capturedProcedure = captor.getValue();

        assertThat(capturedProcedure.getValue("reftkreevaluation")).isNull();
        assertThat(capturedProcedure.getValue("datumtkreevaluation")).isNull();

        assertThat(capturedProcedure.getValue("reftkhumangenber")).isNotNull();
        assertThat(capturedProcedure.getValue("reftkhumangenber").getInt()).isEqualTo(procedureId);
        assertThat(capturedProcedure.getValue("datumtkhumangenber")).isNotNull();
        assertThat(capturedProcedure.getValue("datumtkhumangenber").getDate()).isEqualTo(testDate);
    }

    @Test
    void shouldUpdateSectionsIfNoHumanGenConsultation() throws Exception {
        var testProcedure = baseProcedure(onkostarApi);

        // Humangenetische Beratung aber keine Reevaluation
        testProcedure.setValue("humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.NEIN.getCode()));
        testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.JA.getCode()));

        this.service.updateRequiredMtbEntries(testProcedure);

        var captor = ArgumentCaptor.forClass(Procedure.class);
        verify(onkostarApi, times(1)).saveProcedure(captor.capture(), anyBoolean());

        var capturedProcedure = captor.getValue();

        assertThat(capturedProcedure.getValue("reftkhumangenber")).isNull();
        assertThat(capturedProcedure.getValue("datumtkhumangenber")).isNull();

        assertThat(capturedProcedure.getValue("reftkreevaluation")).isNotNull();
        assertThat(capturedProcedure.getValue("reftkreevaluation").getInt()).isEqualTo(procedureId);
        assertThat(capturedProcedure.getValue("datumtkreevaluation")).isNotNull();
        assertThat(capturedProcedure.getValue("datumtkreevaluation").getDate()).isEqualTo(testDate);
    }

    @Test
    void shouldFindFollowUps() {
        doAnswer(invocationOnMock -> {
            var testProcedure = baseProcedure(onkostarApi);
            testProcedure.setId(procedureId);
            testProcedure.setFormName("DNPM UF Einzelempfehlung");
            testProcedure.addDiseaseId(123);
            return testProcedure;
        }).when(onkostarApi).getProcedure(anyInt());

        doAnswer(invocationOnMock -> {
            var diseaseId = invocationOnMock.getArgument(0, Integer.class);
            var formName = invocationOnMock.getArgument(1, String.class);
            var procedure = baseProcedure(onkostarApi);
            procedure.addDiseaseId(diseaseId);
            procedure.setFormName(formName);
            procedure.setValue("LinkTherapieempfehlung", new Item("LinkTherapieempfehlung", procedureId));
            return List.of(procedure);
        }).when(onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString());

        var followUps = this.service.findReferencedFollowUpsForSubform(1);

        assertThat(followUps).hasSize(1)
                .allSatisfy(procedure -> assertThat(procedure.getFormName()).isEqualTo("DNPM FollowUp"));
    }

    @Test
    void shouldFindFollowUpsById() {
        var testProcedure = baseProcedure(onkostarApi);
        testProcedure.setId(procedureId);
        testProcedure.setFormName("DNPM UF Einzelempfehlung");
        testProcedure.addDiseaseId(123);

        doAnswer(invocationOnMock -> {
            var diseaseId = invocationOnMock.getArgument(0, Integer.class);
            var formName = invocationOnMock.getArgument(1, String.class);
            var procedure = baseProcedure(onkostarApi);
            procedure.addDiseaseId(diseaseId);
            procedure.setFormName(formName);
            procedure.setValue("LinkTherapieempfehlung", new Item("LinkTherapieempfehlung", procedureId));
            return List.of(procedure);
        }).when(onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString());

        var followUps = this.service.findReferencedFollowUpsForSubform(testProcedure);

        assertThat(followUps).hasSize(1)
                .allSatisfy(procedure -> assertThat(procedure.getFormName()).isEqualTo("DNPM FollowUp"));
    }

    private static final int procedureId = 1234;
    private static final Date testDate = Date.from(Instant.parse("2023-03-15T09:43:00Z"));

    private Procedure baseProcedure(final IOnkostarApi onkostarApi) {
        var testProcedure = new Procedure(onkostarApi);
        testProcedure.setId(1000);

        // Setzen MTB Referenz und Datum MTB
        testProcedure.setValue("referstemtb", new Item("ref_tumorkonferenz", procedureId));
        testProcedure.setValue("datum", new Item("datum", testDate));

        return testProcedure;
    }

}