Hello, I hope you are doing well. I am encountering a problem with the database I am using for OpenMRS. All the tables have been created properly, but they are empty, and when I fill out forms, I am unable to find this data in the tables. Someone can help me?
Can you first select everything within patient.without where. Something like SELECT *FROM patient;
and strangely when I try to find a patient who already exists on open mrs or that I have created it shows me empty
@christiantsopkeng you should select the appropriate database for the instance you’re running. Ideally, the database name should match the OpenMRS instance name especially if it’s run by the OpenMRS SDK tool (on the same MySQL/Maria DB server). Could you run show databases;
and then select <correct_database_name>
to use the correct database?
So by doing SELECT *FROM patient WHERE patient_id='10001MJ'
you are not doing it right. 10001MJ
is actually a patient identifier so must be found within the patient_identifier
table. Have a look at the data model showing what i am talking about → OpenMRS Reference Application 1.9 Data Model
Your SQL query should look something like below in order to get the particular patient and their given details from the various tables related to patient.
SELECT p.patient_id, pe.person_id, pe.gender, pe.birthdate, pn.given_name AS first_name, pn.family_name AS last_name FROM patient_identifier pi JOIN patient p ON pi.patient_id = p.patient_id JOIN person pe ON p.patient_id = pe.person_id JOIN person_name pn ON pe.person_id = pn.person_id WHERE pi.identifier = '10001MJ';
Also keep note of the exact database name you’re querying against just like @ruhanga has stated above.