Relationship between patients and persons in datamodel

2 views
Skip to first unread message

Juan David Pastás Rivera

unread,
Aug 2, 2012, 6:50:51 PM8/2/12
to d...@openmrs.org
I'm implementing a ruby back-end for OpenMRS and I need to know what is the relationship between patients and persons in datamodel?

I don't see any key.

Thanks

Juan David Pastás Rivera

unread,
Aug 2, 2012, 7:12:46 PM8/2/12
to d...@openmrs.org
Ok, I've seen it in patient table:

CONSTRAINT `person_id_for_patient` FOREIGN KEY (`patient_id`) REFERENCES `person` (`person_id`) ON UPDATE CASCADE,

`patient_id` would be `person`.`person_id`

Burke Mamlin

unread,
Aug 2, 2012, 8:15:58 PM8/2/12
to d...@openmrs.org
We used to constrain the patient.patient_id to match person.person_id with the contraint you found; that was a mistake.  We corrected this by adding patient.person_id (at least as of 1.8).  Unfortunately, it appears patient.person_id didn't make it into our data model images (either 1.8 or 1.9). :-/

Cheers,

-Burke

--
-- OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org
Unsubscribe: dev+uns...@openmrs.org
 
 

Ben Wolfe

unread,
Aug 2, 2012, 8:32:28 PM8/2/12
to d...@openmrs.org

Actually, that was only user.person_id. We left patient as extending person. David has it right up through 1.9 at least.

Ben

Burke Mamlin

unread,
Aug 2, 2012, 11:47:22 PM8/2/12
to d...@openmrs.org
Oops.  Ben's right.  Duh.  Apparently "descirbe obs" isn't the right command to list the attributes of the patient table. ;-)

So, patient.person_id must equal person.person_id for now.  Hopefully the next time we need to touch the patient table, we can correct this under the hood by introducing patient.person_id.

-Burke

Ben Wolfe

unread,
Aug 3, 2012, 11:29:20 AM8/3/12
to d...@openmrs.org
If/when we make a change where patient.patient_id != person.person_id we will have to be very deliberate.  There are a lot of places in code that make that assumption.  There are reports that make that assumption.  Then there are all the queries/joins that implementers might be using with that assumption.

I'm not saying its impossible, I just think its a major change that might be better in the eventual "API 2.0" change. 

Ben

Burke Mamlin

unread,
Aug 3, 2012, 12:34:03 PM8/3/12
to d...@openmrs.org
I was imagining that when we next need to touch the patient_id table, we could add patient.person_id, keeping it identical to patient.patient_id (for now).  Then we could refactor the API to no longer assume patient.patient_id==person.person_id (instead, use patient.person_id) and encourage all future development to do the same.  Eventually, the need to keep them the same would fade (or at least be within reach).

-Burke

Darius Jazayeri

unread,
Aug 3, 2012, 12:43:36 PM8/3/12
to d...@openmrs.org
We should also add a method like this, so that people can actually start doing the right thing to start being future-proof.

class Patient {
    ...

    Person getPerson() {
        return this;
    }

}


-Darius
Reply all
Reply to author
Forward
0 new messages