Skip to content

Commit 70d1110

Browse files
authored
Pydantic models for OBX Segments
Pydantic models for OBX Segments
2 parents 277de67 + 3ef1336 commit 70d1110

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ dependencies = [
3434
"ga4gh.cat_vrs~=0.7.1",
3535
"ga4gh.va_spec~=0.4.2",
3636
"ga4gh.vrs==2.1.3",
37-
"pyyaml ~= 6.0"
37+
"pyyaml ~= 6.0",
38+
"pydantic==2.*"
3839
]
3940
description = "biocommons.example package (namespaced)"
4041
dynamic = ["version"]

src/biocommons/models.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1+
from pydantic import BaseModel
2+
13
"""A file for models used in the converter tool"""
4+
5+
class OBXSegmentBase(BaseModel):
6+
"""Common OBX fields (1..5 without the value)."""
7+
8+
line_number: int # OBX-2
9+
10+
variant_identifier_line: str # OBX-5
11+
12+
13+
class OBXSegmentST(OBXSegmentBase):
14+
'''A class representing a segment with a string type'''
15+
16+
observation_type: str = "ST"
17+
18+
value: str
19+
20+
21+
class OBXSegmentCWE(OBXSegmentBase):
22+
'''A class representing a segment with a codeable concept type'''
23+
24+
observation_type: str = "CWE"
25+
26+
code: str
27+
28+
coding_system: str
29+
30+
label: str
31+
32+
33+
class OBXSegmentNM(OBXSegmentBase):
34+
'''A class representing a segment with a numeric type'''
35+
36+
observation_type: str = "NM"
37+
38+
value: float
39+
40+
41+
class OBXSegmentNR(OBXSegmentBase):
42+
'''A class representing a segment with a numeric range type'''
43+
44+
observation_type: str = "NR"
45+
46+
lower_bound: float
47+
48+
upper_bound: float
49+
50+
51+
class OBXSegmentGroup(BaseModel):
52+
'''A class representing one or more segments that have the same type and segment identifier (e.g., the Discrete Genetic Variant lines)'''
53+
54+
segments: list[OBXSegmentBase]
55+
56+
segment_type: str = "OBX" # OBX-1
57+
58+
observation_type: str # OBX-3
59+
60+
variant_type: int = 2 # OBX-5
61+
62+
variant_identifier: str # OBX-5
63+
64+
segment_identifier: str # OBX-3.1
65+
66+
segment_name: str # OBX 3.2
67+
68+
segment_identifier_system: str # OBX 3.3

0 commit comments

Comments
 (0)