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

Package refactoring #13

Merged
merged 4 commits into from
Oct 29, 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
48 changes: 42 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Introduction

MIABIS is focused on standardizing the data elements used to describe biobanks, research on samples, and related data.
The goal of MIABIS is to enhance interoperability among biobanks that share valuable data and samples. MIABIS Core 2.0,
introduced in 2016, established general attributes at an aggregated/metadata level for describing biobanks, sample
Expand All @@ -10,8 +12,28 @@ The foundation for this FHIR profile (all the attributes defined by MIABIS) is a

The MIABIS on FHIR profile full specification along with the guide is available on the [simplifier platform](https://simplifier.net/miabis).

This Python package provides a set of classes that can be used to create, read, and validate MIABIS on FHIR resources, as well as to convert them to and from JSON format.
This package aims to allow developers to easily work with MIABIS on FHIR resources in Python, while ensuring that the resources are compliant with the MIABIS on FHIR profile.
## Modules

### 1. `MIABIS_on_FHIR`
The `MIABIS_on_FHIR` module includes a set of classes to help developers:
- **Create** MIABIS on FHIR resources.
- **Read** and **validate** these resources.
- **Convert** resources to and from JSON format.

This module ensures compliance with the MIABIS on FHIR profile, allowing developers to handle MIABIS resources confidently and efficiently in Python.

### 2. `blaze_client`
The `blaze_client` module simplifies communication with the [Samply.blaze](https://github.com/samply/blaze) FHIR storage server. Samply.blaze is a FHIR-compliant database designed for managing and storing FHIR resources. This module provides:
- **Streamlined communication** with Samply.blaze, abstracting away the need for direct JSON response handling.
- **BlazeClient** methods that simplify operations with the server, focusing on ease of use and minimizing boilerplate code.

## Key Features
- **Compliance**: Ensures MIABIS on FHIR resources meet the profile standards.
- **Ease of Use**: Abstracts complex JSON interactions for a streamlined experience.
- **Blaze Integration**: Seamless integration with Samply.blaze for FHIR resource management.

This package is ideal for developers looking to work with MIABIS on FHIR resources and interact with FHIR storage servers using Python.


## Installation
```bash
Expand All @@ -24,10 +46,24 @@ Here is how you can create a MIABIS on FHIR sample resource:
from src.MIABIS_on_FHIR import Sample
from src.MIABIS_on_FHIR import StorageTemperature

sample = Sample("sampleId", "donorId", "Blood", storage_temperature=StorageTemperature.TEMPERATURE_GN,
sample = Sample("sampleId", "donorId", "Urine", storage_temperature=StorageTemperature.TEMPERATURE_ROOM,
use_restrictions="No restrictions")
# Convert the MoFSample object to a FHIR resource
# Convert the Sample object to a FHIR resource
sample_resource = sample.to_fhir("donorId")
# Convert the FHIR resource to a JSON string
sample_json = sample_resource.to_json()
```
sample_json = sample_resource.as_json()
```

Here is an example on how to communicate with blaze server via the BlazeClient:

```python
import datetime
from src.MIABIS_on_FHIR import Gender
from src.blaze_client import BlazeClient
from src.MIABIS_on_FHIR import SampleDonor

client = BlazeClient("example_url","username","password")

donor = SampleDonor("donorId", Gender.MALE, birth_date=datetime.datetime(year=2000,month=12,day=12))
donor_fhir_id = client.upload_donor(donor)
```
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "MIABIS_on_FHIR"
version = "1.0.0"
version = "1.1.1dev01"
description = "Library containing classes for easier handling of data according to the MIABIS on FHIR profile"
readme = "README.md"
authors = [{"name" = "Simon Konar", "email" = "[email protected]"}]
Expand All @@ -16,13 +16,21 @@ classifiers = [
keywords = ["MIABIS", "FHIR", "model" , "profile", "data", "handling"]
dependencies = [
"simple-icd-10 >= 2.0.0",
"fhirclient >= 4.2.1"
"fhirclient >= 4.2.1",
"requests >= 2.32",
"python-dateutil >= 2.9.0"

]
requires-python = ">=3.11"

[project.optional-dependencies]
test=["requests >= 2.32.0"]
test=["pytest >= 8.3.0"]

[tool.setuptools]
package-dir = { "" = "src" }


[tool.setuptools.packages.find]
where = ["src"]
include = ["MIABIS_on_FHIR*", "blaze_client*"]
exclude =["test*"]
13 changes: 13 additions & 0 deletions src/MIABIS_on_FHIR/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .biobank import Biobank
from .collection import Collection
from .collection_organization import CollectionOrganization
from .condition import Condition
from .diagnosis_report import DiagnosisReport
from .gender import Gender
from .incorrect_json_format import IncorrectJsonFormatException
from .network import Network
from .network_organization import NetworkOrganization
from .observation import Observation
from .sample import Sample
from .sample_donor import SampleDonor
from .storage_temperature import StorageTemperature
20 changes: 10 additions & 10 deletions src/MIABIS_on_FHIR/biobank.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from fhirclient.models.meta import Meta
from fhirclient.models.organization import Organization

from src.MIABIS_on_FHIR.util._constants import BIOBANK_BIOPROCESSING_AND_ANALYTICAL_CAPABILITIES, \
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.constants import BIOBANK_BIOPROCESSING_AND_ANALYTICAL_CAPABILITIES, \
BIOBANK_INFRASTRUCTURAL_CAPABILITIES, \
BIOBANK_ORGANISATIONAL_CAPABILITIES, DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_contact
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier, create_contact, create_country_of_residence, \
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_contact
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier, create_contact, create_country_of_residence, \
create_codeable_concept_extension, create_string_extension
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig


class Biobank:
Expand All @@ -30,14 +30,14 @@ def __init__(self, identifier: str, name: str, alias: str, country: str, contact
:param contact_surname: surname of the contact person
:param contact_email: email of the contact person
:param infrastructural_capabilities: The technical infrastructural capabilities that
the biobank can offer to the clients. Available values in the _constants.py file
the biobank can offer to the clients. Available values in the constants.py file
:param organisational_capabilities: The organisational capabilities and services that
the biobank can provide to support clients. Available values in the _constants.py file
the biobank can provide to support clients. Available values in the constants.py file
:param bioprocessing_and_analysis_capabilities: The bioprocessing and analytical services
that the biobank can offer to the clients. Available values in the _constants.py file
that the biobank can offer to the clients. Available values in the constants.py file
:param quality__management_standards: The standards that the biobank is certified or accredited for.
:param juristic_person: The legal entity that is responsible for the biobank.
Available values in the _constants.py file
Available values in the constants.py file
"""
self.identifier = identifier
self.name = name
Expand Down Expand Up @@ -316,7 +316,7 @@ def to_fhir(self) -> Organization:
self.juristic_person))
if self.description is not None:
extensions.append(create_string_extension(
FHIRConfig.get_extension_url("biobank","description"),
FHIRConfig.get_extension_url("biobank", "description"),
self.description))
if extensions:
fhir_organization.extension = extensions
Expand Down
15 changes: 7 additions & 8 deletions src/MIABIS_on_FHIR/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
from fhirclient.models.quantity import Quantity
from fhirclient.models.range import Range

from src.MIABIS_on_FHIR.util._constants import COLLECTION_INCLUSION_CRITERIA, COLLECTION_MATERIAL_TYPE_CODES, \
DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier, create_integer_extension, \
create_codeable_concept_extension, \
create_codeable_concept
from src.MIABIS_on_FHIR.gender import Gender
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.MIABIS_on_FHIR.storage_temperature import StorageTemperature
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.constants import COLLECTION_INCLUSION_CRITERIA, COLLECTION_MATERIAL_TYPE_CODES
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier, create_integer_extension, \
create_codeable_concept_extension, \
create_codeable_concept


class Collection:
Expand All @@ -40,7 +39,7 @@ def __init__(self, identifier: str, name: str, managing_collection_org_id: str,
:param storage_temperatures: List of storage temperatures of the samples in the collection.
:param material_types: List of material types of the samples in the collection.
:param diagnoses: List of diagnoses of the subjects in the collection.
Available values in the _constants.py file
Available values in the constants.py file
:param number_of_subjects: Number of subjects in the collection.
:param inclusion_criteria: Inclusion criteria for the subjects in the collection.
:param sample_ids: List of sample identifiers belonging to the collection.
Expand Down
21 changes: 10 additions & 11 deletions src/MIABIS_on_FHIR/collection_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
from fhirclient.models.meta import Meta
from fhirclient.models.organization import Organization

from src.MIABIS_on_FHIR.util._constants import COLLECTION_DESIGN, COLLECTION_SAMPLE_COLLECTION_SETTING, \
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.constants import COLLECTION_DESIGN, COLLECTION_SAMPLE_COLLECTION_SETTING, \
COLLECTION_SAMPLE_SOURCE, COLLECTION_DATASET_TYPE, COLLECTION_USE_AND_ACCESS_CONDITIONS
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_contact, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_country_of_residence, create_contact, \
create_codeable_concept_extension, \
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_contact, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_country_of_residence, create_contact, create_codeable_concept_extension, \
create_string_extension, create_fhir_identifier
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig


class CollectionOrganization:
Expand Down Expand Up @@ -43,12 +42,12 @@ def __init__(self, identifier: str, name: str, managing_biobank_id: str,
:param alias: Alias of the collection.
:param url: URL of the collection.
:param description: Description of the collection.
:param dataset_type: Type of the dataset. Available values in the _constants.py file
:param sample_source: Source of the samples. Available values in the _constants.py file
:param sample_collection_setting: Setting of the sample collection. Available values in the _constants.py file
:param collection_design: Design of the collection. Available values in the _constants.py file
:param dataset_type: Type of the dataset. Available values in the constants.py file
:param sample_source: Source of the samples. Available values in the constants.py file
:param sample_collection_setting: Setting of the sample collection. Available values in the constants.py file
:param collection_design: Design of the collection. Available values in the constants.py file
:param use_and_access_conditions: Conditions for use and access of the collection.
Available values in the _constants.py file
Available values in the constants.py file
:param publications: Publications related to the collection.
"""

Expand Down
8 changes: 4 additions & 4 deletions src/MIABIS_on_FHIR/condition.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import Self

import fhirclient.models.condition as fhir_condition
import simple_icd_10 as icd10
from fhirclient.models.codeableconcept import CodeableConcept
from fhirclient.models.coding import Coding
from fhirclient.models.fhirreference import FHIRReference
from fhirclient.models.meta import Meta

from src.MIABIS_on_FHIR.util._constants import DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier


class Condition:
Expand Down
7 changes: 3 additions & 4 deletions src/MIABIS_on_FHIR/diagnosis_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from fhirclient.models.fhirreference import FHIRReference
from fhirclient.models.meta import Meta

from src.MIABIS_on_FHIR.util._constants import DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier


class DiagnosisReport:
Expand Down
6 changes: 3 additions & 3 deletions src/MIABIS_on_FHIR/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from fhirclient.models.group import Group
from fhirclient.models.meta import Meta

from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier


class Network:
Expand Down
10 changes: 5 additions & 5 deletions src/MIABIS_on_FHIR/network_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from fhirclient.models.meta import Meta
from fhirclient.models.organization import Organization

from src.MIABIS_on_FHIR.util._constants import NETWORK_COMMON_COLLAB_TOPICS, DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_contact, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier, create_contact, create_country_of_residence, \
create_codeable_concept_extension, create_string_extension
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.constants import NETWORK_COMMON_COLLAB_TOPICS
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_contact, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier, create_contact, create_country_of_residence, \
create_codeable_concept_extension, create_string_extension


class NetworkOrganization:
Expand Down
10 changes: 4 additions & 6 deletions src/MIABIS_on_FHIR/observation.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from datetime import datetime
from dateutil import parser as date_parser
from typing import Self

import fhirclient.models.observation as fhir_observation
import simple_icd_10 as icd10
from dateutil import parser as date_parser
from dateutil.parser import ParserError
from fhirclient.models.codeableconcept import CodeableConcept
from fhirclient.models.coding import Coding
from fhirclient.models.fhirdate import FHIRDate
from fhirclient.models.fhirdatetime import FHIRDateTime
from fhirclient.models.fhirreference import FHIRReference
from fhirclient.models.meta import Meta

from src.MIABIS_on_FHIR.util._constants import DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier


class Observation:
Expand Down
10 changes: 5 additions & 5 deletions src/MIABIS_on_FHIR/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from fhirclient.models.meta import Meta
from fhirclient.models.specimen import Specimen, SpecimenCollection, SpecimenProcessing

from src.MIABIS_on_FHIR.util._constants import DETAILED_MATERIAL_TYPE_CODES, DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier, create_codeable_concept, \
create_codeable_concept_extension
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.MIABIS_on_FHIR.storage_temperature import StorageTemperature
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.constants import DETAILED_MATERIAL_TYPE_CODES
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value, parse_reference_id
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier, create_codeable_concept, \
create_codeable_concept_extension


class Sample:
Expand Down
8 changes: 4 additions & 4 deletions src/MIABIS_on_FHIR/sample_donor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from fhirclient.models.meta import Meta
from fhirclient.models.patient import Patient

from src.MIABIS_on_FHIR.util._constants import DONOR_DATASET_TYPE, DEFINITION_BASE_URL
from src.MIABIS_on_FHIR.util._parsing_util import get_nested_value
from src.MIABIS_on_FHIR.util._util import create_fhir_identifier, create_codeable_concept_extension
from src.MIABIS_on_FHIR.gender import Gender
from src.MIABIS_on_FHIR.incorrect_json_format import IncorrectJsonFormatException
from src.config import FHIRConfig
from src.MIABIS_on_FHIR.util.config import FHIRConfig
from src.MIABIS_on_FHIR.util.constants import DONOR_DATASET_TYPE
from src.MIABIS_on_FHIR.util.parsing_util import get_nested_value
from src.MIABIS_on_FHIR.util.util import create_fhir_identifier, create_codeable_concept_extension


class SampleDonor:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dateutil import parser as date_parser
from datetime import date

from src.MIABIS_on_FHIR.util._constants import DETAILED_MATERIAL_TYPE_TO_COLLECTION_MATERIAL_TYPE_MAP
from src.MIABIS_on_FHIR.util.constants import DETAILED_MATERIAL_TYPE_TO_COLLECTION_MATERIAL_TYPE_MAP


def get_nested_value(data: dict, keys: list):
Expand Down
File renamed without changes.
Empty file removed src/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions src/blaze_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .blaze_client import BlazeClient
from .NonExistentResourceException import NonExistentResourceException
Loading
Loading