cobra_db.model
Module Contents
Classes
Defines the interface to load the object from dict and how to export it to dict. |
|
Base class for an embedded doc (that doesn't get its own _id) |
|
Stores information of when the db doc was created, modified, and the data model |
|
Base class for all entities that are stored in the db with an _id, i.e. that |
|
Base class for a pointer to more information. |
|
Base class for all entities that contain dicom_tags. |
|
Pointer to another Entity instance in the database. |
|
Pointer to a file in the filesystem. |
|
Represents a unique person that has gone through at least one study. |
|
Aggregation of multiple dicom instances by the combination of patient and date. |
|
Base class for all entities that contain dicom_tags. |
|
Represents one DICOM image i.e. a DICOM instance with PixelData. |
|
Abstract class for any annotation that is stored in cobra_db. Should be subclassed |
|
Base class for all entities that are stored in the db with an _id, i.e. that |
- class cobra_db.model.BaseObj[source]
Defines the interface to load the object from dict and how to export it to dict.
- class cobra_db.model.Embedded[source]
Bases:
BaseObj
Base class for an embedded doc (that doesn’t get its own _id)
- class cobra_db.model.Metadata[source]
Bases:
Embedded
Stores information of when the db doc was created, modified, and the data model version. Should be used in any doc with _id that is stored in the database.
- model_version: str
- created: datetime.datetime
- modified: datetime.datetime
- project_name: str
- class cobra_db.model.Entity[source]
Bases:
BaseObj
Base class for all entities that are stored in the db with an _id, i.e. that require a Dao. Usually parent of a
@dataclass
class- _id: bson.ObjectId
- class cobra_db.model.DicomEntity[source]
Bases:
Entity
Base class for all entities that contain dicom_tags.
- dicom_tags: dict
- static optional(ds: pydicom.dataset.Dataset, tag_name: str, parser: Callable = None, default=None)[source]
Get tag value from dataset, if missing return default value.
- static choose_first(ds, *tag_names, parser, default)[source]
Choose first tag that does not return None,
- class cobra_db.model.EntitySource[source]
-
Pointer to another Entity instance in the database. Should only be used when there’s ambiguity about the referenced class/collection.
- name: str
- description: str
- _id: bson.ObjectId
- class cobra_db.model.FileSource[source]
-
Pointer to a file in the filesystem. rel_path is relative to the place where drive_name is mounted. This is because drive_name can be mounted in different paths according to the machine and we don’t have another way of referencing a drive. filename is automatically stored for easy indexing and querying without having to manipulate the rel_path to extract the filename.
- drive_name: str
- rel_path: str
- filename: str
- class cobra_db.model.Patient[source]
Bases:
Entity
Represents a unique person that has gone through at least one study. https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.2.2.html https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.2.3.html
- anon_id: str
- birth_date: datetime.datetime
- class cobra_db.model.RadiologicalStudy[source]
Bases:
DicomEntity
Aggregation of multiple dicom instances by the combination of patient and date.
- study_uid: List[str]
- date: datetime.datetime
- series_count: int
- patient_id: bson.ObjectId
- sop_class: List[str]
- modality: List[cobra_db.enums.Modality]
- description: str
- accession_number: List[str]
- patient_age: int
- patient_weight: float
- patient_height: float
- patient_pregnancy_status: cobra_db.enums.PregnancyStatus
- manufacturer: List[str]
- manufacturer_model_name: List[str]
- detector_id: List[str]
- detector_type: List[str]
- device_serial_number: List[str]
- software_versions: List[str]
- date_of_last_detector_calibration: List[str]
- breast_implant_present: List[str]
- classmethod from_dataset(ds: pydicom.dataset.Dataset)[source]
Create an instance of the entity from a DICOM dataset
- __eq__(other: RadiologicalStudy) bool [source]
Return self==value.
- class cobra_db.model.RadiologicalSeries[source]
Bases:
DicomEntity
Base class for all entities that contain dicom_tags.
- study_id: bson.ObjectId
- date: datetime.datetime
- series_uid: str
- description: str
- image_count: int
- image_shape: Tuple[int, int]
- protocol_name: str
- classmethod from_dataset(ds: pydicom.dataset.Dataset)[source]
Create an instance of the entity from a DICOM dataset
- classmethod from_images_metadata(images_metadata: List[ImageMetadata])[source]
- __eq__(other: RadiologicalSeries) bool [source]
Return self==value.
- class cobra_db.model.ImageMetadata[source]
Bases:
DicomEntity
Represents one DICOM image i.e. a DICOM instance with PixelData. Only the dicom headers are stored. While the pixel data is not stored.
- dicom_tags: dict
- file_source: FileSource
- study_id: bson.ObjectId
- series_id: bson.ObjectId
- aka_file_sources: List[FileSource]
- classmethod from_dataset(ds: pydicom.dataset.Dataset, mount_paths: dict)[source]
Create one instance from a pydicom Dataset.
- Parameters:
ds – pydicom Dataset
mount_paths – dict that maps the drive_names to the mount path of the drives that are in use.
- to_dataset() pydicom.dataset.Dataset [source]
Creates a pydicom Dataset with only the metadata in dicom_tags. Useful to use pydicom interface when required.
- get_checksum(mount_paths: dict) str [source]
Obtain the md5 hexdigest hash of the original file. This helps finding duplicated images. Warning: md5 is not cryptographycally secure.
- Parameters:
mount_paths – a dictionary mapping the drive_name to the mount path in the local computer.
- Returns:
string hexdigest with the hash of the file.
- get_local_filepath(mount_paths: dict) str [source]
Returns the filepath of the file_source according to mount_paths.
- Parameters:
mount_paths – a dictionary mapping the drive_name to the mount path in the local computer.
- Returns:
string hexdigest with the hash of the file.
- class cobra_db.model.Annotation[source]
Bases:
Entity
Abstract class for any annotation that is stored in cobra_db. Should be subclassed
- annotation_type: List[Literal[text, semantic_segmentation, binary, categorical]]
- annotator_email: str
- date: datetime.datetime
- possible_labels: List[str]
- file_format: str
- aggregation_level: Literal[patient, study, series, image]
- referenced_entity_uid: str
- patient_anon_id: str
- study_date: datetime.datetime
- file_source: FileSource
- project_name: str