Can't create New Encounter w 7.0.2.1 & Older Encounters have lots of code that shouldn't be there

Situation
Creating a new encounter does this:

SQL Statement failed on preparation: INSERT INTO form_encounter SET date = ?, onset_date = ?, reason = ?, facility = ?, pc_catid = ?, facility_id = ?, billing_facility = ?, sensitivity = ?, referral_source = ?, pid = ?, encounter = ?, pos_code = ?, class_code = ?, external_id = ?, parent_encounter_id = ?, provider_id = ?, discharge_disposition = ?, referring_provider_id = ?, encounter_type_code = ?, encounter_type_description = ?, in_collection = ?, ordering_provider_id = ?’

Query Error

ERROR: insert failed: INSERT INTO form_encounter SET date = ?, onset_date = ?, reason = ?, facility = ?, pc_catid = ?, facility_id = ?, billing_facility = ?, sensitivity = ?, referral_source = ?, pid = ?, encounter = ?, pos_code = ?, class_code = ?, external_id = ?, parent_encounter_id = ?, provider_id = ?, discharge_disposition = ?, referring_provider_id = ?, encounter_type_code = ?, encounter_type_description = ?, in_collection = ?, ordering_provider_id = ?

Error: Unknown column ‘ordering_provider_id’ in ‘field list’

C:\xampp\htdocs\openemr\interface\forms\newpatient\save.php at 122:sqlInsert

Opening up an old encounter shows this:

SQL Statement failed on preparation: SELECT fe.eid, fe.euuid, fe.date, fe.reason, fe.onset_date, fe.sensitivity, fe.billing_note, fe.pc_catid, fe.last_level_billed, fe.last_level_closed, fe.last_stmt_date, fe.stmt_count, fe.supervisor_id, fe.invoice_refno, fe.referral_source, fe.billing_facility, fe.external_id, fe.last_update, fe.pos_code, fe.class_code, class.notes as class_title, opc.pc_catname, patient.pid, patient.puuid, facilities.facility_id, facilities.facility_uuid, facilities.facility_name, facilities.facility_location_uuid, fa.billing_facility_id, fa.billing_facility_uuid, fa.billing_facility_name, fa.billing_location_uuid, fe.provider_id, fe.referring_provider_id, fe.ordering_provider_id, providers.provider_uuid, providers.provider_username, referrers.referrer_uuid, referrers.referrer_username, fe.discharge_disposition, discharge_list.discharge_disposition_text FROM ( select encounter as eid, uuid as euuid, date, reason, onset_date, sensitivity, billing_note, pc_catid, last_level_billed, last_level_closed, last_stmt_date, stmt_count, provider_id, supervisor_id, invoice_refno, referral_source, billing_facility, external_id, pos_code, class_code, facility_id, discharge_disposition, pid as encounter_pid, referring_provider_id, ordering_provider_id, last_update FROM form_encounter ) fe LEFT JOIN openemr_postcalendar_categories as opc ON opc.pc_catid = fe.pc_catid LEFT JOIN list_options as class ON class.option_id = fe.class_code LEFT JOIN ( select facility.id AS billing_facility_id ,facility.uuid AS billing_facility_uuid ,facility.name AS billing_facility_name ,locations.uuid AS billing_location_uuid from facility LEFT JOIN uuid_mapping AS locations ON locations.target_uuid = facility.uuid AND locations.resource=‘Location’ ) fa ON fa.billing_facility_id = fe.billing_facility LEFT JOIN ( select pid ,uuid AS puuid FROM patient_data ) patient ON fe.encounter_pid = patient.pid LEFT JOIN ( select id AS provider_provider_id ,uuid AS provider_uuid ,username AS provider_username FROM users WHERE npi IS NOT NULL and npi != ‘’ ) providers ON fe.provider_id = providers.provider_provider_id LEFT JOIN ( select id AS referring_provider_id ,uuid AS referrer_uuid ,username AS referrer_username FROM users WHERE npi IS NOT NULL and npi != ‘’ ) referrers ON fe.referring_provider_id = referrers.referring_provider_id LEFT JOIN ( select facility.id AS facility_id ,facility.uuid AS facility_uuid ,facility.name AS facility_name ,locations.uuid AS facility_location_uuid from facility LEFT JOIN uuid_mapping AS locations ON locations.target_uuid = facility.uuid AND locations.resource=‘Location’ ) facilities ON facilities.facility_id = fe.facility_id LEFT JOIN ( select option_id AS discharge_option_id ,title AS discharge_disposition_text FROM list_options WHERE list_id = ‘discharge-disposition’ ) discharge_list ON fe.discharge_disposition = discharge_list.discharge_option_id WHERE BINARY pid = ? AND BINARY eid = ? ORDER BY fe.eid DESC’



OpenEMR Version
I’m using OpenEMR version

Browser:
I’m using:

Operating System
I’m using: W10

Search
Yarp.

Logs
Did you check the logs?
[Fri May 31 10:37:38.910255 2024] [php:notice] [pid 17640:tid 1828] [client 192.168.86.131:51486] SQL Error with statement:insert failed: INSERT INTO form_encounter SET date = ?, onset_date = ?, reason = ?, facility = ?, pc_catid = ?, facility_id = ?, billing_facility = ?, sensitivity = ?, referral_source = ?, pid = ?, encounter = ?, pos_code = ?, class_code = ?, external_id = ?, parent_encounter_id = ?, provider_id = ?, discharge_disposition = ?, referring_provider_id = ?, encounter_type_code = ?, encounter_type_description = ?, in_collection = ?, ordering_provider_id = ?--Unknown column 'ordering_provider_id' in 'field list'==>C:\\xampp\\htdocs\\openemr\\interface\\forms\\newpatient\\save.php at 122:sqlInsert, referer: http://192.168.86.78/openemr/interface/forms/newpatient/new.php?autoloaded=1&calenc=

Why is it most people don’t follow our patch instructions! You need to run sql_patch.php from browser so


#IfMissingColumn form_encounter ordering_provider_id
ALTER TABLE `form_encounter` ADD `ordering_provider_id` INT(11) DEFAULT '0' COMMENT 'ordering provider, if any, for this visit';
#EndIf

1 Like

That worked! Thanks!