コード例 #1
0
    def map_patient(self, patient: fhir_patient.Patient) -> None:
        """ Maps a FHIR Patient Resource to a Patient entity in TranSMART.
        The gender and birthDate are mapped to a Date Observation entity.
        The Patient and Observations are added to the collections of
        Patients and Observations returned by the mapper.

        :param patient: a FHIR Patient Resource
        """
        subject = Patient(patient.id, patient.gender, [])
        self.patients[patient.id] = subject
        gender_observation = Observation(
            subject,
            gender_concept,
            None,
            trial_visit,
            None,
            None,
            CategoricalValue(patient.gender))
        self.add_observation(gender_observation)
        birth_date_observation = Observation(
            subject,
            birth_date_concept,
            None,
            trial_visit,
            None,
            None,
            DateValue(patient.birthDate.date))
        self.add_observation(birth_date_observation)
コード例 #2
0
    def map_condition(self, condition: Condition) -> None:
        """ Maps a FHIR Condition Resource to a categorical Observation entity
        in TranSMART.
        The reference to the subject is resolved to the corresponding TranSMART Patient.
        The reference to the encounter is resolved to the corresponding TranSMART Visit.
        The Observation is added to the collection of Observations returned by the mapper.

        :param condition: a FHIR Condition Resource
        """
        subject = self.patients[get_reference(condition.subject)]
        visit_ref = get_reference(condition.encounter)
        if visit_ref is None:
            visit_ref = get_reference(condition.context)
        visit = self.visits[visit_ref] if visit_ref else None
        concept = map_concept(condition.code)
        observation = Observation(
            subject,
            concept,
            visit,
            trial_visit,
            None,
            None,
            CategoricalValue(concept.name)
        )
        self.add_observation(observation)
コード例 #3
0
 def map_observation_metadata(
         self,
         entity_type_to_id: Dict[str,
                                 str]) -> Optional[ObservationMetadata]:
     """
     Get observation metadata based on the observation modifier key to value of the modifier observation
     :param entity_type_to_id: dictionary from entity type to id of the entity
     :return: transmart-loader metadata if any
     """
     mod_metadata: Dict[Modifier, Value] = dict()
     for modifier_key, value in entity_type_to_id.items():
         modifier = self.modifier_key_to_modifier.get(modifier_key)
         if modifier is None:
             return None
         mod_metadata[modifier] = CategoricalValue(value)
     return ObservationMetadata(mod_metadata)
コード例 #4
0
 def row_value_to_value(row_value,
                        value_type: ValueType) -> Optional[Value]:
     """
     Map entity value to transmart-loader Value by ValueType
     :param row_value: entity value
     :param value_type: transmart-loader ValueType
     :return: transmart-loader Value
     """
     if row_value is None:
         return None
     if value_type is ValueType.Categorical:
         return CategoricalValue(row_value)
     elif value_type is ValueType.Numeric:
         return NumericalValue(row_value)
     elif value_type is ValueType.Date:
         return DateValue(row_value)
     else:
         return TextValue(row_value)
コード例 #5
0
concepts = [age_concept, diagnosis_concept, diagnosis_date_concept]
studies = [Study('test', 'Test study')]
trial_visits = [TrialVisit(studies[0], 'Week 1', 'Week', 1)]
patients = [Patient('SUBJ0', 'male', []), Patient('SUBJ1', 'female', [])]
visits = [
    Visit(patients[0], 'visit1', None, None, None, None, None, None, []),
    Visit(patients[1], 'visit2', None, None, None, None, None, None, [])
]
# Create the observations
observations = [
    Observation(patients[0], age_concept, visits[0], trial_visits[0],
                date(2019, 3, 28), None, NumericalValue(28)),
    Observation(patients[0], diagnosis_concept, visits[0], trial_visits[0],
                datetime(2019, 6, 26, 12, 34, 00),
                datetime(2019, 6, 28, 16, 46, 13, 345),
                CategoricalValue('Influenza')),
    Observation(patients[0], diagnosis_date_concept, visits[0],
                trial_visits[0], datetime(2019, 6, 26, 13, 50, 10), None,
                DateValue(datetime(2018, 4, 30, 17, 10, 00))),
    Observation(patients[1], age_concept, visits[1], trial_visits[0],
                date(2019, 3, 28), None, NumericalValue(43)),
    Observation(patients[1], diagnosis_concept, visits[1], trial_visits[0],
                datetime(2019, 8, 12, 10, 30, 00), None,
                CategoricalValue('Malaria')),
    Observation(patients[1], diagnosis_date_concept, visits[1],
                trial_visits[0], datetime(2019, 8, 12, 10, 30, 00), None,
                DateValue(datetime(2018, 10, 7, 13, 20, 00)))
]

# Create the ontology of the structure
# └ Ontology
コード例 #6
0
def simple_collection() -> DataCollection:
    concepts: List[Concept] = [
        Concept('dummy_code', 'Dummy variable', '\\dummy\\path',
                ValueType.Categorical),
        Concept('diagnosis_date', 'Diagnosis date', '\\diagnosis_date',
                ValueType.Date),
        Concept('extra_c1', 'Extra c1', '\\c1', ValueType.Categorical),
        Concept('extra_c2', 'Extra c2', '\\c1', ValueType.Categorical)
    ]
    modifiers: List[Modifier] = [
        Modifier('missing_value', 'Missing value', '\\missing_value',
                 ValueType.Text),
        Modifier('sample_id', 'Sample ID', '\\sample_id', ValueType.Numeric)
    ]
    dimensions: List[Dimension] = [
        Dimension('sample', modifiers[1], DimensionType.Subject, 1)
    ]
    study_metadata = StudyMetadata(
        **{
            'conceptCodeToVariableMetadata': {
                'test_concept': {
                    'name': 'variable_1',
                    'type': 'DATETIME'
                }
            }
        })
    studies: List[Study] = [Study('test', 'Test study', study_metadata)]
    trial_visits: List[TrialVisit] = [
        TrialVisit(studies[0], 'Week 1', 'Week', 1)
    ]
    patients: List[Patient] = [Patient('SUBJ0', 'male', [])]
    visits: List[Visit] = [
        Visit(patients[0], 'visit1', None, None, None, None, None, None, [])
    ]
    top_node = StudyNode(studies[0])
    top_node.metadata = TreeNodeMetadata({'Upload date': '2019-07-01'})
    top_node.add_child(ConceptNode(concepts[0]))
    top_node.add_child(ConceptNode(concepts[1]))

    node2 = TreeNode('Extra node')
    node2.add_child((ConceptNode(concepts[2])))
    node3 = TreeNode('Extra node')
    node3.add_child(ConceptNode(concepts[3]))

    ontology: List[TreeNode] = [top_node, node2, node3]
    observations: List[Observation] = [
        Observation(patients[0], concepts[0], visits[0], trial_visits[0],
                    date(2019, 3, 28), None, CategoricalValue('value')),
        Observation(patients[0], concepts[0], visits[0], trial_visits[0],
                    datetime(2019, 6, 26, 12, 34, 00),
                    datetime(2019, 6, 28, 16, 46, 13, 345),
                    CategoricalValue(None),
                    ObservationMetadata({modifiers[0]: TextValue('Invalid')})),
        Observation(patients[0], concepts[1], visits[0], trial_visits[0],
                    datetime(2019, 6, 26, 13, 50, 10), None,
                    DateValue(datetime(2018, 4, 30, 17, 10, 00)))
    ]
    collection = DataCollection(concepts, modifiers, dimensions, studies,
                                trial_visits, visits, ontology, patients,
                                observations)
    return collection