Hey folks! I am wanting to write a script to upload patients from a CSV file. I need to first check if the user exists, and if they do not, then create them. Here is what I have at the moment https://gist.github.com/marklocklear/da925c519a84665bac0ece71fa11e9f3.
This works fine to query whether or not the patient exists but then dies when trying to create patients. Actually, it creates the first patient, but then dies on subsequent patients with the error Duplicate entry ‘0’ for key ‘patient_data.pid’ due to the fact that the pid is being set to 0 and is not being autoincremented (assuming that is even OK).
I am a noob to openemr and am just figuring things out as I go. Is it OK to query and find the last/highest pid and just start autoincrementing from there? Ideally I’d like to call openemr methods to do this work, but do they exist? I found library/patient.inc and the newPatientData() which looks promising, but I’m not sure how to call this method from within my script.
I did try adding require_once DIR.’/interface/globals.php’ to my script in hopes of getting access to some of these methods but am getting the error Site ID is missing from session data! when I try that.
Any help or direction is appreciated.