sdc-mapper 4.3.0__tar.gz → 4.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {sdc_mapper-4.3.0/src/sdc_mapper.egg-info → sdc_mapper-4.3.2}/PKG-INFO +2 -2
  2. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/README.md +1 -1
  3. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/pyproject.toml +1 -1
  4. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/__init__.py +1 -1
  5. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/codes.py +26 -10
  6. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2/src/sdc_mapper.egg-info}/PKG-INFO +2 -2
  7. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/tests/test_codes.py +38 -0
  8. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/LICENSE +0 -0
  9. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/NOTICE +0 -0
  10. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/setup.cfg +0 -0
  11. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/cli.py +0 -0
  12. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/contract.py +0 -0
  13. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/engine.py +0 -0
  14. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/gate.py +0 -0
  15. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/log.py +0 -0
  16. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/mapping.py +0 -0
  17. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/mcp_server.py +0 -0
  18. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/placement.py +0 -0
  19. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/report.py +0 -0
  20. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/resolve.py +0 -0
  21. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/schemas/log-entry.schema.json +0 -0
  22. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/schemas/mapping.schema.json +0 -0
  23. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/schemas/sdc4.xsd +0 -0
  24. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper/service.py +0 -0
  25. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper.egg-info/SOURCES.txt +0 -0
  26. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper.egg-info/dependency_links.txt +0 -0
  27. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper.egg-info/entry_points.txt +0 -0
  28. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper.egg-info/requires.txt +0 -0
  29. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/src/sdc_mapper.egg-info/top_level.txt +0 -0
  30. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/tests/test_core.py +0 -0
  31. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/tests/test_placement.py +0 -0
  32. {sdc_mapper-4.3.0 → sdc_mapper-4.3.2}/tests/test_service.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdc-mapper
3
- Version: 4.3.0
3
+ Version: 4.3.2
4
4
  Summary: The shared core of the Semantic Data Charter's Governed Data Record mappers: validate, resolve, map, and report every value; MCP server included.
5
5
  Author: Axius SDC, Inc.
6
6
  License-Expression: Apache-2.0
@@ -33,7 +33,7 @@ target could say it too. Every call is appended to a hash-chained log that holds
33
33
  Each target format is its own package (`sdc-gdr2ubl`, `sdc-gdr2edifact`, `sdc-gdr2omop`, ...) registered under the
34
34
  entry-point group `sdc_mapper.targets`. Outbound only. Apache 2.0.
35
35
 
36
- **Status:** 4.3.0. Five target mappers are released: `sdc-gdr2ubl` (OASIS UBL 2.3), `sdc-gdr2edifact` (UN/EDIFACT
36
+ **Status:** 4.3.2. Five target mappers are released: `sdc-gdr2ubl` (OASIS UBL 2.3), `sdc-gdr2edifact` (UN/EDIFACT
37
37
  D.24A), `sdc-gdr2omop` (OMOP CDM 5.4), `sdc-gdr2fhir` (HL7 FHIR R4) and `sdc-gdr2hl7v2` (HL7 v2.5.1).
38
38
 
39
39
  ## Use
@@ -11,7 +11,7 @@ target could say it too. Every call is appended to a hash-chained log that holds
11
11
  Each target format is its own package (`sdc-gdr2ubl`, `sdc-gdr2edifact`, `sdc-gdr2omop`, ...) registered under the
12
12
  entry-point group `sdc_mapper.targets`. Outbound only. Apache 2.0.
13
13
 
14
- **Status:** 4.3.0. Five target mappers are released: `sdc-gdr2ubl` (OASIS UBL 2.3), `sdc-gdr2edifact` (UN/EDIFACT
14
+ **Status:** 4.3.2. Five target mappers are released: `sdc-gdr2ubl` (OASIS UBL 2.3), `sdc-gdr2edifact` (UN/EDIFACT
15
15
  D.24A), `sdc-gdr2omop` (OMOP CDM 5.4), `sdc-gdr2fhir` (HL7 FHIR R4) and `sdc-gdr2hl7v2` (HL7 v2.5.1).
16
16
 
17
17
  ## Use
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sdc-mapper"
7
- version = "4.3.0"
7
+ version = "4.3.2"
8
8
  description = "The shared core of the Semantic Data Charter's Governed Data Record mappers: validate, resolve, map, and report every value; MCP server included."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -20,7 +20,7 @@ from .placement import JOIN, LOOKUP_TRANSFORMS, ClusterPlacement, Extra, Placeme
20
20
  from .report import CoverageReport, IncompleteMapping, build_report
21
21
  from .resolve import Exceptional, ResolvedRecord, ResolvedValue, Units, resolve
22
22
 
23
- __version__ = "4.3.0"
23
+ __version__ = "4.3.2"
24
24
  __all__ = [
25
25
  "Engine", "CallResult", "Gate", "GateResult", "Recovery", "Log", "entry_hash", "Mapping", "MappingError", "Rule",
26
26
  "load_mapping", "place", "Placement", "ClusterPlacement", "Extra", "JOIN", "join_depth", "LOOKUP_TRANSFORMS", "CodeRef", "code_of",
@@ -39,8 +39,14 @@ class CodeRef:
39
39
  code: str
40
40
 
41
41
 
42
- def code_of(iri: str | None) -> CodeRef | None:
43
- """The code an IRI names, or None (an IRI that names a whole code system, or a page about a variable)."""
42
+ def code_of(iri: str | None, code_lists: bool = True) -> CodeRef | None:
43
+ """The code an IRI names, or None (an IRI that names a whole code system, or a page about a variable).
44
+
45
+ The code systems' own forms (LOINC, SNOMED CT, NCI Thesaurus) always read as codes. An IRI ending in `#code` reads
46
+ as an entry in a code list only with `code_lists`: that is how a model binds an enumerated value to a list (UBL's,
47
+ HL7's), but the same form also names a vocabulary term (`prov#Entity`) or an anchor on a page about a variable
48
+ (`DEMO_J.htm#SEQN`), which are not codes. 4.3.1: concept links read without it.
49
+ """
44
50
  if not iri:
45
51
  return None
46
52
  iri = iri.strip()
@@ -48,9 +54,10 @@ def code_of(iri: str | None) -> CodeRef | None:
48
54
  m = form.match(iri)
49
55
  if m:
50
56
  return CodeRef(system, m.group(1))
51
- m = _FRAGMENT.match(iri)
52
- if m:
53
- return CodeRef(m.group(1), m.group(2))
57
+ if code_lists:
58
+ m = _FRAGMENT.match(iri)
59
+ if m:
60
+ return CodeRef(m.group(1), m.group(2))
54
61
  return None
55
62
 
56
63
 
@@ -59,17 +66,25 @@ def _in(ref: CodeRef | None, system: str | None) -> bool:
59
66
 
60
67
 
61
68
  def bound_code(value, system: str | None = None) -> CodeRef | None:
62
- """The code the model defines an enumerated value by, if it is one (in `system`, when given)."""
69
+ """The code the model defines an enumerated value by, if it is one (in `system`, when given): a code system's
70
+ concept, or an entry in a code list."""
63
71
  ref = code_of(value.code.defined_by) if getattr(value, "code", None) else None
64
72
  return ref if _in(ref, system) else None
65
73
 
66
74
 
67
75
  def linked_code(value, system: str | None = None, predicates=CONCEPT_LINKS) -> CodeRef | None:
68
- """The first code the component links to (in `system`, when given), by the predicates in order."""
76
+ """The code the component links to (in `system`, when given), by the predicates in order: a code system's concept
77
+ only, never a `#fragment` (a link names a concept; a fragment in a link is a term or a page anchor).
78
+
79
+ An exact match is the component's concept. A subject is, only when it is the component's one subject: several
80
+ subjects are the parts of a compound concept (NIH's "Are you pregnant now?" is Person + Current + Pregnancy), no
81
+ part alone is the component, so a compound gives no code (4.3.2)."""
69
82
  links = getattr(value, "links", None) or {}
70
83
  for predicate in predicates:
71
- for iri in links.get(predicate, []):
72
- ref = code_of(iri)
84
+ refs = [r for r in (code_of(iri, code_lists=False) for iri in links.get(predicate, [])) if r is not None]
85
+ if predicate == SUBJECT and len(refs) > 1:
86
+ return None
87
+ for ref in refs:
73
88
  if _in(ref, system):
74
89
  return ref
75
90
  return None
@@ -78,5 +93,6 @@ def linked_code(value, system: str | None = None, predicates=CONCEPT_LINKS) -> C
78
93
  def model_codes(value) -> set[str]:
79
94
  """Every code the model names for a value: its enumeration value's definition and the component's concept links.
80
95
  A target code that is one of these came from the model."""
81
- refs = [bound_code(value)] + [code_of(i) for p in CONCEPT_LINKS for i in (getattr(value, "links", None) or {}).get(p, [])]
96
+ refs = [bound_code(value)] + [code_of(i, code_lists=False)
97
+ for p in CONCEPT_LINKS for i in (getattr(value, "links", None) or {}).get(p, [])]
82
98
  return {r.code for r in refs if r}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdc-mapper
3
- Version: 4.3.0
3
+ Version: 4.3.2
4
4
  Summary: The shared core of the Semantic Data Charter's Governed Data Record mappers: validate, resolve, map, and report every value; MCP server included.
5
5
  Author: Axius SDC, Inc.
6
6
  License-Expression: Apache-2.0
@@ -33,7 +33,7 @@ target could say it too. Every call is appended to a hash-chained log that holds
33
33
  Each target format is its own package (`sdc-gdr2ubl`, `sdc-gdr2edifact`, `sdc-gdr2omop`, ...) registered under the
34
34
  entry-point group `sdc_mapper.targets`. Outbound only. Apache 2.0.
35
35
 
36
- **Status:** 4.3.0. Five target mappers are released: `sdc-gdr2ubl` (OASIS UBL 2.3), `sdc-gdr2edifact` (UN/EDIFACT
36
+ **Status:** 4.3.2. Five target mappers are released: `sdc-gdr2ubl` (OASIS UBL 2.3), `sdc-gdr2edifact` (UN/EDIFACT
37
37
  D.24A), `sdc-gdr2omop` (OMOP CDM 5.4), `sdc-gdr2fhir` (HL7 FHIR R4) and `sdc-gdr2hl7v2` (HL7 v2.5.1).
38
38
 
39
39
  ## Use
@@ -82,3 +82,41 @@ def test_join_depth_orders_deferred_writes():
82
82
  a, b, c = ("x:A", ()), ("x:B", JOIN), ("x:C", JOIN)
83
83
  assert join_depth([a]) == -1 and join_depth([a, b]) == 1 and join_depth([b, a, c]) == 2
84
84
  assert LOOKUP_TRANSFORMS == {"binding", "link"}
85
+
86
+
87
+ @pytest.mark.parametrize("iri", ["https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DEMO_J.htm#SEQN",
88
+ "http://www.w3.org/ns/prov#Entity", "http://www.w3.org/2000/01/rdf-schema#label"])
89
+ def test_a_term_or_a_page_anchor_is_no_concept_code(iri, tmp_path):
90
+ """4.3.1: a `#fragment` in a concept link is a vocabulary term or an anchor on a page, not a code."""
91
+ assert code_of(iri, code_lists=False) is None
92
+ rs = resolved()
93
+ v = _value_with(rs, links={"http://www.w3.org/2004/02/skos/core#exactMatch": [iri, "https://loinc.org/8480-6/"]})
94
+ rs.values[v.position] = v
95
+ assert model_codes(v) == {"8480-6"}, "the link to LOINC is a code; the fragment is not"
96
+ p = next(p for p in place(rs, mapping(tmp_path, [{"component": v.ct_id, "to": "/x:Code", "transform": "link"}]))[0]
97
+ if p.value.position == v.position)
98
+ assert p.text == "8480-6"
99
+ only = _value_with(rs, links={"http://www.w3.org/2004/02/skos/core#exactMatch": [iri]})
100
+ rs.values[only.position] = only
101
+ with pytest.raises(MappingError, match="links to no code"):
102
+ place(rs, mapping(tmp_path, [{"component": only.ct_id, "to": "/x:Code", "transform": "link"}]))
103
+
104
+
105
+ def test_a_code_list_entry_still_binds_an_enumerated_value():
106
+ assert code_of(f"{UBL_LIST}#2") == CodeRef(UBL_LIST, "2")
107
+ assert code_of(f"{UBL_LIST}#2", code_lists=False) is None
108
+
109
+
110
+ def test_a_compound_concept_gives_no_linked_code():
111
+ """4.3.2: several subjects are the parts of a compound concept; no part alone is the component."""
112
+ from sdc_mapper import linked_code, NCIT
113
+ rs = resolved()
114
+ subject = "http://purl.org/dc/terms/subject"
115
+ parts = ["http://purl.obolibrary.org/obo/NCIT_C25190", "http://purl.obolibrary.org/obo/NCIT_C25471", "http://purl.obolibrary.org/obo/NCIT_C25742"]
116
+ compound = _value_with(rs, links={subject: parts})
117
+ assert linked_code(compound) is None and linked_code(compound, NCIT) is None
118
+ one = _value_with(rs, links={subject: ["http://snomed.info/id/73211009"]})
119
+ assert linked_code(one).code == "73211009", "a single subject is the component's concept"
120
+ exact = _value_with(rs, links={"http://www.w3.org/2004/02/skos/core#exactMatch": ["https://loinc.org/8480-6/"], subject: parts})
121
+ assert linked_code(exact).code == "8480-6", "an exact match wins over a compound's parts"
122
+ assert model_codes(compound) == {"C25190", "C25471", "C25742"}, "the parts are still codes the model names"
File without changes
File without changes
File without changes