File tree Expand file tree Collapse file tree 4 files changed +37
-5
lines changed
healthchain/data_generators Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 99
1010from fhir .resources .codeableconcept import CodeableConcept
1111from fhir .resources .coding import Coding
12+ from healthchain .data_generators .coding_utils import create_coding
1213
1314
1415faker = Faker ()
@@ -195,11 +196,10 @@ def generate_from_valueset(ValueSet):
195196
196197 return CodeableConcept (
197198 coding = [
198- Coding (
199+ create_coding (
199200 system = value_set_instance .system ,
200201 code = code ,
201202 display = display ,
202- # extension=[Extension(value_set_instance.extension)],
203203 )
204204 ]
205205 )
Original file line number Diff line number Diff line change 1+ from typing import Optional , Dict , Any
2+
3+ # Common system URIs
4+ SNOMED_CT_URI = "http://snomed.info/sct"
5+ ICD10_URI = "http://hl7.org/fhir/sid/icd-10"
6+ LOINC_URI = "http://loinc.org"
7+
8+
9+ def create_coding (
10+ code : str ,
11+ system : str ,
12+ display : Optional [str ] = None ,
13+ version : Optional [str ] = None ,
14+ ) -> Dict [str , Any ]:
15+ """Create a standardized FHIR Coding dict.
16+
17+ Mirrors the FHIR Coding structure and keeps optional fields omitted when None,
18+ which matches how other helpers in the codebase behave.
19+ """
20+ coding : Dict [str , Any ] = {
21+ "system" : system ,
22+ "code" : code ,
23+ }
24+ if display is not None :
25+ coding ["display" ] = display
26+ if version is not None :
27+ coding ["version" ] = version
28+ return coding
29+
30+
Original file line number Diff line number Diff line change 1515from fhir .resources .period import Period
1616from fhir .resources .codeableconcept import CodeableConcept
1717from fhir .resources .coding import Coding
18+ from healthchain .data_generators .coding_utils import create_coding
1819from fhir .resources .patient import Patient
1920
2021
@@ -81,7 +82,7 @@ def generate():
8182 marital_code = faker .random_element (elements = (marital_status_dict .keys ()))
8283 return CodeableConcept (
8384 coding = [
84- Coding (
85+ create_coding (
8586 system = "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" ,
8687 code = marital_code ,
8788 display = marital_status_dict .get (marital_code ),
Original file line number Diff line number Diff line change 1414)
1515from fhir .resources .codeableconcept import CodeableConcept
1616from fhir .resources .coding import Coding
17+ from healthchain .data_generators .coding_utils import create_coding
1718
1819
1920faker = Faker ()
@@ -37,7 +38,7 @@ def generate():
3738 )
3839 return CodeableConcept (
3940 coding = [
40- Coding (
41+ create_coding (
4142 system = "http://example.org" ,
4243 code = random_qual ,
4344 display = QualificationGenerator .qualification_dict .get (random_qual ),
@@ -79,7 +80,7 @@ def generate():
7980 language = faker .random_element (elements = language_value_dict .keys ())
8081 return CodeableConcept (
8182 coding = [
82- Coding (
83+ create_coding (
8384 system = "http://terminology.hl7.org/CodeSystem/languages" ,
8485 code = language ,
8586 display = language_value_dict .get (language ),
You can’t perform that action at this time.
0 commit comments