Skip to content

Commit

Permalink
Fixed CRCA to state Under 60 or 60, fixed Diabetes for MODY couple of…
Browse files Browse the repository at this point in the history
… others
  • Loading branch information
bremonline committed Oct 24, 2014
1 parent 4ad41d8 commit 7638599
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 26 deletions.
2 changes: 1 addition & 1 deletion js/fhh.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ function bind_personal_cancel_button_action () {
$("#invalid_date_of_birth_warning").remove();
$("#invalid_gender_warning").remove();

alert (typeof personal_information);
// alert (typeof personal_information);
$("#add_personal_information_dialog").dialog("close");
});
}
Expand Down
2 changes: 1 addition & 1 deletion js/load_xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ function load_race(data) {
function get_age_at_diagnosis (xml_snippet) {
if (xml_snippet == null) return null;

if (xml_snippet.html() && xml_snippet.html().indexOf("prebirth") > -1) return 'Pre-Birth';
if (xml_snippet.html() && xml_snippet.html().indexOf("pre-birth") > -1) return 'prebirth';
var estimated_age = xml_snippet.html();
if (estimated_age && estimated_age.indexOf('unit="day"') > -1) {
if (estimated_age.indexOf('value="0"') > -1) return "newborn";
Expand Down
20 changes: 8 additions & 12 deletions js/save_xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function add_relative_estimated_age_tag(relationship_tag, estimated_age) {
code_tag.setAttribute("codeSystemName", "LOINC");
code_tag.setAttribute("code", "21611-9");
dataEstimatedAge_tag.appendChild(code_tag);
add_estimated_age_tag(dataEstimatedAge_tag, estimated_age);
add_estimated_age_tag(dataEstimatedAge_tag, code_tag, estimated_age);
}

function add_relative_age_tag(relationship_tag, age) {
Expand Down Expand Up @@ -428,7 +428,7 @@ function add_clinical_observations(tag,
adopted_flag,
active_flag)
{
var subjectOfTwo_tag = doc.createElement("subjectof2");
var subjectOfTwo_tag = doc.createElement("subjectOf2");
tag.appendChild(subjectOfTwo_tag);

add_twin_tag(subjectOfTwo_tag, twin_status);
Expand Down Expand Up @@ -569,20 +569,16 @@ function add_diseases(tag, diseases) {
new_code_tag.setAttribute("code", LOINC_CODE.ESTIMATED_AGE);
dataEstimatedAge_tag.appendChild(new_code_tag);

add_estimated_age_tag(dataEstimatedAge_tag, age_at_diagnosis);
add_estimated_age_tag(dataEstimatedAge_tag, new_code_tag, age_at_diagnosis);
}
}

function add_estimated_age_tag(tag, estimated_age) {
function add_estimated_age_tag(tag, code_tag, estimated_age) {
var av = get_age_values_from_estimated_age(estimated_age);
if (estimated_age == "Pre-Birth") {
var new_code_tag = doc.createElement("code");
new_code_tag.setAttribute("originalText", "pre-birth");
tag.appendChild(new_code_tag);
if (estimated_age == "Pre-Birth" || estimated_age == "prebirth") {
code_tag.setAttribute("originalText", "pre-birth");
} else if (estimated_age == "Unknown") {
var new_code_tag = doc.createElement("code");
new_code_tag.setAttribute("originalText", "unknown");
tag.appendChild(new_code_tag);
code_tag.setAttribute("originalText", "unknown");
} else {

// These estimates ages have high, low, and unit tags/attr
Expand Down Expand Up @@ -630,7 +626,7 @@ function add_death_age(tag, estimated_death_age) {
deceasedEstimatedAge_tag.appendChild(code_tag);
var value_tag = doc.createElement("value");

add_estimated_age_tag(deceasedEstimatedAge_tag, estimated_death_age);
add_estimated_age_tag(deceasedEstimatedAge_tag, code_tag, estimated_death_age);

}

Expand Down
10 changes: 5 additions & 5 deletions risk/crca/crca.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,17 @@ function test_secondary_family_members_colon_cancer_before_60() {
for (i=0;i<h.length;i++) {
if (h[i]['Detailed Disease Name'] == 'Colon Cancer' && is_age_before('Under60', h[i]['Age At Diagnosis']) ) {
name = get_name_or_relationship(this.name, key);
risk_reason += name + " has had colon cancer before the age of 60.<br />";
risk_reason += name + " has had colon cancer before the age of 60 years or at the age of 60 years.<br />";
risk=true;
}
if (h[i]['Detailed Disease Name'] == 'Colorectal Cancer' && is_age_before('Under60', h[i]['Age At Diagnosis']) ) {
name = get_name_or_relationship(this.name, key);
risk_reason += name + " has had colorectal cancer before the age of 60.<br />";
risk_reason += name + " has had colorectal cancer before the age of 60 years or at the age of 60 years.<br />";
risk=true;
}
if (h[i]['Detailed Disease Name'] == 'Rectal Cancer' && is_age_before('Under60', h[i]['Age At Diagnosis']) ) {
name = get_name_or_relationship(this.name, key);
risk_reason += name + " has had rectal cancer before the age of 60.<br />";
risk_reason += name + " has had rectal cancer before the age of 60 years or at the age of 60 years.<br />";
risk=true;
}
}
Expand All @@ -399,7 +399,7 @@ function test_secondary_family_members_colon_cancer_before_60() {
set_icon($("#secondary_family_members_colon_cancer_before_60"), 'negative');
set_reason($("#secondary_family_members_colon_cancer_before_60"),
"None of your secondary relatives (aunts, uncles, grandparents, grandchildren, halfsiblings) " +
"have had colon, rectal, or colorectal cancer before the age of 60.");
"have had colon, rectal, or colorectal cancer before the age of 60 years or at the age of 60 years.");
}

final_risk |= risk;
Expand Down Expand Up @@ -427,7 +427,7 @@ function test_secondary_family_members_uterine_cancer_before_50() {
for (i=0;i<h.length;i++) {
if (h[i]['Detailed Disease Name'] == 'Uterine Cancer' && is_age_before('Under50', h[i]['Age At Diagnosis']) ) {
name = get_name_or_relationship(this.name, key);
risk_reason += name + " has had uterine cancer before the age of 50.<br />";
risk_reason += name + " has had uterine cancer before the age of 50 years or at the age of 50 years.<br />";
risk=true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion risk/drc/diabetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function check_for_diabetes_prediabetes() {
if (h[i]['Detailed Disease Name'] == 'Impaired Fasting Glucose') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Impaired Glucose Tolerance') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Insulin Resistance') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Maturity Onset Diabetesmellitus in Young (MODY)') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Maturity Onset Diabetes mellitus in Young (MODY)') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Pre-Diabetes') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Type 1 Diabetes') diabetes_types.push(h[i]['Detailed Disease Name']);
if (h[i]['Detailed Disease Name'] == 'Type 2 Diabetes') diabetes_types.push(h[i]['Detailed Disease Name']);
Expand Down
230 changes: 224 additions & 6 deletions upload/upload3.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,239 @@
exit;

function make_json_output($file) {
global $disease_list, $pi;
$pi = array();

read_disease_list();
$dis = get_disease_name_from_detailed_name("Lung Cancer");
$pi['test'] = $dis;

$familyHistory = new SimpleXMLElement($file);

$subjectTypeCode = $familyHistory->subject[0]['typeCode'];
if ($subjectTypeCode == 'SBJ') $code = "Yes"; else $code = "No";

$pi = array();
$pi['name'] = reset($familyHistory->subject[0]->patient->patientPerson->name['formatted']);
$pi['gender'] = strtoupper(reset($familyHistory->subject[0]->patient->patientPerson->administrativeGenderCode['displayName']));
$pi['date_of_birth'] = reset($familyHistory->subject[0]->patient->patientPerson->birthTime['value']);
// $pi['id'] = reset($familyHistory->subject[0]->patient->patientPerson->id['extention']);
// if ($pi['id'] == "") $pi['id'] = reset($familyHistory->subject[0]->patient->patientPerson->id['extension']);

// the old site had a misspelling of extension, so we chekc either form.
$pi['id'] = g($familyHistory->subject->patient->patientPerson->id['extension']);
if (!isset($pi['id'])) $pi['id'] = g($familyHistory->subject->patient->patientPerson->id['extention']);

$pi['name'] = g($familyHistory->subject->patient->patientPerson->name['formatted']);
$pi['gender'] = strtoupper(g($familyHistory->subject->patient->patientPerson->administrativeGenderCode['displayName']));
$pi['date_of_birth'] = g($familyHistory->subject->patient->patientPerson->birthTime['value']);

$clinical_observations = $familyHistory->subject[0]->patient->patientPerson->subjectOf2->clinicalObservation;
$clinical_observations = $familyHistory->subject->patient->patientPerson->subjectof2->clinicalObservation;
// sometimes subjectOf2 is done as subjectof2 (note capital O)
if (!isset($clinical_observations)) $clinical_observations = $familyHistory->subject->patient->patientPerson->subjectOf2->clinicalObservation;

$diseases = array();

if (isset($clinical_observations)) {
foreach ($clinical_observations as $co) {
if ($co->code['displayName'] == 'height') {
$height = $co->value['value'];
$height_unit = $co->value['unit'];
} else if ($co->code['displayName'] == 'weight') {
$weight = $co->value['value'];
$weight_unit = $co->value['unit'];
} else if ($co->code['displayName'] == 'Physically Active') {
if ($co->value['value'] == 'true') $physically_active = true;
else $physically_active = false;
} else if ($co->code['originalText'] == 'Parental consanguinity indicated') {
$consanguinity = true;
} else if ($co->code['code'] == '313415001') {
$twin_status = 'IDENTICAL';
} else if ($co->code['code'] == '313416000') {
$twin_status = 'FRATERNAL';
} else if ($co->code['code'] == '160496001') {
$adopted = true;
} else {
$new_disease = load_disease($co);
if (count($new_disease) > 0) array_push($diseases, $new_disease);
}
}
}

// Race
$race_list = $familyHistory->subject->patient->patientPerson->raceCode;

$races = array();
foreach ($race_list as $race_code) {
$race_name = reset($race_code['displayName']);
if ($race_name == "Asian - Not Specified") $race_name = 'Unknown Asian';
if ($race_name == "Unspecified Native Hawaiian or Other Pacific Islander") $race_name = 'Unknown South Pacific Islander';
$races[$race_name] = true;
}

$ethnicity_list = $familyHistory->subject->patient->patientPerson->ethnicGroupCode;

$ethnicities = array();
foreach ($ethnicity_list as $ethnicity_code) {
$ethnicity_name = reset($ethnicity_code['displayName']);
$ethnicities[$ethnicity_name] = true;
}

// All that is left are relatives
$relatives = $familyHistory->subject->patient->patientPerson->relative;
$pi['relative_count'] = count($relatives);
add_all_relatives($relatives);

if (isset($height)) $pi['height'] = reset($height);
if (isset($height_unit)) $pi['height_unit'] = reset($height_unit);
if (isset($weight)) $pi['weight'] = reset($weight);
if (isset($weight_unit)) $pi['weight_unit'] = reset($weight_unit);
if (isset($physically_active) && $physically_active == 'true') $pi['physically_active'] = true;
if (isset($consanguinity) && $consanguinity == 'true') $pi['consanguinity'] = true;
if (isset($twin_status)) $pi['twin_status'] = $twin_status;
if (isset($adopted) && $adopted == 'true') $pi['adopted'] = true;

if (count($races) > 0) $pi['race'] = $races;
if (count($ethnicities) > 0) $pi['ethnicity'] = $ethnicities;
if (count($diseases) > 0) $pi['Health History'] = $diseases;

$pi['observations'] = $clinical_observations[1];
return json_encode($pi);

}

function add_all_relatives($relatives) {
global $pi;
foreach ($relatives as $r) {
$relationship = get_relationship_from_relationship_code(reset($r->code['code']));
$new_relative = array();

$new_relative['name'] = reset($r->relationshipHolder->name['formatted']);
$new_relative['gender'] = strtoupper(g($r->relationshipHolder->administrativeGenderCode['displayName']));
$new_relative['id'] = g($r->relationshipHolder->id['extension']);
if (!isset($new_relative['id'])) $new_relative['id'] = g($r->relationshipHolder->id['extention']);

$pi[$relationship] = $new_relative;

}
$relationship_code = $relatives;
}

function get_relationship_from_relationship_code($code) {
switch ($code) {
case "NMTH": return "mother";
case "NFTH": return "father";
case "MGRMTH": return "maternal_grandmother";
case "MGRFTH": return "maternal_grandfather";
case "PGRMTH": return "paternal_grandmother";
case "PGRFTH": return "paternal_grandfather";
case "NBRO": return get_next_available("brother");
case "NSIS": return get_next_available("sister");

default: return $code;
}
}

function get_next_available($relative) {
global $pi;
$i = 0;

while (isset($pi[$relative . "_" . $i]) && $i < 10) $i++;

return $relative . "_" . $i;
}

function g ($xml_element) {
if ($xml_element) return reset($xml_element);
else return NULL;
}

function read_disease_list () {
global $disease_list;
$diseases_str = file_get_contents( "../data/diseases.json");
$disease_list = json_decode($diseases_str, true);
}



function load_disease($co) {
$new_disease = array();

$disease_detailed_name = $co->code['displayName'];
$disease_code = $co->code['code'];
$disease_code_system = $co->code['codeSystemName'];

if (isset($disease_detailed_name)) {
$new_disease['Detailed Disease Name'] = reset($disease_detailed_name);
$new_disease['Disease Name'] = get_disease_name_from_detailed_name($new_disease['Detailed Disease Name']);
}
if (isset($disease_code) && isset($disease_code_system)) {
$new_disease['Disease Code'] = reset($disease_code_system) . '-' . reset($disease_code);
}
$estimated_age = $co->subject->dataEstimatedAge;
$age_at_diagnosis = get_age_at_diagnosis($estimated_age);

if (isset($age_at_diagnosis)) $new_disease['Age At Diagnosis'] = $age_at_diagnosis;

return $new_disease;
}

function get_disease_name_from_detailed_name($detailedDiseaseName) {
global $disease_list;

$high_level_disease_list = array_keys($disease_list);
foreach ($high_level_disease_list as $hld) {
$subdisease_list = $disease_list[$hld];
foreach ($subdisease_list as $sub) {
$name = $sub['name'];
if ($name == $detailedDiseaseName) return $hld;
}
}
return 'other';
}

function get_age_at_diagnosis ($estimated_age) {
$originalText = $estimated_age->code['originalText'];
if (isset($originalText) && reset($originalText) == 'pre-birth') return "prebirth";
if (isset($originalText) && reset($originalText) == 'unknown') return "unknown";

$unit = $estimated_age->value['unit'];
$low = $estimated_age->value->low['value'];

if (isset($unit) && reset($unit) == 'day') {
if (isset($low) && reset($low) == '0') return "newborn";
if (isset($low) && reset($low) == '29') return "infant";
}
if (isset($unit) && reset($unit) == 'year') {
if (isset($low) && reset($low) == '2') return "child";
if (isset($low) && reset($low) == '10') return "teen";
if (isset($low) && reset($low) == '20') return "twenties";
if (isset($low) && reset($low) == '30') return "thirties";
if (isset($low) && reset($low) == '40') return "fourties";
if (isset($low) && reset($low) == '50') return "fifties";
if (isset($low) && reset($low) == '60') return "senior";
}

return "unknown";
}
// Javascript below
/*
function get_age_at_diagnosis (xml_snippet) {
if (xml_snippet == null) return null;
if (xml_snippet.html() && xml_snippet.html().indexOf("prebirth") > -1) return 'Pre-Birth';
var estimated_age = xml_snippet.html();
if (estimated_age && estimated_age.indexOf('unit="day"') > -1) {
if (estimated_age.indexOf('value="0"') > -1) return "newborn";
if (estimated_age.indexOf('value="29"') > -1) return "infant";
}
if (estimated_age && estimated_age.indexOf('unit="year"') > -1) {
if (estimated_age.indexOf('value="2"') > -1) return "child";
if (estimated_age.indexOf('value="10"') > -1) return "teen";
if (estimated_age.indexOf('value="20"') > -1) return "twenties";
if (estimated_age.indexOf('value="30"') > -1) return "thirties";
if (estimated_age.indexOf('value="40"') > -1) return "fourties";
if (estimated_age.indexOf('value="50"') > -1) return "fifties";
if (estimated_age.indexOf('value="60"') > -1) return "senior";
}
if (xml_snippet.html() && xml_snippet.html().indexOf("unknown") > -1) return 'unknown';
return null;
}
*/
?>

0 comments on commit 7638599

Please sign in to comment.