Skip to content

Commit

Permalink
Merge pull request #139 from OHDSI/138-case-sensitivity-issue-affecti…
Browse files Browse the repository at this point in the history
…ng-measurement-source-concept-id-in-cprd

138 case sensitivity issue affecting measurement source concept id in cprd
  • Loading branch information
bradanton authored Nov 28, 2024
2 parents 9255019 + 35526e8 commit 0ca6005
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
37 changes: 36 additions & 1 deletion docs/CPRD/Test Cases/R/observationTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ createObservationTests <- function()
add_medical(medcode = 14612, read_code = '657E.00')
add_medical(medcode = 1942, read_code = 'M240012', description = 'Hair loss')
add_medical(medcode = 28844, read_code = '66Ya.00')

add_medical(medcode = 14231, read_code = '339A.00')
add_medical(medcode = 23237, read_code = '339a.00')

# 1) -- clinical procedure with visit

Expand Down Expand Up @@ -219,6 +220,40 @@ createObservationTests <- function()
value_as_number=3.7, observation_source_value='66Ya.00', qualifier_concept_id=4172703,
unit_source_value='%')
expect_count_observation(rowCount = 1, person_id = lookup_person("person_id", person_source_value = patient$person_id))

patient <- createPatient();
declareTest(id = patient$person_id, 'Read code case-sensitive test #1 339A.00')
add_patient(patid = patient$patid, gender = 1, yob = 199, mob = 1, accept = 1, crd = '2010-01-01', pracid = patient$pracid)
add_test(patid = patient$patid, eventdate = '2012-01-01', medcode = 14231, staffid = 1001, enttype = 380,
data1 = 9, data2 = 28.800,data3 = 114.000 ,data4 = 0.000, data5 = NULL, data6 = NULL,
data7 =0 ,data8_value = NULL,data8_date = NULL)
add_entity(code = 380, description = 'Pulmonary function tests', filetype = 'Test', category = 'Haematology',
data_fields = 4, data1 = 'Qualifier', data1lkup = 'TQU',
data2 = 'Normal range from', data2lkup = NULL,
data3 = 'Normal range to', data3lkup = NULL,
data4 = 'Normal range basis', data4lkup = NULL)
add_lookup(lookup_id = 1156,lookup_type_id = 85, code = 9, text = 'Normal')
expect_observation(person_id = lookup_person("person_id", person_source_value = patient$person_id), observation_source_concept_id=45455049,
observation_date='2012-01-01',
observation_type_concept_id=32856,
observation_source_value='339A.00')

patient <- createPatient();
declareTest(id = patient$person_id, 'Read code case-sensitive test #2 339a.00')
add_patient(patid = patient$patid, gender = 1, yob = 199, mob = 1, accept = 1, crd = '2010-01-01', pracid = patient$pracid)
add_test(patid = patient$patid, eventdate = '2012-01-01', medcode = 23237, staffid = 1001, enttype = 380,
data1 = 9, data2 = 28.800,data3 = 114.000 ,data4 = 0.000, data5 = NULL, data6 = NULL,
data7 =0 ,data8_value = NULL,data8_date = NULL)
add_entity(code = 380, description = 'Pulmonary function tests', filetype = 'Test', category = 'Haematology',
data_fields = 4, data1 = 'Qualifier', data1lkup = 'TQU',
data2 = 'Normal range from', data2lkup = NULL,
data3 = 'Normal range to', data3lkup = NULL,
data4 = 'Normal range basis', data4lkup = NULL)
add_lookup(lookup_id = 1156,lookup_type_id = 85, code = 9, text = 'Normal')
expect_observation(person_id = lookup_person("person_id", person_source_value = patient$person_id), observation_source_concept_id=45421972,
observation_date='2012-01-01',
observation_type_concept_id=32856,
observation_source_value='339a.00')

#========================================================================
# DONE TESTS UP TO HERE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using org.ohdsi.cdm.framework.common.Builder;
using org.ohdsi.cdm.framework.common.Enums;
using org.ohdsi.cdm.framework.common.Helpers;
using org.ohdsi.cdm.framework.common.Lookups;
using org.ohdsi.cdm.framework.common.Omop;
using org.ohdsi.cdm.framework.common.PregnancyAlgorithm;

Expand Down Expand Up @@ -385,8 +386,8 @@ private static string GetDomain2(string entityDomain, string conceptDomain)
switch (e.AdditionalFields["data"].ToLower().Trim())
{
case "read code for condition":
var result = Vocabulary.Lookup(value, "Read_Code", DateTime.MinValue);
return result.Count != 0 ? result[0].ConceptId : null;
var result = GetReadCodeConceptId(value, DateTime.MinValue);
return result?.ConceptId;

case "drug code":
var result1 = Vocabulary.Lookup(value, "Drug", DateTime.MinValue);
Expand Down Expand Up @@ -441,15 +442,12 @@ public override void AddToChunk(string domain, IEnumerable<IEntity> entities)

if (!string.IsNullOrEmpty(mes.SourceValue))
{
var result = Vocabulary.Lookup(mes.SourceValue, "Read_Code", mes.StartDate);
var result = GetReadCodeConceptId(mes.SourceValue, mes.StartDate);

if (result.Count != 0
&& result.Count > 0
&& result[0].SourceConcepts.Count > 0
&& result[0].SourceConcepts.First().ConceptId > 0
/*&& result[0].Domain == "Measurement"*/)
if(result != null && result.SourceConcepts.Count > 0
&& result.SourceConcepts.First().ConceptId > 0)
{
mes.SourceConceptId = result[0].SourceConcepts.First().ConceptId;
mes.SourceConceptId = result.SourceConcepts.First().ConceptId;
}
}

Expand Down Expand Up @@ -509,14 +507,12 @@ public override void AddToChunk(string domain, IEnumerable<IEntity> entities)

if (obs.TypeConceptId == 32856 && !string.IsNullOrEmpty(obs.SourceValue))
{
var result = Vocabulary.Lookup(obs.SourceValue, "Read_Code", obs.StartDate);
var result = GetReadCodeConceptId(obs.SourceValue, obs.StartDate);

if (result.Count != 0
&& result.Count > 0
&& result[0].SourceConcepts.Count > 0
&& result[0].SourceConcepts.First().ConceptId > 0)
if (result != null && result.SourceConcepts.Count > 0
&& result.SourceConcepts.First().ConceptId > 0)
{
obs.SourceConceptId = result[0].SourceConcepts.First().ConceptId;
obs.SourceConceptId = result.SourceConcepts.First().ConceptId;
}
}

Expand Down Expand Up @@ -614,12 +610,6 @@ public override IEnumerable<Measurement> BuildMeasurement(Measurement[] measurem
{
foreach (var mes in BuildEntities(measurements, visitOccurrences, observationPeriods, false))
{
//if (!string.IsNullOrEmpty(mes.SourceValue))
//{
// var result = Vocabulary.Lookup(mes.SourceValue, "Read_Code", mes.StartDate);
// mes.SourceConceptId = result.Any() ? result[0].ConceptId ?? 0 : 0;
//}

yield return mes;
}
}
Expand Down Expand Up @@ -651,6 +641,18 @@ public override IEnumerable<DeviceExposure> BuildDeviceExposure(DeviceExposure[]
return BuildEntities(devExposure, visitOccurrences, observationPeriods, false);
}

private LookupValue? GetReadCodeConceptId(string sourceValue, DateTime date)
{
var result = Vocabulary.Lookup(sourceValue, "Read_Code", date);

if (result != null && result.Count > 0)
{
return result.FirstOrDefault(r => sourceValue.Equals(r.SourceCode, StringComparison.Ordinal));
}

return null;
}

#endregion
}
}

0 comments on commit 0ca6005

Please sign in to comment.