transmart_loader.copy_writer module

class transmart_loader.copy_writer.TransmartCopyWriter(output_dir: str)

Bases: transmart_loader.collection_visitor.CollectionVisitor

Writes TranSMART data collections to a folder with files that can be loaded into a TranSMART database using transmart-copy.

concepts_header = ['concept_cd', 'concept_path', 'name_char']
dimensions_header = ['id', 'name', 'modifier_code', 'value_type']
init_writers() → None

Creates files and initialises writers for the output files in transmart-copy format.

observations_header = ['encounter_num', 'patient_num', 'concept_cd', 'provider_id', 'start_date', 'end_date', 'modifier_cd', 'instance_num', 'trial_visit_num', 'valtype_cd', 'tval_char', 'nval_num', 'observation_blob']
patient_mappings_header = ['patient_ide', 'patient_ide_source', 'patient_num']
patients_header = ['patient_num', 'sex_cd']
prepare_output_dir() → None

Creates an output directory if it does not exist. Fails if the output directory exists and is not empty.

studies_header = ['study_num', 'study_id', 'secure_obj_token']
study_dimensions_header = ['study_id', 'dimension_description_id']
tree_nodes_header = ['c_hlevel', 'c_fullname', 'c_name', 'c_visualattributes', 'c_basecode', 'c_facttablecolumn', 'c_tablename', 'c_columnname', 'c_columndatatype', 'c_operator', 'c_dimcode', 'secure_obj_token']
trial_visits_header = ['trial_visit_num', 'study_num', 'rel_time_unit_cd', 'rel_time_num', 'rel_time_label']
value_type_codes = {<ValueType.Numeric: 1>: 'N', <ValueType.Categorical: 2>: 'T', <ValueType.Date: 4>: 'D', <ValueType.Text: 3>: 'B'}
visit_concept(concept: transmart_loader.transmart.Concept) → None

Serialises a Concept entity to a TSV file.

Parameters:concept – the Concept entity
visit_node(node: transmart_loader.transmart.TreeNode) → None
visit_observation(observation: transmart_loader.transmart.Observation) → None

Serialises an Observation entity to a TSV file.

FIXME: fix date value serialisation

Parameters:observation – the Observation entity
visit_patient(patient: transmart_loader.transmart.Patient) → None

Serialises an Patient entity and related PatientMapping entities to TSV files.

Parameters:patient – the Patient entity
visit_study(study: transmart_loader.transmart.Study) → None

Serialises a Study entity to a TSV file.

Parameters:study – the Study entity
visit_tree_node(node: transmart_loader.transmart.TreeNode, level=0, parent_path='\\')

Serialises a TreeNode entity and its children to a TSV file.

Parameters:
  • node – the TreeNode entity
  • level – the hierarchy level of the node
  • parent_path – the path of the parent node.
visit_trial_visit(trial_visit: transmart_loader.transmart.TrialVisit) → None

Serialises a TrialVisit entity to a TSV file.

Parameters:trial_visit – the TrialVisit entity
visit_visit(visit: transmart_loader.transmart.Visit) → None

Serialises a Visit entity to a TSV file. NB: this requires all patient visits to be cleared before loading new visits for the patient.

Parameters:visit – the Visit entity
visits_header = ['encounter_num', 'patient_num', 'active_status_cd', 'start_date', 'end_date', 'inout_cd', 'location_cd', 'location_path', 'length_of_stay', 'visit_blob']
write_collection(collection: transmart_loader.transmart.DataCollection) → None
write_dimension(dimension: transmart_loader.transmart.Dimension) → None

Serialises a Dimension entity to a TSV file.

Parameters:dimension – the Dimension entity
write_dimensions() → None

Write dimensions metadata and link all studies to the dimensions

write_study_dimensions(study_index)
class transmart_loader.copy_writer.VisualAttribute

Bases: enum.Enum

Visual attribute of an ontology node

Categorical = 8
Container = 3
Date = 7
Folder = 2
Leaf = 1
Numerical = 5
Study = 4
Text = 6
transmart_loader.copy_writer.format_date(value: Optional[datetime.date]) → Optional[str]
transmart_loader.copy_writer.get_concept_node_row(node: transmart_loader.transmart.ConceptNode, level, node_path)
transmart_loader.copy_writer.get_folder_node_row(node: transmart_loader.transmart.TreeNode, level, node_path)
transmart_loader.copy_writer.get_study_node_row(node: transmart_loader.transmart.StudyNode, level, node_path)