I am trying to run a SQL query that will allow me to grab any OBS values for a given time frame based on Visits. I use VISITS as my starting point. I had been able to join OBS based on PID and OBSdate to PID and Visitdate. This seemed to be working great until it relates to Tests. Because they may come back with a different OBSdate than the original Visit. I believe there is a way to use the DOCUMENT table in order to join them and get the result I am looking for. So far I have not had any luck. For full disclosure, I am by far a SQL expert, more of a novice. Any insight would be greatly appreciated. I can provide a sample of my Query if that would help.
Thanks,
Don
You can use the SDID column, which will link to your DOCUMENT table's SDID
Thank You for the responses and both of these work with the exception that the SDID from ORDERS to DOCUMENT can change if the DOCUMENT comes back at a later date.
For Example: I have an office Visit on 3/10/14 SDID:*7760 (I shortened the number for ease). Associated with this office visit is a Lab order on 3/10/14 SDID:*7760.
Now is where my confusion comes in. The Office Visit DOCUMENT SDID is *7760, so yes it links easily, but the LAB SDID is *8180 because it came back on a different date.
Then both SDID #'s link to the OBS table records with their associated SDID's. My question is how do I get the Labs to link back to the original order since they have different SDID and DATES associated with them. Maybe I am over thinking the issue. Any help would be appreciated.
Thanks,
Really, the SDID should never change if it came from that DOCUMENT. That is how it is linked to that DOCUMENT. And the OBS Table's SDID should also be the same as the DOCUMENT SDID. If they are Lab orders Results, you are talking about, then those do not link directly to your DOCUMENT as usually they create their own NEW DOCUMENT when the DTS imports them in.
acantu - Thank You, that is where I was over thinking it. I was so focused on getting the dates to match up. When all I have to do on my filters is key on the OBSdate instead of the visit date. Thanks for all of the help.