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

Update AEMPSconn with the new structure #16

Merged
merged 20 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
per-file-ignores = __init__.py:F401
67 changes: 67 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Check Code Lint & Poetry Configuration
on:
pull_request:
push:
branches:
- dev
jobs:
ci:
# Set up operating system
runs-on: ubuntu-latest

# Define job steps
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Check-out repository
uses: actions/checkout@v3

- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry

- name: Install poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: ~/.venv
installer-parallel: true

- name: Install black
run: poetry run pip install black

- name: Restore cached dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: Install package
run: poetry install

- name: Lint
run: |
poetry run black --check --diff src/
poetry run flake8 src/

#- name: Test with pytest
# run: poetry run pytest tests/ --cov=aempsconn --cov-report=xml

#- name: Use Codecov to track coverage
# uses: codecov/codecov-action@v3
# with:
# files: ./coverage.xml # coverage report

#- name: Build documentation
# run: poetry run make html --directory docs/
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.17
uses: JRubics/poetry-publish@v2.0
with:
pypi_token: ${{ secrets.PYPI }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode*
no_load*
45 changes: 32 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
repos:
- repo: https://github.com/ambv/black
rev: 23.9.1
hooks:
- id: black
language_version: python3.11
- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: pytest
language: system
pass_filenames: false
always_run: true
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
language_version: python3

- repo: https://github.com/jsh9/pydoclint
rev: 0.4.1
hooks:
- id: pydoclint
args: [--style=google, --check-return-types=True, --skip-checking-short-docstrings=False]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args:
- '--max-line-length=120'
- '--per-file-ignores=*/__init__.py:F401'

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

111 changes: 33 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# AEMPSconn
Library designed for interacting with the CIMA REST API ([AEMPS](https://cima.aemps.es/cima/publico/home.html)).
More information related to the official REST API can be found [here](https://cima.aemps.es/cima/resources/docs/CIMA_REST_API.pdf).
Library designed for interacting with the CIMA REST API ([AEMPS](https://cima.aemps.es/cima/publico/home.html)).
More information related to the official REST API can be found [here](https://cima.aemps.es/cima/resources/docs/CIMA_REST_API.pdf).

*Note: AEMPSconn is developed to make use of it with [CIMA REST API v1.23](https://cima.aemps.es/cima/resources/docs/CIMA_REST_API.pdf).*


## Testing
**Unit-tests for this new version are under development.**


## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install aempsconn.
Expand All @@ -12,96 +17,46 @@ Use the package manager [pip](https://pip.pypa.io/en/stable/) to install aempsco
pip install aempsconn
```

## Custom Logger
The use of the `logger` in the library **is not mandatory**.

A *custom logger* has been created in order to offer the possibility to use it in an integrated way with the library and it allows you to set the logging level.

However, as the `logger` argument requires a Logger type, it is fully customizable so that the programmer can set it according to his own preferences.

**To not use any logger, simply leave it blank.**

## Building queries
It has developed a easy-use query builder for the most important endpoints: `/medicamento` & `/medicamentos`.
Each endpoint has its own custom filters so you can find and add them to the request by:

```python
import aempsconn

aemps = aempsconn.Orchestrate(logger=aempsconn.CustomLogger(level=50))

filter_med = aemps.filter_medicamento.<FILTER_CONDITION_MED>.equals(value=<VALUE>)
filter_meds = aemps.filter_medicamentos.<FILTER_CONDITION_MEDS>.equals(value=<VALUE>)
```

This query builder supports as many conditions/filters as you want.
Be noted that the the first endpoint (`/medicamento`) **will only make use of the last condition set**, since it only admits a single condition.

## Handling errors
The library comes with custom exceptions for error handling.
This exceptions are the following:

- _aempsconn.errors.HTTPFailure_
Custom exception related to the HTTP requests.

- _aempsconn.errors.JSONDecodeFailure_
Custom exception related to JSON decode.

- _aempsconn.errors.JSONKeyFailure_
Custom exception related to JSON dict's keys.

- _aempsconn.errors.ProxyFailure_
Custom exception related to the proxy configuration.

- _aempsconn.errors.RequestFailure_
Custom exception related to the Python3 request module.

- _aempsconn.errors.TimeoutFailure_
Custom exception related to the timeout.
## Usage
Each module has embedded in it the only type of filter it supports.
The filters are created dynamically so depending on the type of data you want to obtain, it will ask for the type of value required for it.

- _aempsconn.errors.UnhandledError_
Custom exception related to unhandled exceptions.
If you want to filter by more than one value, simply concatenate all the desired filters, the query-builder will create the necessary query.

## Usage
```python
import aempsconn
from aempsconn.aemps import AempsConn
from aempsconn.filter import (
MedicamentoFilter,
MedicamentosFilter,
PresentacionesFilter,
VmppFilter,
)

# Initialize all the modules with the same configuration.
aemps = aempsconn.Orchestrate(logger=aempsconn.CustomLogger(level=50))
# or initialize all the modules without the Logger or any other custom settings
aemps = aempsconn.Orchestrate()
aemps = AempsConn()

# Create a filter needed for the wanted request.
# This filter is custom for "/medicamento" endpoint.
filter1 = aemps.filter_medicamento.num_registro.equals("59494")
# Download the med that satisfies the previous custom filter.
med = aemps.medicamento.get(filter=filter1)
for med in aemps.medicamento.get(
filter=MedicamentoFilter().nregistro.equals(value="62121")
):
print(med.nombre)

# If med is not null prints the name.
if med is not None:
for med in aemps.medicamentos.get(
filter=MedicamentosFilter().nombre.startswith(value="meto")
):
print(med.nombre)

# Create a new filter needed for the wanted request.
# This filter is custom for "/medicamentos" endpoint.
filter2 = (
aemps.filter_medicamentos.nombre.equals("paraceta*")
.comercializado.equals(True)
.laboratorio.equals("cinfa")
.receta.equals(True)
)
# Download all the meds that satisfy the previous custom filter.
meds = aemps.medicamentos.get(filter=filter2)
for med in aemps.presentaciones.get(
filter=PresentacionesFilter().vmp.equals("270671000140106")
):
print(med.nombre)

# If meds are not null iterates and prints the names.
if meds is not None:
for med in meds:
print(med.nombre)
for desc_cli in aemps.vmpp.get(filter=VmppFilter().nombre.contains("metotrexato")):
print(desc_cli.vmpDesc)

```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Expand Down
4 changes: 0 additions & 4 deletions aempsconn/__init__.py

This file was deleted.

18 changes: 0 additions & 18 deletions aempsconn/datatypes/__init__.py

This file was deleted.

20 changes: 0 additions & 20 deletions aempsconn/datatypes/atc.py

This file was deleted.

25 changes: 0 additions & 25 deletions aempsconn/datatypes/documento.py

This file was deleted.

20 changes: 0 additions & 20 deletions aempsconn/datatypes/elemento.py

This file was deleted.

20 changes: 0 additions & 20 deletions aempsconn/datatypes/estado.py

This file was deleted.

Loading
Loading