updated user manual wiki page link for future 4.1.2
[openemr.git] / Documentation / OpenEMR_Backend_Spec.txt
blob29fd3e99e07de1d1d2b5f3d36a0253938e192fff
1 ********** internal backend functions **********
3 ----- library/auth.inc ------
5 NOTICE: Please note that this Backend Spec is a development document, and was used during the developmental stages of OpenEMR. It was last updated for OpenEMR version 1.3, and therefore does not completely detail all of the newer library functions.
7 --------------------------------------------------------
9 we will ALWAYS look for $_GET['auth'], if it is login we will do so, if it is logout we will do so. all our post vars must be set to have a chance getting in.  auth.inc should ALWAYS BE CALLED ABSOLUTELY FIRST.
11 authNewSession(username, md5sum of password, provider)
12 returns boolean, is pass checks out or not.  if true, also sets:
13         $_SESSION['authUser'] = current username logged in
14         $_SESSION['authProvider'] = the current provider
15         $_SESSION['authId'] = user Id number (record id)
17 authCheckSession()
18 returns boolean for whether current cookie checks out
20 authCloseSession()
21 returns nothing, runs a session_destroy
23 authLoginScreen()
24 returns nothing. includes js file, then login.inc, and die()
26 addUser(username, password, info, authorized w/ default yes)
27 adds a user to the system with the given credentials
28 returns the unique ID of the user with the given information
29 password is an MD5 hash
31 delUser(id)
32 deletes the user with the given ID from the system
34 changePassword(id, password)
35 changes the password of the user with the given id to password
36 password is an MD5 hash
38 getUserList(cols w/default *, limit w/default all, start w/default 0)
39 returns a nested array of the user information specified in cols
41 getProviderList(cols w/default *, limit w/ default all, start w/ default
43 return a nested array of cols from the groups table
45 addGroup(groupname)
46 add a new group name to the system
47 returns the ID of the group
49 delGroup(groupname)
50 deletes the group from the system
52 ----- library/sql.inc - Matthew Beale, Ted Dziuba -----
53 we will ALWAYS create a connection to sql, and set $GLOBALS['dbh']  to our database connection.
55 sqlConnect()
56 returns a database handle, connected to localhost, user openemr, db openemr
58 sqlStatement(statement)
59 returns the query result resource.
61 sqlClose()
62 returns whatever mysql_close returns.
64 sqlInsert(statement)
65 returns the last inserted id after running your insert.
67 sqlFetchArray(mysql query result resource)
68 returns the current mysql_fetch_array result.
70 sqlQuery(statement)
71 returns the first result from the database.
74 ********** public backend functions **********
76 ----- library/lists.inc - Matthew Beale -----
77 used for accessing openemr.lists in the db, we require_once('sql.inc')
79 getListById(id, columns - default all)
80 returns the first record returned, the most recent (although there _should_ only be one.
82 getListByType(patient id, type, wanted columns w/ deafult all, active - default 'all', limit default "all", offset default "0")
83 returns a multi-dimensional array or record lines returned.
85 addList(patient id, entry type, title, comments, activity state w/ default active)
86 returns the id generated by the insert
88 disappearList (id)
89 returns true
91 reappearList (id)
92 returns true
94 ----- library/transactions.inc - Matt Koch, Matthew Beale ------
95 used for accessing openemr.transactions in the db, we require_once('sql.inc')
97 getTransById(id, columns - default all)
98 returns the first record returned, the most recent (although there _should_ only be one.
100 getTransByPid(patient id, columns w/ default all)
101 returns a multi-dimensional array or record lines returned.
103 newTransaction(patient id, body text, title, authorized w/ default "0")
104 returns id of inserted record
106 authorizeTransaction(id, authorized w/ default '1')
107 returns useless data. if you want it to return something let us know.
109 ----- library/pnotes.inc - Matt Koch, Matthew Beale -----
110 used for accessing openemr.pnotes in the db, we require_once('sql.inc')
112 getByPnoteId(id, columns - default all)
113 returns the first record returned, the most recent (although there _should_ only be one.
115 getPnotesByDate(date, activity w/ default "1", columns w/ default "*", patient id - default "%", limit w/ default "all", start w/ default 0)
116 returns a multi-dimensional array or record lines returned.
118 getPnotesByPid(patient id, activity w/ default "1", columns w/ default all, limit - 10, start - 0)
119 returns a multi-dimensional array or record lines returned.
121 addPnote(patient id, body text, authorized w/ default "0", activity w/ default "1")
122 returns the id of the insert.
124 authorizePnote(id, authorize w/ default "1")
125 returns useless data. if you want it to return something let us know.
127 disappearPnote (id)
128 returns true
130 reappearPnote (id)
131 returns true
133 ----- library/onotes.inc - Ted Dziuba, Matthew Beale -----
134 used for accessing openemr.onotes, we require('sql.inc')
136 getOnoteById(id, cols wanted w/default all)
137 returns the first record returned, the most recent
139 getOnoteByDate(date, activity w/ default "1" (can take 0, 1, or all), cols wanted w/default all,limit - "all", offset w/ default "0")
140 returns a multi-dimensional array or record of lines returned
142 addOnote(body text, $activity w/ default "1")
143 returns the id you just generated, dont you feel lucky.
145 disappearOnote (id)
146 returns true
148 reappearOnote (id)
149 returns true
151 ----- library/forms.inc - Ted Dziuba, Matthew Koch -----
153 getFormById(id, cols - "*")
154 returns form with specified id
156 getFormsByPID (pid, columns w/ default all)
157 returns form with specified PID
159 getFormByEncounter(pid, encounter, columns w/ default "form_id, form_name")
160 return forms matching encounter in multi-dimensional array
162 addForm(encounter, form_name, form_id, formdir, pid, authorized w/ default "0")
163 adds form with specified values, returns id
165 authorizeForm(id, authorize w/ default "1")
166 returns useless data. if you want it to return something let us know.
168 function getEncounters($pid)
169 returns array of all encounters filed under a given pid, in order by date descending
171 ----- library/billing.inc - Matthew Beale, Ted Dziuba -----
173 getBillingById(id, cols w/ default all)
174 returns billing record from id
176 getBillingByPid(pid, columns w/ default all)
177 returns billing record from pid
179 getBillingByEncounter(pid,encounter id, columns w/ defaults "code_type, code, code_text")
180 return billings matching encounter in multi-dimensional array
182 addBilling(encounter, code_type, code, $code_text, pid, authorized w/ default "0")
183 adds billing entry with values, returns id
185 authorizeBilling(id, authorize w/ default "1")
186 returns useless data. if you want it to return something let us know
188 function deleteBilling($id)
189 makes a billing entry not active - misnomer - does not actually delete it, but makes it invisible to interface
190 ----- library/log.inc - Matthew Beale, Ted Dziuba -----
192 newEvent(event(login||logout||backup||view), user, groupname, comment w/ default "")
193 return id generated in insert
195 getEventByDate($date, $cols w/ default all)
196 returns nested array of results
199 ----- library/patient.inc - Matthew Beale, Ted Dziuba -----
201 DEPRECATED
202 getPatientById(id, cols w/default *, type w/ default "primary") << "table_name_col_name, table2_name_col2_name"
203 return array of patient information in cols of the patient with pid id
205 DEPRECATED
206 getPatientByLname(lname, cols w/default *, type w/ default "primary") << as above
207 return array of patient information in cols of the patient with lname
209 DEPRECATED
210 getPatients(cols w/default "patient_data_name, patient_data_fname, patient_data_lname")
211 returns nested array of said values.
213 newPatientData(         $title, //all default "" unless specified
214                         $fname,
215                         $lname,
216                         $mname,
217                         $sex,
218                         $DOB,
219                         $street,
220                         $postal_code,
221                         $city,
222                         $state,
223                         $country_code,
224                         $ss,
225                         $occupation,
226                         $phone_home,
227                         $phone_biz,
228                         $phone_contact,
229                         $contact_relationship,
230                         $pid w/ default "MAX(pid)+1"
231                 )
232 returns generated pid, new or old.
234 function newEmployerData(       $pid,
235                                 $name, //all default "" unless specified
236                                 $street,
237                                 $postal_code,
238                                 $city,
239                                 $state,
240                                 $country
241                         )
242 returns generated id
244 function newInsuranceData(      $pid,
245                                 $type, //all default "" unless specified
246                                 $provider,
247                                 $policy_number,
248                                 $group_number,
249                                 $subscriber,
250                                 $subscriber_relationship,
251                                 $subscriber_ss,
252                                 $subscriber_DOB,
253                                 $subscriber_street,
254                                 $subscriber_postal_code,
255                                 $subscriber_city,
256                                 $subscriber_state,
257                                 $subscriber_country,
258                                 $subscriber_employer,
259                                 $subscriber_employer_street,
260                                 $subscriber_employer_postal_code,
261                                 $subscriber_employer_state,
262                                 $subscriber_employer_country,
263                                 $copay
264                         )
265 returns generated id
267 function newHistoryData(        $pid,
268                                 $coffee, //all default "" unless specified
269                                 $tobacco,
270                                 $alchohol,
271                                 $sleep_patterns,
272                                 $exercise_patterns,
273                                 $seatbelt_use,
274                                 $counseling,
275                                 $hazardous_activities,
276                                 $last_breast_exam,
277                                 $last_mammogram,
278                                 $last_gynocological_exam,
279                                 $last_rectal_exam,
280                                 $last_prostate_exam,
281                                 $last_phyiscal_exam,
282                                 $last_sigmoidoscopy_colonoscopy,
283                                 $history_mother,
284                                 $history_father,
285                                 $history_siblings,
286                                 $history_offspring,
287                                 $history_spouse,
288                                 $relatives_cancer,
289                                 $relatives_tuberculosis,
290                                 $relatives_diabetes,
291                                 $relatives_high_blood_pressite,
292                                 $relatives_heart_problems,
293                                 $relatives_stroke,
294                                 $relatives_epilepsy,
295                                 $relatives_mental_illness,
296                                 $relatives_suicide,
297                                 $cataract_surgery,
298                                 $tonsillectomy,
299                                 $appendectomy,
300                                 $cholecystestomy,
301                                 $heart_surgery,
302                                 $hysterectomy,
303                                 $hernia_repair,
304                                 $hip_replacement
305                                 )
306 returns id generated
308 updatePatientData(pid, array of new datas:
309         $passed['colname'] = "value string"
310 returns id generated
312 updateInsuranceData(pid, array of new datas:
313         $passed['colname'] = "value string"
314 returns id generated
316 updateEmployerData(pid, array of new datas:
317         $passed['colname'] = "value string"
318 returns id generated
319         
320 updateHistoryData(pid, array of new datas:
321         $passed['colname'] = "value string"
322 returns id generated
323         
324 getPatientData(pid, cols w/ default *)
325 returns array of cols specified by given with pid id
327 getHistoryData(pid, cols w/ default *)
328 returns array of cols specified by given with pid id
330 getInsuranceData(pid, type w/ default primary, cols w/ default *)
331 return array of cols specified by given from patient with pid id and type primary or secondary
333 getEmployerData(pid, cols w/ default *)
334 return array of cols specified by given of patient with pid id
336 getPatientLnames(lname, cols w/default = "pid, lname, fname, mname, id", orderby w/ default "lname ASC", limit w/ default "all", start w/ default "0")
337 return array of cols specified by given of patients with last name lname
339 getPatientIds(cols w/ default "pid, id, lname, fname, mname", orderby w/ default "id ASC", limit w/ default "all", start w/ default "0")
340 returns array of cols specified by cols of all unique pids
342 ----- library/report.inc - Matthew Beale -----
344 getPatientReport(pid)
345 returns nested array of column name containing 'content' at time of change and 'date'
347 getEmployeeReport(pid)
348 returns nested array of column name containing 'content' at time of change and 'date'
350 getHistoryReport(pid)
351 returns nested array of column name containing 'content' at time of change and 'date
353 getInsuranceReport(pid, type)
354 returns nested array of column name containing 'content' at time of change and 'date
357 ----- library/encounter.inc - Matthew Stack -----
359 function setencounter(encounter)
360 set the global encounter session variable - if encounter is "", then it creates an entry in the forms table to represent a blank encounter
362 ----- library/pid.inc - Matthew Stack -----
364 function setpid(pid)
365 set the global pid session variable