Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is how my data looks:
635584 8/10/2012   Family Medicine  Ba NP            
635584 4/18/2013   Family Medicine  Egan MD 
635584 3/17/2014   Women's Health   Prenatal Registration   
635584 6/2/2014    Family Medicine  Matathia        
635584 8/5/2014    Women's Health   Forman CNM     


I want to only pull the latest appointment which was 8/5/14, I created the formula:
maximum({Command.lastappt}) and was able to do just that!

but I also got the providers too...
635584 8/5/2014   Family Medicine  Ba NP            
635584 8/5/2014   Family Medicine  Egan MD 
635584 8/5/2014   Women's Health   Prenatal Registration   
635584 8/5/2014   Family Medicine  Matathia        
635584 8/5/2014   Women's Health   Forman CNM  


So I went ahead and did this...
maximum({Command.lastappt}) & " " & {Command.provider}

and it gave me the same results.

It works the same way even if I group by Provider. What's the best approach?

Thanks in advance!
Posted
Updated 27-Aug-14 3:57am
v2
Comments
Kschuler 25-Aug-14 17:03pm    
Where are you putting this formula? Is this data all in table? Or is it pulling from several? If several, have you setup your database links in the Database Expert?

1 solution

I'm adding a formula in Crystal and adding a command in the Database Expert, below is the sql I'm using, innerjoin on PatientProfileId:

CPSDORDB
select a.PatientProfileId,
a.MedicalRecordNumber,
a.searchname,
a.edcdate, a.wk, b.lastappt from
(SELECT PatientProfile.PID,PatientProfile.PatientProfileID, PatientProfile.MedicalRecordNumber,
PatientProfile.searchname,
EDCDATE=case when isdate(max(RPTOBS.obsvalue))=1 then max(RPTOBS.obsvalue) end,
WK=case when isdate(max(RPTOBS.obsvalue))=1 then 40-DATEDIFF(d,getdate(),max(RPTOBS.obsvalue))/7 end
FROM OBSHEAD OBSHEAD
INNER JOIN ((PatientProfile PatientProfile
INNER JOIN DOCUMENT DOCUMENT ON PatientProfile.PId=DOCUMENT.PID)
INNER JOIN RPTOBS RPTOBS ON (DOCUMENT.PID=RPTOBS.pid)
AND (DOCUMENT.SDID=RPTOBS.sdid)) ON OBSHEAD.HDID=RPTOBS.hdid
WHERE
RPTOBs.hdid='8086'
group by PatientProfile.PID,PatientProfile.PatientProfileID, PatientProfile.MedicalRecordNumber,
PatientProfile.searchname)a
inner join
(Select a.ownerid, p.patientprofileid, p.searchname, max(a.ApptStart) as LastAppt
from Appointments a
left join patientprofile p on p.PatientProfileId= a.OwnerId
inner join DoctorFacility f on f.DoctorFacilityId = a.FacilityId
inner join DoctorFacility d on d.DoctorFacilityId = a.ResourceId
where a.FacilityId in ('127','64') and
a.Status in ('Completed','Arrived')
group by a.OwnerId,p.patientprofileid, p.searchname) b
on a.patientprofileid = b.patientprofileid

where EDCDATE>=cast(GETDATE() as DATE)-- and a.PatientProfileId = '635584'
group by a.PatientProfileId,
a.MedicalRecordNumber,
a.searchname,a.edcdate,
a.wk, b.lastappt
EXTERNAL JOIN Command.PatientProfileId={?CPSDORDB: Command_1.patientprofileid}


CPSDORDB
Select a.ownerid, p.patientprofileid, p.medicalrecordnumber, p.searchname, min(a.ApptStart) as NextAppt, d.listname
from Appointments a
left join patientprofile p on p.PatientProfileId= a.OwnerId
inner join DoctorFacility f on f.DoctorFacilityId = a.FacilityId
inner join DoctorFacility d on d.DoctorFacilityId = a.ResourceId
where a.FacilityId in ('127','64') and
a.Status = 'Scheduled' and
a.ApptTypeId in ('15','10','181','25','24','263','235','89','90')
--and a.ownerid = '635584'

group by a.OwnerId,p.patientprofileid, p.MedicalRecordNumber, p.searchname, d.listname
order by p.MedicalRecordNumber
EXTERNAL JOIN Command_1.patientprofileid={?CPSDORDB: Command.PatientProfileId}
 
Share this answer
 
Comments
[no name] 10-Jun-15 3:21am    
Thanks in advance!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900