I will preface this by saying I have a medical background and am a major novice at access but am trying my hand at making a database.
The context of this query is I have a database of patients where every record is a visit of theirs to a clinic where they get measurements. I need to distinguish patients that have 1) only pre operative measurements (before surgery) and 2) those with pre operative measurements AND post operative measurements (after surgery). I need to do this for patients who have had a particular diagnosis and surgery (as indicated by checkboxes) and pull all the records/visits of those patients.
Table: PtList
Preoperative Patients: Indicated by having checkbox (DiagnosisX = True) AND (SurgeryY = False). So the patient has the diagnosis I want but they haven't had surgery yet
Postoperative Patients: Indicated by having checkbox (DiagnosisX = True) AND (SurgeryY = False)
Patients are identified by "PatientID". They can have multiple visits that aren't necessarily a progression from Preop to Postop (ie they can have multiple Preop visits and not had surgery)
Basically, what I need is a way to query all the other records that are tied to the record that meets my criteria.
So far what I've come up with is just the logical flow from it, I don't yet know the proper syntax. However, it seems cumbersome and I am wondering if there is a better way. If not I am hoping for help with the code itself
For 1) Pre op only visits
Select * From PtList Where PatientID =/= True IN 'selects patients who do NOT have surgery checked off (does this work referencing "T" which appears within the statment?) from a subset of patients I already know I have a preop visit
Select PatientID From PtList As CC Where SurgeryY = True IN 'finds patients with a post op visit
Select PatientID From PtList As BB Where PatientID IN 'finds all visits from those patients that have a preop visit
Select PatientID From PtList As AA Where DiagnosisX = True AND SurgeryY = False 'finds patients with a preop visit
For 2) Pre and Post op visits:
Select * From PtList Where PatientID IN
Select PatientID From PTList As CC Where DiagosisX = True AND SurgeryY = True IN ' finds patient with a post op visit
Select PatientID From PtList As BB Where PatientID IN 'finds all visits from those patients that have a preop visit
(Select PatientID From PtList As AA Where DiagnosisX = True AND SurgeryY = False) 'finds patients with a preop visit
Also, I am a bit confused on where to us the "As" expression in this code but have put it where I think makes sense.
If all this can be answered with just some further reading on my end by all means point me in the right direction and no need to spend the time explaining.
Can not thank you guys enough for your help!