All pastes #2073420 Raw Edit

Quasar

public cpp v1 · immutable
#2073420 ·published 2011-06-01 22:13 UTC
rendered paste body
//----------------------------------------------------------------------------------------------------------------------void __fastcall TframeAssessmentVitals::gridVitalsEntrySetEditText(      TObject *Sender, int ACol, int ARow, const AnsiString Value){  if(ACol == 1)  {    // User has edited an observation value; mark as modified    SetModified(true);        // Do auto-calculations for certain fields    string height_id = lookupTables->IdOf("obs_questions", "Height");    string weight_id = lookupTables->IdOf("obs_questions", "Weight");    string bmi_id    = lookupTables->IdOf("obs_questions", "Body-Mass Index");    string systolic_id  = lookupTables->IdOf("obs_questions", "Systolic Blood Pressure");    string diastolic_id = lookupTables->IdOf("obs_questions", "Diastolic Blood Pressure");    string slash_id     = lookupTables->IdOf("obs_questions", "Blood Pressure (w/slash)");    // Editing height or weight? See if can calculate BMI    if(rownum_to_question_id[ARow] == height_id || rownum_to_question_id[ARow] == weight_id)    {      string height_str = gridVitalsEntry->Cells[1][question_id_to_rownum[height_id]].c_str();      string weight_str = gridVitalsEntry->Cells[1][question_id_to_rownum[weight_id]].c_str();      if(height_str != "" && weight_str != "" &&       // not blanks;         (IsInt(height_str) || IsFloat(height_str)) && // height is an integer or float value, and         (IsInt(weight_str) || IsFloat(weight_str)))   // weight is an integer or float value      {        float height_in  = StringToFloat(height_str);        float weight_lbs = StringToFloat(weight_str);        // Yeah, I'm hardcoding the conversions. Sue me. I'll hopefully fix it up when I get user units editing working.        // Frankly what the observation pane is doing with FloatConvertMetric is not any better (hardcoded ID values).        float height_m   = height_in  * 0.0254f;        float weight_kg  = weight_lbs * 0.453592f; // Warning to Octopi Men of the future: assumes G at Earth's surface :P        float bmi = weight_kg / (height_m * height_m);        gridVitalsEntry->Cells[1][question_id_to_rownum[bmi_id]] = FloatToString(bmi, 2).c_str();      }      else        gridVitalsEntry->Cells[1][question_id_to_rownum[bmi_id]] = "";    }    if(rownum_to_question_id[ARow] == systolic_id || rownum_to_question_id[ARow] == diastolic_id)    {      string systolic_str  = gridVitalsEntry->Cells[1][question_id_to_rownum[systolic_id]].c_str();      string diastolic_str = gridVitalsEntry->Cells[1][question_id_to_rownum[diastolic_id]].c_str();      if(systolic_str != "" && diastolic_str != "" &&      // not blanks;         (IsInt(systolic_str)  || IsFloat(systolic_str)) && // systolic BP is an int or float, and         (IsInt(diastolic_str) || IsFloat(diastolic_str)))      {        int systolic_bp  = (int)StringToFloat(systolic_str);        int diastolic_bp = (int)StringToFloat(diastolic_str);        gridVitalsEntry->Cells[1][question_id_to_rownum[slash_id]] =          (IntToString(systolic_bp) + "/" + IntToString(diastolic_bp)).c_str();      }      else        gridVitalsEntry->Cells[1][question_id_to_rownum[slash_id]] = "";    }  }}//----------------------------------------------------------------------------------------------------------------------