summaryrefslogtreecommitdiff
path: root/src/main/java/DNPM/services/mtb/OsTumorkonferenzVarianteUkwToProtocolMapper.java
blob: de36415259bf882ffcd982713cc034386b2cebeb (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
package DNPM.services.mtb;

import de.itc.onkostar.api.Procedure;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class OsTumorkonferenzVarianteUkwToProtocolMapper implements ProcedureToProtocolMapper {
    @Override
    public Optional<String> apply(List<Procedure> procedures) {
        procedures.forEach(procedure -> {
            assert (procedure.getFormName().equals("OS.Tumorkonferenz.VarianteUKW"));
        });

        procedures.sort(Comparator.comparing(Procedure::getStartDate));

        var result = procedures.stream().map(procedure -> {
            var fragestellung = procedure.getValue("Fragestellung");
            var empfehlung = procedure.getValue("Empfehlung");

            if (
                    null != fragestellung && !fragestellung.getString().isBlank()
                            && null != empfehlung && !empfehlung.getString().isBlank()
            ) {
                return String.format("%s\n%s", fragestellung.getString(), empfehlung.getString());
            } else if (null != fragestellung && !fragestellung.getString().isBlank()) {
                return fragestellung.getString();
            } else if (null != empfehlung && !empfehlung.getString().isBlank()) {
                return empfehlung.getString();
            }
            return "";
        }).collect(Collectors.joining("\n"));

        if (!result.isBlank()) {
            return Optional.of(result);
        }

        return Optional.empty();
    }
}