| 1 | package Convert::Pheno::ClinicalCDM::I2B2; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 136 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 136 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 136 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 136 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 136 | ▶ | use Convert::Pheno::ClinicalCDM::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | coded_term | ||||||||||||||||||||||||||||
| 11 | date_value | ||||||||||||||||||||||||||||
| 12 | first_value | ||||||||||||||||||||||||||||
| 13 | map_sex | ||||||||||||||||||||||||||||
| 14 | numeric_value | ||||||||||||||||||||||||||||
| 15 | row_visit | ||||||||||||||||||||||||||||
| 16 | source_term | ||||||||||||||||||||||||||||
| 17 | table_rows | ||||||||||||||||||||||||||||
| 18 | timestamp_value | ||||||||||||||||||||||||||||
| 19 | 136 | ); | |||||||||||||||||||||||||||
| 20 | 136 | ▶ | use Convert::Pheno::Utils::Default qw(get_defaults); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 136 | our @EXPORT_OK = qw(map_i2b2_individual); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 136 | my $DEFAULT = get_defaults(); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 14 | ▶ | sub map_i2b2_individual { | ||||||||||||||||||||||||||
|
Subroutine
map_i2b2_individual: called CC=31 SCAR=35.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 14 | my ( $self, $record ) = @_; | |||||||||||||||||||||||||||
| 28 | 14 | my $patient = $record->{patient}; | |||||||||||||||||||||||||||
| 29 | 14 | my $individual = { | |||||||||||||||||||||||||||
| 30 | id => "$record->{personId}", | ||||||||||||||||||||||||||||
| 31 | sex => map_sex( | ||||||||||||||||||||||||||||
| 32 | first_value( $patient, qw(SEX_CD SEX GENDER_CD GENDER) ) | ||||||||||||||||||||||||||||
| 33 | ), | ||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 14 | my $birth = timestamp_value( | |||||||||||||||||||||||||||
| 37 | first_value( $patient, qw(BIRTH_DATE BIRTHDATE DATE_OF_BIRTH) ) | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | 14 | ▶ | $individual->{info}{phenopacket}{dateOfBirth} = $birth | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | if defined $birth; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 14 | my $death = timestamp_value( | |||||||||||||||||||||||||||
| 43 | first_value( $patient, qw(DEATH_DATE DEATH_DATE_TIME DOD) ) | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | 14 | ▶ | if ( defined $death ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | $individual->{info}{phenopacket}{vitalStatus} = { | ||||||||||||||||||||||||||||
| 47 | 6 | status => 'DECEASED', | |||||||||||||||||||||||||||
| 48 | timeOfDeath => { timestamp => $death }, | ||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 14 | my ( @diseases, @procedures, @measures, @treatments, @features ); | |||||||||||||||||||||||||||
| 53 | 14 | for my $row ( @{ table_rows( $record, 'OBSERVATION_FACT' ) } ) { | |||||||||||||||||||||||||||
| 54 | 36 | my $code = first_value( $row, qw(CONCEPT_CD CONCEPT_CODE) ); | |||||||||||||||||||||||||||
| 55 | 36 | ▶ | next unless defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 36 | ▶ | my $concept = $record->{concepts}{$code} || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$record->{'concepts'}{$code} || {}
MC/DC100%1/1
$record->{'concepts'}{$code} || {}
$record->{'concepts'}{$code}
Truth table100%2/2
A
A= $record->{'concepts'}{$code}
| |||||||||||||||||||||||||||||
| 57 | 36 | my $label = first_value( | |||||||||||||||||||||||||||
| 58 | $concept, | ||||||||||||||||||||||||||||
| 59 | qw(NAME_CHAR CONCEPT_NAME NAME DESCRIPTION) | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | 36 | my $term = coded_term( | |||||||||||||||||||||||||||
| 62 | model => 'i2b2', | ||||||||||||||||||||||||||||
| 63 | kind => 'Concept', | ||||||||||||||||||||||||||||
| 64 | code => $code, | ||||||||||||||||||||||||||||
| 65 | label => $label, | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | 36 | my $prefix = _concept_prefix($code); | |||||||||||||||||||||||||||
| 68 | 36 | ▶ | my $valtype = uc( first_value( $row, qw(VALTYPE_CD VALUETYPE_CD) ) // q{} ); | ||||||||||||||||||||||||||
|
Condition50%1/2
first_value($row, ("VALTYPE_CD", "VALUETYPE_CD")) // ""
MC/DC0%0/1
first_value($row, ("VALTYPE_CD", "VALUETYPE_CD")) // ""
first_value($row, ("VALTYPE_CD", "VALUETYPE_CD"))
Truth table50%1/2
A
A= first_value($row, ("VALTYPE_CD", "VALUETYPE_CD"))
| |||||||||||||||||||||||||||||
| 69 | 36 | ▶ | my $modifier = first_value( $row, qw(MODIFIER_CD) ) // '@'; | ||||||||||||||||||||||||||
|
Condition50%1/2
first_value($row, "MODIFIER_CD") // "\@"
MC/DC0%0/1
first_value($row, "MODIFIER_CD") // "\@"
first_value($row, "MODIFIER_CD")
Truth table50%1/2
A
A= first_value($row, "MODIFIER_CD")
| |||||||||||||||||||||||||||||
| 70 | 36 | my $visit = row_visit( $record, $row, model => 'i2b2' ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # i2b2 modifier rows describe attributes of the base observation; | ||||||||||||||||||||||||||||
| 73 | # they are not independent clinical events. Preserve them in source | ||||||||||||||||||||||||||||
| 74 | # provenance without duplicating the BFF event. | ||||||||||||||||||||||||||||
| 75 | 36 | ▶ | next unless $modifier eq '@'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 30 | ▶ | if ( $valtype eq 'N' || $prefix eq 'LOINC' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$valtype eq "N" or $prefix eq "LOINC"
MC/DC50%1/2
$valtype eq "N" or $prefix eq "LOINC"
$valtype eq "N"
$prefix eq "LOINC"
Truth table66%2/3
A or B
A= $valtype eq "N"B= $prefix eq "LOINC"
| |||||||||||||||||||||||||||||
| 78 | 6 | my $value = _measurement_value($row); | |||||||||||||||||||||||||||
| 79 | 6 | ▶ | next unless $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 6 | my $measure = { | |||||||||||||||||||||||||||
| 81 | assayCode => $term, | ||||||||||||||||||||||||||||
| 82 | measurementValue => $value, | ||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||
| 84 | 6 | my $date = date_value( first_value( $row, qw(START_DATE OBS_DATE) ) ); | |||||||||||||||||||||||||||
| 85 | 6 | ▶ | $measure->{date} = $date if defined $date; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 6 | ▶ | $measure->{_visit} = $visit if $visit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 6 | push @measures, $measure; | |||||||||||||||||||||||||||
| 88 | 6 | next; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 24 | ▶ | if ( _is_medication_prefix($prefix) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 6 | my $treatment = { treatmentCode => $term }; | |||||||||||||||||||||||||||
| 93 | 6 | ▶ | $treatment->{_visit} = $visit if $visit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 6 | push @treatments, $treatment; | |||||||||||||||||||||||||||
| 95 | 6 | next; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 18 | ▶ | if ( _is_procedure_prefix($prefix) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 6 | my $procedure = { procedureCode => $term }; | |||||||||||||||||||||||||||
| 100 | 6 | my $date = date_value( first_value( $row, qw(START_DATE OBS_DATE) ) ); | |||||||||||||||||||||||||||
| 101 | 6 | ▶ | $procedure->{dateOfProcedure} = $date if defined $date; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 6 | ▶ | $procedure->{_visit} = $visit if $visit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 6 | push @procedures, $procedure; | |||||||||||||||||||||||||||
| 104 | 6 | next; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 12 | ▶ | if ( _is_diagnosis_prefix($prefix) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 6 | my $disease = { diseaseCode => $term }; | |||||||||||||||||||||||||||
| 109 | 6 | ▶ | $disease->{_visit} = $visit if $visit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 6 | push @diseases, $disease; | |||||||||||||||||||||||||||
| 111 | 6 | next; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 6 | my $feature = { featureType => $term }; | |||||||||||||||||||||||||||
| 115 | 6 | ▶ | $feature->{_visit} = $visit if $visit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 6 | push @features, $feature; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 14 | ▶ | $individual->{diseases} = \@diseases if @diseases; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 14 | ▶ | $individual->{interventionsOrProcedures} = \@procedures if @procedures; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 14 | ▶ | $individual->{measures} = \@measures if @measures; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 14 | ▶ | $individual->{treatments} = \@treatments if @treatments; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 14 | ▶ | $individual->{phenotypicFeatures} = \@features if @features; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 14 | ▶ | if ( $self->{source_info} // 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"source_info"} // 1
MC/DC0%0/1
$self->{"source_info"} // 1
$self->{"source_info"}
Truth table50%1/2
A
A= $self->{"source_info"}
| |||||||||||||||||||||||||||||
| 126 | $individual->{info}{i2b2} = { | ||||||||||||||||||||||||||||
| 127 | patient => dclone($patient), | ||||||||||||||||||||||||||||
| 128 | 14 | tables => dclone( $record->{tables} ), | |||||||||||||||||||||||||||
| 129 | }; | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | $individual->{info}{convertPheno} = $self->{convertPheno} | ||||||||||||||||||||||||||||
| 132 | 14 | ▶ | if !$self->{test} && defined $self->{convertPheno}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->{"test"} and defined $self->{"convertPheno"}
MC/DC0%0/2
not $self->{"test"} and defined $self->{"convertPheno"}
not $self->{"test"}
defined $self->{"convertPheno"}
Truth table33%1/3
not(A) and B
A= not $self->{"test"}B= defined $self->{"convertPheno"}
| |||||||||||||||||||||||||||||
| 133 | 14 | return $individual; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 6 | ▶ | sub _measurement_value { | ||||||||||||||||||||||||||
|
Subroutine
_measurement_value: called CC=4 SCAR=17.3
| |||||||||||||||||||||||||||||
| 137 | 6 | my ($row) = @_; | |||||||||||||||||||||||||||
| 138 | 6 | my $number = numeric_value( $row, qw(NVAL_NUM NUMERIC_VALUE) ); | |||||||||||||||||||||||||||
| 139 | 6 | ▶ | if ( defined $number ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 6 | my $unit_label = first_value( $row, qw(UNITS_CD UNIT) ); | |||||||||||||||||||||||||||
| 141 | my $unit = defined $unit_label | ||||||||||||||||||||||||||||
| 142 | ? source_term( 'i2b2', 'Unit', $unit_label, $unit_label ) | ||||||||||||||||||||||||||||
| 143 | 6 | ▶ | : dclone( $DEFAULT->{ontology_term} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 6 | return { quantity => { value => $number, unit => $unit } }; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 0 | my $text = first_value( $row, qw(TVAL_CHAR TEXT_VALUE) ); | |||||||||||||||||||||||||||
| 147 | 0 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | return source_term( 'i2b2', 'Result', $text, $text ); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 36 | ▶ | sub _concept_prefix { | ||||||||||||||||||||||||||
|
Subroutine
_concept_prefix: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 152 | 36 | my ($code) = @_; | |||||||||||||||||||||||||||
| 153 | 36 | my ($prefix) = split /:/, $code, 2; | |||||||||||||||||||||||||||
| 154 | 36 | ▶ | $prefix = uc( $prefix // q{} ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$prefix // ""
MC/DC0%0/1
$prefix // ""
$prefix
Truth table50%1/2
A
A= $prefix
| |||||||||||||||||||||||||||||
| 155 | 36 | $prefix =~ s/[^A-Z0-9]+//g; | |||||||||||||||||||||||||||
| 156 | 36 | return $prefix; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 12 | ▶ | sub _is_diagnosis_prefix { | ||||||||||||||||||||||||||
|
Subroutine
_is_diagnosis_prefix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 160 | 12 | my ($prefix) = @_; | |||||||||||||||||||||||||||
| 161 | 12 | return $prefix =~ /\A(?:ICD9|ICD9CM|ICD10|ICD10CM|ICD11|SNOMED|SNOMEDCT|DX)\z/; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 18 | ▶ | sub _is_procedure_prefix { | ||||||||||||||||||||||||||
|
Subroutine
_is_procedure_prefix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | 18 | my ($prefix) = @_; | |||||||||||||||||||||||||||
| 166 | 18 | return $prefix =~ /\A(?:CPT|CPT4|HCPCS|ICD10PCS|ICD9PROC|PROC|PX)\z/; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 24 | ▶ | sub _is_medication_prefix { | ||||||||||||||||||||||||||
|
Subroutine
_is_medication_prefix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 170 | 24 | my ($prefix) = @_; | |||||||||||||||||||||||||||
| 171 | 24 | return $prefix =~ /\A(?:RXNORM|NDC|MED|MEDICATION|DRUG)\z/; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 136 | 1; | |||||||||||||||||||||||||||