-
Notifications
You must be signed in to change notification settings - Fork 4
BDMS-139: Create Parameter table
#152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
09dbfc0
feat: create new `Parameter` model and add it to the `__init__.py` file.
ksmuczynski 6ce3e6f
feat: create new `regulatory_limit` table.
ksmuczynski 14461fb
refactor: remove TODO from `regulatory_limit` table.
ksmuczynski fb67f57
refactor: modify the TODO in the `parameter` table.
ksmuczynski a5e8d37
refactor: modify comment for `limit_source` field.
ksmuczynski a871a2c
Merge branch 'staging' into parameter_model
ksmuczynski 4e2c683
feat: add `parameter` relationship and foreign key to`Observation` mo…
ksmuczynski f0ef0a8
Formatting changes
ksmuczynski 22f2626
refactor: update relationship name from `reg_limit` to `regulatory_li…
ksmuczynski ba29abd
Merge remote-tracking branch 'origin/parameter_model' into parameter_…
ksmuczynski 39ce40e
refactor: fix typo in `cas_number` comment
ksmuczynski 808f8ca
feat: add 'matrix' field and unique constraint to `Parameter` table.
ksmuczynski 3e7bd0e
feat: add `RegulatoryLimit` model to the `db/__init__.py` file so it …
ksmuczynski ac2b0d0
refactor: updated the `lexicon.json` file to use the new normalized s…
ksmuczynski 938ee3a
Merge branch 'staging' into parameter_model
jirhiker 6e3b5e9
refactor: fix pytest failures
ksmuczynski cfdf8ea
fix: don't restrict lexicon strings
jacob-a-brown 404b0b0
fix: eagerly load parameters
jacob-a-brown 0710483
fix: use function scopes for fixtures to prevent queue pool limit
jacob-a-brown 8879457
fix: coalesce contatinated contact search to prevent null from breaki…
jacob-a-brown 77a541f
reversion: add pytest back to pre commit hooks
jacob-a-brown 5e10768
refactor: Merge staging
ksmuczynski da5170e
refactor: initialize parameters
jacob-a-brown a74f404
Merge branch 'parameter_model' of https://github.com/DataIntegrationG…
jacob-a-brown d39b3db
Merge branch 'staging' into parameter_model
jirhiker ed5971d
Update test_observation.py
jirhiker 1dad9c0
refactor: update test_observation.py to remove redundant assertions a…
jirhiker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [ | ||
| { | ||
| "parameter_name": "groundwater level", | ||
| "matrix": "groundwater", | ||
| "parameter_type": "Field Parameter", | ||
| "cas_number": null, | ||
| "default_unit": "ft" | ||
| }, | ||
| { | ||
| "parameter_name": "pH", | ||
| "matrix": "groundwater", | ||
| "parameter_type": "Field Parameter", | ||
| "cas_number": null, | ||
| "default_unit": "dimensionless" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """ | ||
| This table is a controlled vocabulary for all analytes, properties, and | ||
| characteristics that can be measured or observed. | ||
| """ | ||
|
|
||
| from typing import List, TYPE_CHECKING | ||
|
|
||
| from sqlalchemy.orm import relationship, Mapped, mapped_column | ||
|
|
||
| from db.base import Base, AutoBaseMixin, ReleaseMixin, lexicon_term | ||
|
|
||
| if TYPE_CHECKING: | ||
| from db.observation import Observation | ||
| from db.regulatory_limit import RegulatoryLimit | ||
|
|
||
|
|
||
| class Parameter(Base, AutoBaseMixin, ReleaseMixin): | ||
| """ | ||
|
|
||
| Represents an analyte or property that can be measured (e.g., Chloride). | ||
| """ | ||
|
|
||
| __versioned__ = {} | ||
|
|
||
| # --- Columns --- | ||
| # TODO: Parameter names are currently associated with the 'observed_property' category in the lexicon. Should we update the lexicon category name to 'parameter_name'? | ||
| parameter_name: Mapped[str] = lexicon_term( | ||
| nullable=False, | ||
| comment="The official, full name of the parameter (e.g., 'Arsenic, Dissolved').", | ||
| ) | ||
| matrix: Mapped[str] = lexicon_term( | ||
| nullable=False, | ||
| comment="A controlled vocabulary field defining the physical medium the analyte is measured in (e.g., 'Water', 'Soil', 'Air').", | ||
| ) | ||
|
ksmuczynski marked this conversation as resolved.
|
||
| parameter_type: Mapped[str] = lexicon_term( | ||
| nullable=True, | ||
| comment="A controlled vocabulary field defining the category of the parameter (e.g., 'Metals', 'Nutrients', 'Field Parameter'). Used for grouping and filtering.", | ||
| ) | ||
| cas_number: Mapped[str] = mapped_column( | ||
| nullable=True, | ||
| comment="The Chemical Abstracts Service (CAS) registry number, a globally unique identifier for a chemical substance.", | ||
| ) | ||
| default_unit: Mapped[str] = lexicon_term( | ||
| nullable=False, | ||
| comment="The standard, preferred unit for reporting this parameter (e.g., 'ug/L', 'mg/L', 'pH units').", | ||
|
ksmuczynski marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| # --- Relationships --- | ||
| # One-To-Many: A Parameter can have many Observations. | ||
| observations: Mapped[List["Observation"]] = relationship( | ||
| "Observation", back_populates="parameter" | ||
| ) | ||
|
|
||
| # One-To-Many: A Parameter can have many associated RegulatoryLimits. | ||
| # If a Parameter is deleted, all its associated limits are deleted as well. | ||
| regulatory_limits: Mapped[List["RegulatoryLimit"]] = relationship( | ||
| "RegulatoryLimit", back_populates="parameter", cascade="all, delete-orphan" | ||
| ) | ||
|
|
||
| # --- Table Arguments --- | ||
| # An analyte is defined by its name and matrix. This constraint | ||
| # ensures a single, specific analyte can only be defined once. | ||
| from sqlalchemy import UniqueConstraint | ||
|
|
||
| __table_args__ = ( | ||
| UniqueConstraint("parameter_name", "matrix", name="uq_parameter_name_matrix"), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """ | ||
| This table stores the various regulatory or health-based limits for a given | ||
| parameter, sourced from different agencies or standards. | ||
|
ksmuczynski marked this conversation as resolved.
|
||
|
|
||
| The purpose of this table is to solve the real-world problem where a single | ||
| chemical (`Parameter`) can have multiple different limits set by various agencies | ||
| (e.g., a federal EPA limit and a state-level NMED limit). | ||
| """ | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from sqlalchemy import Integer, Numeric, ForeignKey | ||
| from sqlalchemy.orm import relationship, Mapped, mapped_column | ||
|
|
||
| from db.base import Base, AutoBaseMixin, ReleaseMixin, lexicon_term | ||
|
|
||
| if TYPE_CHECKING: | ||
| from db.parameter import Parameter | ||
|
|
||
|
|
||
| class RegulatoryLimit(Base, AutoBaseMixin, ReleaseMixin): | ||
| """ | ||
| Represents a single, citable regulatory or health-based limit for a | ||
| specific Parameter. | ||
| """ | ||
|
|
||
| __versioned__ = {} | ||
|
|
||
| # --- Foreign Keys --- | ||
| parameter_id: Mapped[int] = mapped_column( | ||
| Integer, ForeignKey("parameter.id"), nullable=False | ||
| ) | ||
|
|
||
| # --- Columns --- | ||
| limit_source: Mapped[str] = lexicon_term( | ||
| nullable=False, | ||
| comment="The official source of the limit (e.g., 'EPA', 'NMED', 'EPA').", | ||
| ) | ||
| limit_value: Mapped[float] = mapped_column(Numeric, nullable=False) | ||
| limit_unit: Mapped[str] = lexicon_term(nullable=False) | ||
| limit_type: Mapped[str] = lexicon_term( | ||
| nullable=True, | ||
| comment="A controlled vocabulary field to categorize the limit (e.g., 'MCL', 'PQL', 'MDL', etc.).", | ||
| ) | ||
|
|
||
| # --- Relationships --- | ||
| # Many-To-One: A RegulatoryLimit is for one Parameter. | ||
| parameter: Mapped["Parameter"] = relationship( | ||
| "Parameter", back_populates="regulatory_limits" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from schemas import BaseResponseModel | ||
|
|
||
|
|
||
| # -------- RESPONSE ------- | ||
| class ParameterResponse(BaseResponseModel): | ||
| """ | ||
| Pydantic model for the response of a parameter. | ||
| This model can be extended to include additional fields as needed. | ||
| """ | ||
|
|
||
| parameter_name: str | ||
| matrix: str | ||
| parameter_type: str | None | ||
| cas_number: str | None | ||
| default_unit: str |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.