Skip to content

Commit

Permalink
Performance Profile Tuning (openemr#3598)
Browse files Browse the repository at this point in the history
* Profile Tuning [WIP]
- combine reminders to one ajax call
- mod globals for session write type flags
- eob invoice bug fix

* - add flag for <7.3

* - revert old flags for new default read and close

* dealing with prior session_write_close() calls, api, and commandline driven scripts

* fix to remove session write requirement from last_updated

* - removed jsFetchGlobals
- but we have js xl()
- clean up main.php some
- replaced a couple ajaxs

* - oops forgot delete

* - fix dup dependencies

* session work

1. fix line 222 of clinical_rules.php and line 28 of active_reminder_popup.php (DONE)
2. look at setencounter php function (library/encounter.inc) use in interface/patient_file/encounter/encounter_top.php and interface/forms/newpatient/save.php (DONE)
3. look at setpid php function (library/pid.inc) use in 11 scripts (DONE)
4. a lot of form saves (maybe every save form) will modify the encounter session. Just removed them all :) (DONE)
5. calendar/index.php does quite a few session edits. Had to block entire calendar, but this is something that we should be able to clean all session writes from and will have big impact since calendar load time is so long. (TEMPORARILY DONE BUT PLAN TO LOOK INTO MORE)
6. some misc items (PENDING)

phpstorm regex search using:
`^\s*\$_SESSION.*=` (PENDING)
`^\s*\$_SESSION\[['"]pid.*=` (DONE)
`^\s*\$_SESSION\[['"]encounter.*=` (DONE)

* couple loose ends

* -- add setSession and unsetSession to Session class
-- rework pid and encounter includes

* used Session Master's (aka Jerry) technique to turbo charge session performance

* quick fix

* bug fix, psr2 fix, comments, and misc

1. Fixed issue where the form_tracker code war running in patient summary when not
   supposed to be.
2. Added some comments to code so don't forget why we did what we did
3. PSR2 fix
4. Incremented database counter

Co-authored-by: Brady Miller <[email protected]>
  • Loading branch information
sjpadgett and bradymiller committed Jun 10, 2020
1 parent 674c2f9 commit d76c881
Show file tree
Hide file tree
Showing 95 changed files with 1,893 additions and 1,882 deletions.
6 changes: 6 additions & 0 deletions apis/dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
}
}

// Set $sessionAllowWrite to true here for following reasons:
// 1. !$isLocalApi - in this case setting sessions far downstream and no benefit to set to false since single process
// 2. $isLocalApi - in this case, basically setting this to true downstream after some session sets via session_write_close() call
$sessionAllowWrite = true;
require_once("./../interface/globals.php");

use OpenEMR\Common\Csrf\CsrfUtils;
Expand Down Expand Up @@ -155,6 +159,8 @@

if ($isLocalApi) {
// Ensure that a local process does not hold up other processes
// Note can not do this for !$isLocalApi since need to be able to set
// session variables and it won't help performance anyways.
session_write_close();
}

Expand Down
4 changes: 3 additions & 1 deletion ccdaservice/ccda_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
$_SESSION ['site_id'] = 'default';
}

// This is to close session write access when called from portal (core session already can not write to session)
session_write_close();

$server_url = $_SERVER['HTTP_HOST'] . $GLOBALS['webroot'];
// CCM returns entire cda with service doing templates
$ccdaxml = portalccdafetching($pid, $server_url, $parameterArray);
Expand All @@ -85,7 +88,6 @@

function portalccdafetching($pid, $server_url, $parameterArray)
{
session_write_close();
$site_id = $_SESSION['site_id'];
$parameters = http_build_query($parameterArray); // future use
try {
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"autoload": {
"exclude-from-classmap": [
"src/Common/Compatibility/Checker.php",
"src/Common/Session/SessionUtil.php",
"library/classes/ClinicalTypes/",
"library/classes/rulesets/",
"library/classes/smtp/"
Expand Down
5 changes: 2 additions & 3 deletions contrib/forms/assessment_intake/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"update form_assessment_intake set pid = ?,
groupname=?,
user=?,
authorized=?, activity=1, date = NOW(),
dcn=?,
authorized=?, activity=1, date = NOW(),
dcn=?,
location=?,
time_in=?,
time_out=?,
Expand Down Expand Up @@ -301,7 +301,6 @@
);
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
3 changes: 1 addition & 2 deletions contrib/forms/contacts/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
addForm($encounter, "Contacts", $newid, "contacts", $pid, $userauthorized);
} elseif ($_GET["mode"] == "update") {
sqlStatement("update form_contacts set pid = ?,groupname= ?,user= ?, authorized= ?,activity=1, date = NOW(), od_base_curve= ?, od_sphere= ?, od_cylinder= ?,
od_axis= ?, od_diameter= ?, os_base_curve= ?, os_sphere= ?, os_cylinder= ?, os_axis= ?, os_diameter= ?, material= ?, color= ?, bifocal_type= ?,
od_axis= ?, od_diameter= ?, os_base_curve= ?, os_sphere= ?, os_cylinder= ?, os_axis= ?, os_diameter= ?, material= ?, color= ?, bifocal_type= ?,
add_value= ?, va_far= ?, va_near= ?, additional_notes= ? WHERE id= ?", array($_SESSION["pid"], $_SESSION["authProvider"], $_SESSION["authUser"], $userauthorized, $_POST["od_base_curve"], $_POST["od_sphere"], $_POST["od_cylinder"],
$_POST["od_axis"], $_POST["od_diameter"], $_POST["os_base_curve"], $_POST["os_sphere"], $_POST["os_cylinder"], $_POST["os_axis"], $_POST["os_diameter"],
$_POST["material"], $_POST["color"], $_POST["bifocal_type"], $_POST["add_value"], $_POST["va_far"], $_POST["va_near"], $_POST["additional_notes"], $id));
}
$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
1 change: 0 additions & 1 deletion contrib/forms/example2/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
$success = formUpdate($table_name, $_POST, $_GET["id"], $userauthorized);
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
1 change: 0 additions & 1 deletion contrib/forms/formmaker/formscript.pl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
if ($_GET["mode"] == "new"){
reset($field_names);
NOREDIRECT
$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
Expand Down
1 change: 0 additions & 1 deletion contrib/forms/hearingtest/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
);
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
3 changes: 1 addition & 2 deletions contrib/forms/individual_treatment_plan/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

addForm($encounter, "Individual Treatment Plan", $newid, "individual_treatment_plan", $pid, $userauthorized);
} elseif ($_GET["mode"] == "update") {
sqlStatement("update form_individual_treatment_plan set pid = ?, groupname= ?, user = ?, authorized = ?, activity=1, date = NOW(),
sqlStatement("update form_individual_treatment_plan set pid = ?, groupname= ?, user = ?, authorized = ?, activity=1, date = NOW(),
date_of_referal = ?,
dcn = ?,
icd9 = ?,
Expand Down Expand Up @@ -50,7 +50,6 @@
$_POST["medications_2"], $_POST["referrals_1"], $_POST["referrals_2"], $id));
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
7 changes: 3 additions & 4 deletions contrib/forms/obstetrical/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
addForm($encounter, "Obstetrical Form", $newid, "obstetrical", $pid, $userauthorized);
} elseif ($_GET["mode"] == "update") {
sqlStatement("update form_obstetrical set pid = ?,groupname= ?, user= ?,authorized= ?, activity= 1, date = NOW(), name= ?, birthdate= ?, feeding= ?,
birth_status= ?, gender= ?, circumcised= ?, delivery_method= ?, labor_hours= ?, birth_weight= ?, pregnancy_weeks= ?,
anesthesia= ?, pediatrician= ?, length_inches= ?, head_circumference_inches= ?, reactions_to_medications_and_immunizations= ?, birth_complications= ?,
developmental_problems= ?, chronic_illness= ?, chronic_medication= ?, hospitalization= ?, surgery= ?,
birth_status= ?, gender= ?, circumcised= ?, delivery_method= ?, labor_hours= ?, birth_weight= ?, pregnancy_weeks= ?,
anesthesia= ?, pediatrician= ?, length_inches= ?, head_circumference_inches= ?, reactions_to_medications_and_immunizations= ?, birth_complications= ?,
developmental_problems= ?, chronic_illness= ?, chronic_medication= ?, hospitalization= ?, surgery= ?,
injury= ?, day_care= ?, additional_notes= ? WHERE id= ?", array($_SESSION["pid"], $_SESSION["authProvider"], $_SESSION["authUser"], $userauthorized, $_POST["name"], $_POST["birthdate"], $_POST["feeding"], $_POST["birth_status"], $_POST["gender"], $_POST["circumcised"], $_POST["delivery_method"],
$_POST["labor_hours"], $_POST["birth_weight"], $_POST["pregnancy_weeks"], $_POST["anesthesia"], $_POST["pediatrician"], $_POST["length_inches"], $_POST["head_circumference_inches"], $_POST["reactions_to_medications_and_immunizations"], $_POST["birth_complications"],
$_POST["developmental_problems"], $_POST["chronic_illness"], $_POST["chronic_medication"], $_POST["hospitalization"], $_POST["injury"], $_POST["day_care"], $_POST["additional_notes"], $id));
}


$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
7 changes: 3 additions & 4 deletions contrib/forms/pain/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
$newid = formSubmit("form_pain", $_POST, $_GET["id"], $userauthorized);
addForm($encounter, "Pain Evaluation", $newid, "pain", $pid, $userauthorized);
} elseif ($_GET["mode"] == "update") {
sqlStatement("update form_pain set pid = ?,groupname = ?, user = ?, authorized = ?, activity = 1, date = NOW(), history_of_pain = ?,
dull = ?, colicky = ?, sharp = ?, duration_of_pain = ?, pain_referred_to_other_sites= ?, what_relieves_pain= ?,
what_makes_pain_worse= ?, accompanying_symptoms_vomitting= ?, accompanying_symptoms_nausea= ?,
sqlStatement("update form_pain set pid = ?,groupname = ?, user = ?, authorized = ?, activity = 1, date = NOW(), history_of_pain = ?,
dull = ?, colicky = ?, sharp = ?, duration_of_pain = ?, pain_referred_to_other_sites= ?, what_relieves_pain= ?,
what_makes_pain_worse= ?, accompanying_symptoms_vomitting= ?, accompanying_symptoms_nausea= ?,
accompanying_symptoms_headache = ?, accompanying_symptoms_other = ?, additional_notes= ? WHERE id = ?", array($_SESSION["pid"], $_SESSION["authProvider"], $_SESSION["authUser"], $userauthorized, $_POST["history_of_pain"], $_POST["dull"], $_POST["colicky"], $_POST["sharp"], $_POST["duration_of_pain"], $_POST["pain_referred_to_other_sites"],
$_POST["what_relieves_pain"], $_POST["what_makes_pain_worse"], $_POST["accompanying_symptoms_vomitting"], $_POST["accompanying_symptoms_nausea"], $_POST["accompanying_symptoms_headache"],
$_POST["accompanying_symptoms_other"], $_POST["additional_notes"], $id));
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
13 changes: 6 additions & 7 deletions contrib/forms/ped_GI/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
groupname = ?,
user = ?,
authorized = ?,
activity =1,
date = NOW(),
activity =1,
date = NOW(),
diarrhea = ?,
with_every_bowel_movement = ?,
after_every_meal = ?,
Expand All @@ -29,10 +29,10 @@
vomits = ?,
duration = ?,
projectile = ?,
more_often_than_2_hours = ?,
vomit_after_every_meal = ?,
blood_in_vomitus = ?,
taking_medication = ?,
more_often_than_2_hours = ?,
vomit_after_every_meal = ?,
blood_in_vomitus = ?,
taking_medication = ?,
oral_rehydration = ?,
eating_solid_food = ?,
fever = ?,
Expand All @@ -56,7 +56,6 @@
$_POST["siblings_affected"], $_POST["immunization_up_to_date"], $_POST["notes"], $id));
}

$_SESSION["encounter"] = $encounter;

formHeader("Redirecting....");
formJump();
Expand Down
3 changes: 1 addition & 2 deletions contrib/forms/ped_fever/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
groupname = ?,
user = ?
authorized =,
activity =1,
activity =1,
date = NOW(),
measured = ?,
duration = ?,
Expand All @@ -44,7 +44,6 @@
$_POST["siblings_affected"], $_POST["immunization_up_to_date"], $_POST["notes"], $id ));
}

$_SESSION["encounter"] = $encounter;

formHeader("Redirecting....");
formJump();
Expand Down
7 changes: 3 additions & 4 deletions contrib/forms/ped_pain/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
groupname = ?,
user = ?
authorized =,
activity =1,
activity =1,
date = NOW(),
location = ?,
duration = ?,
severity = ?,
fever = ?,
fever = ?,
lethargy = ?,
vomiting = ?,
vomiting = ?,
oral_hydration_capable = ?,
urine_output_last_6_hours = ?,
pain_with_urination = ?,
Expand All @@ -43,7 +43,6 @@
}


$_SESSION["encounter"] = $encounter;

formHeader("Redirecting....");
formJump();
Expand Down
11 changes: 5 additions & 6 deletions contrib/forms/psychiatrySet/brief_aan_verwijzer/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@
}
} elseif ($_GET["mode"] == "update") {
$strSql = "UPDATE form_brief_aan_verwijzer
SET pid = ?, groupname=?, user=?,
authorized=?, activity=1, date = NOW(),
SET pid = ?, groupname=?, user=?,
authorized=?, activity=1, date = NOW(),
introductie=?,
reden_van_aanmelding=?,
reden_van_aanmelding=?,
anamnese=?,
psychiatrisch_onderzoek=?,
beschrijvend_conclusie=?,
advies_beleid=?,
autosave_flag=0,
autosave_datetime=NOW()
autosave_flag=0,
autosave_datetime=NOW()
WHERE id = ?;";

sqlQuery($strSql, array($_SESSION["pid"], $_SESSION["authProvider"], $_SESSION["authUser"], $userauthorized, $_POST["introductie"], $_POST["reden_van_aanmelding"],
$_POST["anamnese"], $_POST["psychiatrisch_onderzoek"], $_POST["beschrijvend_conclusie"], $_POST["advies_beleid"], $newid));
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
13 changes: 6 additions & 7 deletions contrib/forms/psychiatrySet/intakeverslag/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
$newid = formUpdate("form_intakeverslag", $_POST, $_GET["saveid"], $userauthorized);
}
} elseif ($_GET["mode"] == "update") {
sqlQuery("UPDATE form_intakeverslag
SET pid = ?, groupname= ?, user= ?,
authorized=, activity=1, date = NOW(),
sqlQuery("UPDATE form_intakeverslag
SET pid = ?, groupname= ?, user= ?,
authorized=, activity=1, date = NOW(),
intakedatum=?,
reden_van_aanmelding=?,
reden_van_aanmelding=?,
klachten_probleemgebieden=?,
hulpverlening_onderzoek=?,
hulpvraag_en_doelen=?,
Expand All @@ -46,15 +46,14 @@
indruk_observaties=?,
beschrijvende_conclusie=?,
behandelvoorstel=?,
autosave_flag=0,
autosave_datetime=0
autosave_flag=0,
autosave_datetime=0
WHERE id = ?;", array($_SESSION["pid"], $_SESSION["authProvider"], $_SESSION["authUser"], $userauthorized, $_POST["intakedatum"], $_POST["reden_van_aanmelding"], $_POST["klachten_probleemgebieden"],
$_POST["hulpverlening_onderzoek"], $_POST["hulpvraag_en_doelen"], $_POST["bijzonderheden_systeem"], $_POST["werk_opleiding_vrije_tijdsbesteding"], $_POST["relatie_kinderen"], $_POST["somatische_context"],
$_POST["alcohol"], $_POST["drugs"], $_POST["roken"], $_POST["medicatie"], $_POST["familieanamnese"], $_POST["indruk_observaties"], $_POST["beschrijvende_conclusie"], $_POST["behandelvoorstel"],
$_GET["id"]));
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
9 changes: 4 additions & 5 deletions contrib/forms/psychiatrySet/psychiatrisch_onderzoek/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
}
} elseif ($_GET["mode"] == "update") {
$strSql = "UPDATE form_psychiatrisch_onderzoek
SET pid = ?, groupname=?, user=?,
authorized=?, activity=1, date = NOW(),
SET pid = ?, groupname=?, user=?,
authorized=?, activity=1, date = NOW(),
datum_onderzoek=?,
reden_van_aanmelding=?,
conclusie_van_intake=?,
Expand All @@ -40,15 +40,14 @@
psychiatrisch_onderzoek=?,
beschrijvende_conclusie=?,
behandelvoorstel=?,
autosave_flag=1,
autosave_datetime=NOW()
autosave_flag=1,
autosave_datetime=NOW()
WHERE id = ?;";

sqlQuery($strSql, array($_SESSION["pid"], $_SESSION["authProvider"], $_SESSION["authUser"], $userauthorized, $_POST["datum_onderzoek"], $_POST["reden_van_aanmelding"],
$_POST["conclusie_van_intake"], $_POST["medicatie"], $_POST["anamnese"], $_POST["psychiatrisch_onderzoek"], $_POST["beschrijvende_conclusie"], $_POST["behandelvoorstel"], $_GET["id"]));
}

$_SESSION["encounter"] = $encounter;
formHeader("Redirecting....");
formJump();
formFooter();
Loading

0 comments on commit d76c881

Please sign in to comment.