Skip to content
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

[C4GT Community]: Implement a repository pattern using sqlite storage for GeolocationQueryService #26

Open
1 of 12 tasks
codecakes opened this issue Aug 12, 2024 · 5 comments · May be fixed by #71
Open
1 of 12 tasks
Assignees
Labels
C4GT Coding C4GT Community enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@codecakes
Copy link
Contributor

codecakes commented Aug 12, 2024

Ticket Contents

Description

Issue #12 covers a high complexity objective to implement /geo api endpoint. In order to list facilities, implement a repository to be consumed from GeolocationQueryService.

Background:

The project has 3 primary levels:

  1. IO layer: all infrastructural/mutating transactions. --> We want to implement repository storage here.
  2. application services: services that consume the domain layer and are consumed by the IO layer.
  3. domain: the ƒat business logic. --> We want to define interface signatures here.

The project src directory contains the following:

xcov19
├── app: Contains web framework, application services, routes, dto related modules.
│   ├── auth.py
│   ├── binders.py
│   ├── controllers
│   │   ├── diagnose.py
│   │   └── geolocation.py
│   ├── docs
│   │   └── binders.py
│   ├── dto.py
│   ├── errors.py
│   ├── main.py
│   ├── middleware.py
│   ├── services.py
│   └── settings.py: configuration and settings to run server with.
├── dev.py: runs server in developer mode
├── domain: contains the entities, values and aggregates for business domain context
│   ├── common.py
│   ├── models
│   │   ├── patient.py
│   │   └── provider.py
│   └── repository.py: Repository that abstracts away storage implementation and manages application logic between domain aggregate and data store for a specific context.
└── utils
    └── mixins.py

The GeolocationQueryService is an application service consumed by the web api route geo. See here.

The service needs to query the storage layer via a storage repository. This repository is called by the patient query look up service which is a callable and it calls the repository passing relevant parameters available in the set of: [Address, LocationQueryJSON, List[FacilitiesResult]] which are defined in dto.py.

In the repository pattern, extend IProviderStore interface in domain/models/provider.py and implement a provider store with implementation in sqlite to allow GeolocationQueryService to fetch healthcare providers in a storage -agnostic manner.

See You Wanted Banana and API First design for motivation

Goals

Goals

  • Understand a reproducible 'hello world' example of repository pattern
  • Identify parameters to consume in order to implement the repository
  • Identify the expected return value and edge cases for return type from repository
  • Identify type signature and annotations for interface and sqlite implementation
  • Implement the Provider Repository in order to be able to return list of facilties.
  • Have unit test coverage
  • All major use cases have been identified

Expected Outcome

  • Unit test should be able to demonstrate a fake repository implementation using a stub storage that lives only for test session. Refer to the attached wireframe for the flow.
  • The repository implementation should take in the provided parameters and return either a list of care facility records or nothing.

Acceptance Criteria

  • The implementation repository is in repository.py under apps/ module
  • The interface conforms to requirements and can be tested against in the test run.
  • All tests including Automation tests run successfully for repository

Implementation Details

The repository’s role is to handle the persistence of aggregates.

Refer to dto.py and provider.py in order to understand the flow as described here.

The Repository receives aggregate as input parameters so first think and map the necessary DTOs to aggregate. The caller service transforms DTO to aggregates.
The repository takes in and preprocesses query_id, cust_id in addition to geo location coordinates in order to call sqlite db and return a list of records, the return schema for which is defined in #12 ; The repository takes in the aggregate Provider in provider.py and performs a geo-query to filter all records that are within 50 kms of the patient's coordinates.

Query against the following tentative table attributes from the repository:

columns name type
query_id alphanumeric string
cust_id alphanumeric string
lat float
lng float
specialty array[text]

Expected return value
For each query_id and cust_id, filter down the coordinates lat and lng and return the data. Ignore the missing attributes from the attribute column that you cannot find. Let the missing return parameters be optional while maintaining strong consistency with the JSON Type format per attribute.

Mockups/Wireframes

UML sequence for xcov19

Product Name

project-healthcare

Organisation Name

XCoV19

Domain

Healthcare

Tech Skills Needed

Database, Debugging, Flask, Python, SQL, Test, Testing Library

Mentor(s)

@codecakes

Complexity

High

Category

Backend, Database, Refactoring, Testing

@codecakes codecakes added help wanted Extra attention is needed C4GT Community and removed C4GT Community labels Aug 21, 2024
@codecakes codecakes added this to the geolocation milestone Aug 21, 2024
codecakes added a commit that referenced this issue Aug 25, 2024
- Refactors codebase in order to implement requirements for #26 
- Restructures some of the dependencies to maintain project structure
around domain driven design independent of the framework.
@RISHIKESHk07
Copy link

@codecakes is this open and requier's issue #12 to be solved first ? , i would like to contribute to the issue , any deadlines or other info i need to know

@codecakes
Copy link
Contributor Author

#42

@RISHIKESHk07 Short answer: No. All issues are independent. Go ahead with the PR.

Refer to PR #42 to understand what files you would be leveraging upon in order to do this.
Ask for any doubts.

@RISHIKESHk07
Copy link

@codecakes did try running poetry install --no-root --with=dev but got the error group dev not found , i see the line commented out
image

@RISHIKESHk07
Copy link

@codecakes do i install without --with=dev flag

@codecakes
Copy link
Contributor Author

@codecakes did try running poetry install --no-root --with=dev but got the error group dev not found , i see the line commented out image

@RISHIKESHk07 The setup has been simplified. See Contributing; Let me know if this worked for you.

Brownie point if you raise a PR that fixes this setup instruction in the README.md. It should simply point to the CONTRIBUTING page.

codecakes added a commit that referenced this issue Sep 2, 2024
Implements database configuration for sqlite repo in issue #26 by:
- Implementing configure_database_session(services, settings) and
on_start
-  Adding support libraries to `pyproject.toml`
codecakes added a commit that referenced this issue Sep 9, 2024
…rface and sqlite implementation (#66)

Prepares testing support for #26 

- adds support for test markers
- `make test` works. added test-integration marker and is currently WIP.
- refactored unit tests to have dummy functions move to conftest. fix
their type annotaitons. added e2e api testing support in start_server
and conftest. added unit test configuration setup in pyproject.
codecakes added a commit that referenced this issue Sep 9, 2024
Unstable, active and WIP: This is where things start taking shape for setting test coverage
`GeoLocationServiceSqlRepoDBTest` to implement issue: #26 ;

- major rewrite of test services for integration test for Sqlite Repo
DB. refactored code to use container to setup database using
start_test_database and asyncSetUp. WIP: test_fetch_facilities
- added sqlite models to support sqlite database. database.py enhances
app level infra setup using DI using rodi's Container that sets up
database and session
@codecakes codecakes self-assigned this Sep 9, 2024
codecakes added a commit that referenced this issue Sep 11, 2024
Unstable, active and WIP: This is where things start taking shape for setting test coverage
`GeoLocationServiceSqlRepoDBTest` to implement issue: #26 ;

- major rewrite of test services for integration test for Sqlite Repo
DB. refactored code to use container to setup database using
start_test_database and asyncSetUp. WIP: test_fetch_facilities
- added sqlite models to support sqlite database. database.py enhances
app level infra setup using DI using rodi's Container that sets up
database and session
codecakes added a commit that referenced this issue Sep 22, 2024
Introduces changes to fix spatialite extension loading issue to support
data fields in sqlachemy model type `POINT`. This change directly
supports the work in #26
- Fixes spatialite extension as loadable with the updated dockerfile
setup and correct implementation using aiosqlite compatibility
- Temporary disables integration test. The repository return type needs
to be refactored and return type changed to list dto facilities results

<!-- Generated by sourcery-ai[bot]: start summary -->

## Summary by Sourcery

Fix SpatiaLite extension loading issue to support spatial data fields in
SQLAlchemy models. Introduce a new `PointType` for handling geopoint
data. Refactor test database setup and temporarily disable integration
tests pending refactoring. Update build scripts and Makefile for
improved Docker handling.

New Features:
- Introduce a new `PointType` class to handle geopoint data types in
SQLAlchemy models, enabling support for spatial data fields like
`POINT`.

Bug Fixes:
- Fix the loading of the SpatiaLite extension in the database setup to
support spatial data operations.

Enhancements:
- Refactor the test database setup to use a new `SetUpTestDatabase`
class, improving the management of test database lifecycle and session
handling.

Build:
- Update the Makefile to include a new `set-docker` target and modify
the `docker-run-server` target to remove orphan containers.

Tests:
- Temporarily disable integration tests due to the need for refactoring
repository return types and changing return types to list DTO facilities
results.

Chores:
- Update the `run.sh` script to include additional logging for file
listing and database removal.

<!-- Generated by sourcery-ai[bot]: end summary -->

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
codecakes added a commit that referenced this issue Sep 22, 2024
Introduces changes to fix spatialite extension loading issue to support
data fields in sqlachemy model type `POINT`. This change directly
supports the work in #26
- Fixes spatialite extension as loadable with the updated dockerfile
setup and correct implementation using aiosqlite compatibility
- Temporary disables integration test. The repository return type needs
to be refactored and return type changed to list dto facilities results

<!-- Generated by sourcery-ai[bot]: start summary -->

Fix SpatiaLite extension loading issue to support spatial data fields in
SQLAlchemy models. Introduce a new `PointType` for handling geopoint
data. Refactor test database setup and temporarily disable integration
tests pending refactoring. Update build scripts and Makefile for
improved Docker handling.

New Features:
- Introduce a new `PointType` class to handle geopoint data types in
SQLAlchemy models, enabling support for spatial data fields like
`POINT`.

Bug Fixes:
- Fix the loading of the SpatiaLite extension in the database setup to
support spatial data operations.

Enhancements:
- Refactor the test database setup to use a new `SetUpTestDatabase`
class, improving the management of test database lifecycle and session
handling.

Build:
- Update the Makefile to include a new `set-docker` target and modify
the `docker-run-server` target to remove orphan containers.

Tests:
- Temporarily disable integration tests due to the need for refactoring
repository return types and changing return types to list DTO facilities
results.

Chores:
- Update the `run.sh` script to include additional logging for file
listing and database removal.

<!-- Generated by sourcery-ai[bot]: end summary -->

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C4GT Coding C4GT Community enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants