1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.commons.ihe.fhir.support;
18
19
20 import org.hl7.fhir.dstu3.model.Bundle;
21 import org.hl7.fhir.dstu3.model.NamingSystem;
22
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.function.Predicate;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30
31
32
33
34
35
36
37
38
39 public class AbstractNamingSystemServiceImpl implements NamingSystemService {
40
41 protected transient Map<String, Set<NamingSystem>> namingSystems = new HashMap<>();
42
43 public void addNamingSystems(Bundle bundle) {
44 this.namingSystems.merge(bundle.getId(), setOfNamingSystems(bundle), (set1, set2) -> {
45 Set<NamingSystem> result = new HashSet<>(set1);
46 result.addAll(set2);
47 return result;
48 });
49 }
50
51 @Override
52 public Stream<NamingSystem> findNamingSystems(String id, Predicate<? super NamingSystem> predicate) {
53 if (!namingSystems.containsKey(id)) {
54 throw new IllegalArgumentException("No NamingSystem known with ID " + id);
55 }
56 return namingSystems.get(id).stream().filter(predicate);
57 }
58
59 private Set<NamingSystem> setOfNamingSystems(Bundle bundle) {
60 return bundle.getEntry().stream()
61 .map(bec -> (NamingSystem) bec.getResource())
62 .collect(Collectors.toSet());
63 }
64
65 }