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
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-License-Identifier: BUSL-1.1
//! GF-Addressing through the national address book, LRZa (feature `lrza`).
//!
//! The IG's Care Services Directory follows IHE mCSD, with the LRZa as the
//! authoritative source of every top-level care provider `Organization`: its
//! URA identifier and its name (the IG's Care Services Directory page, Update
//! Client). An `Organization` either carries a URA identifier, a top-level
//! care provider, or is `partOf` another `Organization` (the
//! `ura-identifier-or-partof` invariant of the `nl-gf-organization` and
//! `nl-gf-organization-lrza` profiles).
//!
//! [`ura`] reads that identifier, so a directory reader can join a
//! GF-Localization custodian, named by URA, to the `Organization` and the
//! `Endpoint`s the directory publishes for it. The directory itself is read
//! over mCSD ITI-90 and ITI-91, which this crate does not repeat.
//!
//! An `Endpoint` of the GF directory carries `connectionType`
//! `hl7-fhir-rest` in its examples, which does not denote an openEHR Query
//! API; whoever reads openEHR endpoints from it applies its own
//! `connectionType` rule.
//!
//! # Examples
//!
//! ```
//! use fhir_types::r4::identifier::Identifier;
//! use fhir_types::r4::organization::Organization;
//! use fhir_types::r4::primitives::{String as FhirString, Uri};
//! use nl_generic_functions::identification::URA_SYSTEM;
//! use nl_generic_functions::lrza;
//!
//! let organization = Organization {
//! identifier: vec![Identifier {
//! system: Some(Uri { value: Some(URA_SYSTEM.to_owned()), ..Uri::default() }),
//! value: Some(FhirString { value: Some("ura-test-0001".to_owned()), ..FhirString::default() }),
//! ..Identifier::default()
//! }],
//! ..Organization::default()
//! };
//! let ura = lrza::ura(&organization)?;
//! assert_eq!(ura.map(|ura| ura.to_string()).as_deref(), Some("ura-test-0001"));
//! # Ok::<(), lrza::LrzaError>(())
//! ```
use BTreeSet;
use Organization;
use crate;
/// Why an `Organization` has no URA to give.
/// Returns the URA of `organization`: `Some` for a top-level care provider,
/// `None` for an `Organization` that is `partOf` another.
///
/// # Errors
///
/// [`LrzaError::Missing`] for an `Organization` that is neither,
/// [`LrzaError::EmptyValue`] for a URA identifier without a value, and
/// [`LrzaError::Ambiguous`] for two different URAs.
/// Returns the URA among an organisation's identifiers, each given as its
/// `system` and its `value`: `Some` when they carry one URA, `None` when
/// they carry none.
///
/// It applies the rules of [`ura`] to identifiers read from anywhere, such as
/// a registry that kept an organisation's identifiers, and leaves the
/// `partOf` rule to the caller, which alone knows the hierarchy.
///
/// # Examples
///
/// ```
/// use nl_generic_functions::identification::URA_SYSTEM;
/// use nl_generic_functions::lrza;
///
/// let identifiers = [
/// (Some("urn:oid:2.999.7"), Some("org-1")),
/// (Some(URA_SYSTEM), Some("ura-test-0001")),
/// ];
/// let ura = lrza::ura_in(identifiers)?;
/// assert_eq!(ura.map(|ura| ura.to_string()).as_deref(), Some("ura-test-0001"));
/// # Ok::<(), lrza::LrzaError>(())
/// ```
///
/// # Errors
///
/// [`LrzaError::EmptyValue`] for a URA identifier without a value, and
/// [`LrzaError::Ambiguous`] for two different URAs.