Skip to content

Commit

Permalink
Replace core__medicationrequest code with core__medication code (#276)
Browse files Browse the repository at this point in the history
* Delete current medication request builder code

* Rename medication to medicationrequest

* Replace core__medicationrequest code with core__medication code

- core__medication no longer exists.
- core__medicationrequest now has all the "abstract where medications
  come from" logic that core__medication had and no longer retricts
  itself to just RxNorm.

Changes to the field list for core__medicationrequest:
- Dropped `dosageInstruction_text`, since no one was using it and the
  ETL strips the text anyway.
- Add reported_ref (to match reportedBoolean).
- Add category_display.
  • Loading branch information
mikix authored Aug 2, 2024
1 parent 3ccece2 commit ddfd3ef
Show file tree
Hide file tree
Showing 20 changed files with 481 additions and 667 deletions.
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,20 @@ cumulus-library generate-sql \
--target core \
--target discovery
```

## Rebuilding the Markdown table docs

We keep some generated documentation in git,
to help us keep our docs in sync with table changes.
This is stored in `docs/core-study-details.md`

You can regenerate these yourself when you make changes to table layout:
1. Rebuild the `core` study in Athena.
1. Run `generate-md` against Athena:
```sh
cumulus-library generate-md --target core [database args pointing at your athena db]
```

Then take the contents of `cumulus_library/studies/core/core_generated.md`
and paste them into `docs/core-study-details.md`
(being careful to not erase any manually entered descriptions).
4 changes: 4 additions & 0 deletions cumulus_library/.sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ schema =
'category': {
'code': True, 'system': True, 'display': False
},
'reportedBoolean': True,
'reportedReference': {
'reference': True
},
'dosageInstruction': {
'text': True,
},
Expand Down
60 changes: 0 additions & 60 deletions cumulus_library/studies/core/builder_medication.py

This file was deleted.

43 changes: 33 additions & 10 deletions cumulus_library/studies/core/builder_medicationrequest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""Module for extracting US core extensions from medicationrequests
Note: This module assumes that you have already run builder_medication,
as it leverages the core__medication table for data population"""
"""Module for generating core medicationrequest table"""

from cumulus_library import base_table_builder, base_utils
from cumulus_library.studies.core.core_templates import core_templates
Expand All @@ -14,34 +11,60 @@
"intent": [],
"authoredOn": [],
"reportedBoolean": [],
"reportedReference": sql_utils.REFERENCE,
"subject": sql_utils.REFERENCE,
"encounter": sql_utils.REFERENCE,
"dosageInstruction": ["text"],
"medicationReference": sql_utils.REFERENCE,
}
}


class MedicationRequestBuilder(base_table_builder.BaseTableBuilder):
display_text = "Creating MedicationRequest tables..."
display_text = "Creating MedicationRequest table..."

def prepare_queries(
self,
*args,
config: base_utils.StudyConfig,
**kwargs,
):
"""constructs queries related to patient extensions of interest
) -> None:
"""Constructs queries related to medication requests
:param config: A study config object
"""
code_sources = [
sql_utils.CodeableConceptConfig(
source_table="medication",
column_hierarchy=[("code", dict)],
target_table="core__medication_dn_code",
),
sql_utils.CodeableConceptConfig(
source_table="medicationrequest",
column_hierarchy=[("medicationCodeableConcept", dict)],
target_table="core__medicationrequest_dn_inline_code",
),
sql_utils.CodeableConceptConfig(
source_table="medicationrequest",
column_hierarchy=[("contained", list), ("code", dict)],
target_table="core__medicationrequest_dn_contained_code",
expected={
"code": sql_utils.CODEABLE_CONCEPT,
"id": {},
"resourceType": {},
},
extra_fields=[
("id", "contained_id"),
("resourceType", "resource_type"),
],
),
sql_utils.CodeableConceptConfig(
source_table="medicationrequest",
source_id="id",
column_hierarchy=[("category", list)],
target_table="core__medicationrequest_dn_category",
),
]
self.queries += sql_utils.denormalize_complex_objects(config.db, code_sources)
validated_schema = sql_utils.validate_schema(config.db, expected_table_cols)
self.queries.append(core_templates.get_core_template("medicationrequest", validated_schema))
self.queries += [
core_templates.get_core_template("medicationrequest", validated_schema),
]
93 changes: 0 additions & 93 deletions cumulus_library/studies/core/core_templates/medication.sql.jinja

This file was deleted.

Loading

0 comments on commit ddfd3ef

Please sign in to comment.