Skip to content

Commit

Permalink
closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
teslajoy committed Aug 29, 2024
1 parent 1ae3d02 commit 9c25292
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions g3t_etl/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,41 +549,42 @@ def create_observations(self, subject, focus) -> list[Observation]:
id_ = self.mint_id(identifier=identifier, resource_type='Observation')
more_codings = additional_observation_codings(field_info)

focus_reference = self.to_reference(focus)
if not observation_code and focus:
# add general required Observation code based on focus of Observation
if "Specimen" in focus_reference:
code = self.populate_codeable_concept(system="https://loinc.org/",
code="68992-7",
display="Specimen-related information panel")
elif "Patient" in focus_reference:
code = self.populate_codeable_concept(system="https://loinc.org/",
code="68992-7",
display="Specimen-related information panel")
elif not observation_code and not focus:
underscored_code = inflection.underscore(field)
display = field_info.description
if not display:
display = value
code = self.populate_codeable_concept(code=underscored_code, display=display)
else:
code = observation_code

try:
observation_dict = self.render_template(f"Observation-{field}.yaml.jinja")
except Exception as e:
observation_dict = self.render_template(f"Observation.yaml.jinja")

# override the code
if 'code' in observation_dict:
code = None
if 'code' in observation_dict and not observation_code:
code = observation_dict['code']
del observation_dict['code']

focus_reference = self.to_reference(focus)
if not code:
if not observation_code and focus:
# add general required Observation code based on focus of Observation
if "Specimen" in focus_reference:
code = self.populate_codeable_concept(system="https://loinc.org/",
code="68992-7",
display="Specimen-related information panel")
elif "Patient" in focus_reference:
code = self.populate_codeable_concept(system="https://loinc.org/",
code="68992-7",
display="Specimen-related information panel")
elif not observation_code and not focus:
underscored_code = inflection.underscore(field)
display = field_info.description
if not display:
display = value
code = self.populate_codeable_concept(code=underscored_code, display=display)
else:
code = observation_code

observation = Observation(
**observation_dict,
code=code
)


observation.id = id_
observation.identifier = [identifier]
observation.subject = self.to_reference(subject)
Expand Down

0 comments on commit 9c25292

Please sign in to comment.