Skip to content

BDMS-227-231-aquifer-geology-models#248

Merged
jacob-a-brown merged 37 commits into
bdms-227from
kas-227-231-additional-well-info-models
Nov 24, 2025
Merged

BDMS-227-231-aquifer-geology-models#248
jacob-a-brown merged 37 commits into
bdms-227from
kas-227-231-additional-well-info-models

Conversation

@ksmuczynski

@ksmuczynski ksmuczynski commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

Why

This PR addresses the following problem / context:

Aquifer model:

  • Schema needs to be able to model the real-world, many-to-many relationship where a single Thing (well) can interact with multiple AquiferSystems.
  • Schema should be able to distinguish between a well penetrating an aquifer and a well screen targeting a specific aquifer.
  • Wells can encounter multiple aquifer characteristics simultaneously (e.g., both fractured and confined zones). The creation of a separate AquiferType model separates aquifer identity (name) from its characteristics (types), following proper database normalization.

Geology model:

  • Adds support for tracking geologic formations and their associations with other entities (e.g., wells)
  • Enables controlled vocabulary for formation codes and terms
  • Improves data integrity and reference structure for geologic information

The purpose of this PR is to make these intermediate updates available to @jacob-a-brown as we continue to co-work on the main BDMS-227 task.

How

Implementation summary - the following was changed / added / removed:

AQUIFER MODEL

  • Created new AquiferSystem model with controlled vocabulary fields and spatial boundary support
  • Created new AquiferType model to store observed aquifer characteristics at specific well locations (e.g., Fractured, Confined, Perched)
  • Created new ThingAquiferAssociation model to manage many-to-many relationships between Thing and AquiferSystem. This relationship focuses on a well's penetration of an aquifer.
  • Updated Thing model to include aquifer_associations relationship and association proxy for direct access to related aquifer systems
  • Updated the WellScreens model to include a new aquifer_system_id foreign key. This is important for identifying which aquifer a specific screen is monitoring

GEOLOGY MODEL

  • Created GeologicFormation model for master reference of geologic formations
  • Added ThingFormationAssociation model to link formations with things (e.g., wells)
  • Updated Thing model to support formation associations
  • Extended lexicon file to include new formation_code category and terms

Notes

Any special considerations, workarounds, or follow-up work to note?

  • This PR incorporates updates from BDMS-221: Core well information.
  • Controlled vocabularies for lithology pending further review and cleanup
  • Ensure migration scripts are applied to update database schema

jacob-a-brown and others added 18 commits November 11, 2025 11:23
…s-227-231-additional-well-info-models

# Conflicts:
#	.pre-commit-config.yaml
#	core/lexicon.json
#	tests/features/environment.py
…abulary fields

- Implemented `AquiferSystem` model for master reference of aquifer systems and hydrogeologic units
- Added table index for aquifer system name
- Included categories and terms for aquifer type and significance level
Added an association proxy, `things`, to the `AquiferSystem` model. This provides direct access to the `Thing` objects.
- Created ThingAquiferAssociation model to manage many-to-many relationships between Thing and AquiferSystem
- Updated Thing model to include aquifer_associations relationship for linking to aquifer systems
Added an `aquifers` proxy to the Thing model to directly access the AqufierSystems associated with a particular Thing.
This commit addresses the need to handle scenarios where multiple well screens may target different aquifers.

Added the aquifer_system_id foreign key to the WellScreen
model.

This creates a direct, physical link between a screened interval and
the specific hydrogeologic unit it monitors.
Comment thread core/lexicon.json Outdated
Comment thread db/aquifer_system.py Outdated
Comment thread db/aquifer_system.py
Comment thread db/thing_aquifer_association.py
… Thing relationship updates

- Introduced GeologicFormation model as a master reference for geologic formations
- Created ThingFormationAssociation model to manage many-to-many relationships between Thing and GeologicFormation, including depth interval fields
- Updated Thing model to include formation_associations relationship and association proxy for direct access to related geologic formations
@ksmuczynski ksmuczynski changed the title BDMS-227-231-aquifer-model BDMS-227-231-aquifer-geology-models Nov 17, 2025
Comment thread core/lexicon.json
Comment thread db/geologic_formation.py Outdated
Comment thread db/geologic_formation.py Outdated
Comment thread db/geologic_formation.py Outdated
Comment thread db/thing_geologic_formation_association.py
Comment thread db/thing_formation_association.py Outdated
Comment thread db/thing_geologic_formation_association.py
Replace the hardcoded `srid` in the `aquifer_system` and `geologic_formation` models with the SRID_WGS84 from constants.
…and `ThingFormationAssociation` models

Add `lazy="joined"` to `ThingAquiferAssociation` and `ThingFormationAssociation` models to eagerly load relationships.
- Refactor `lithology` field to a lexicon_term
- Add lithology values to lexicon
This is a placeholder file to allow the API to map formation names to codes. It can be  periodically updated from the authoritative source (.e.g USGS).
…formations

Add comprehensive response schemas for AquiferSystem and GeologicFormation
models. Integrate these schemas into
Thing/Well response models to provide complete geological context.

Changes:
-  Add AquiferSystemResponse with name, type, scale, and boundary fields
- Add GeologicFormationResponse with formation code, lithology, and boundary
- Add ThingFormationAssociationResponse with depth interval data
- Update WellResponse to include aquifers and formations lists
- Add field validators to convert ORM association objects to response schemas
- Update WellScreenResponse to include aquifer_system and geologic_formation
- Update CreateWellScreen and UpdateWellScreen with geological associations

@jacob-a-brown jacob-a-brown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updates from BDMS-221 have been incorporated into BDMS-227. If you merge BDMS-227 with this branch (and push back to this PR) the length of the PR will become much shorter (and it'll have the most current work).

Comment thread db/geologic_formation.py Outdated
Comment thread db/thing.py
Comment thread schemas/aquifer_system.py Outdated
Comment thread schemas/geologic_formation.py Outdated
Comment thread schemas/aquifer_system.py Outdated
Comment thread schemas/thing.py Outdated
…imary_aquifer_type`

- Add AquiferType model to store multiple aquifer characteristics per association
- Rename AquiferSystem.aquifer_type to primary_aquifer_type for clarity
- Update ThingAquiferAssociation with aquifer_types relationship
- Update related schemas to use primary_type

This enables capturing wells that encounter multiple aquifer characteristics
(e.g., both fractured and confined) without compound naming.
# Conflicts:
#	.pre-commit-config.yaml
#	core/enums.py
#	core/lexicon.json
#	db/__init__.py
#	schemas/thing.py
#	tests/features/environment.py
#	tests/features/steps/well-additional-information.py
Add eager loading to aquifer and geology relationships to the `thing` model.
Comment thread schemas/geologic_formation.py Outdated
Comment thread schemas/aquifer_system.py Outdated
Comment thread schemas/aquifer_system.py Outdated
@jacob-a-brown jacob-a-brown merged commit 31b8602 into bdms-227 Nov 24, 2025
4 checks passed
@ksmuczynski ksmuczynski deleted the kas-227-231-additional-well-info-models branch December 10, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants