I just ran your code, here is an actual set of 6 records, same patient:
PTID CODE UNITS
1 100 1
1 100 1
1 100 -1
1 100 1
1 100 -1
1 100 1
These are all the same code, if it works on one, it will work on all
codes. The correct result is 2 units and 2 visits, the bottom four are
a wash, leaving the top two. Your code produced 6 visits and 2 units. I
would be happy just to get the visits. Not sure why your code did not
work, it looks correct.
Any suggestions? Thanks again.
James A. Fortune wrote:
> johngl wrote:
> > This is another question about eliminating accounting entries in a
> > clinical database, yet retaining the valid record. Latest wrinkle is
> > being able to sum the visits to the doctor, and the units of services
> > received. Here's the problem: If a visit is wrongly coded, then a
> > reverse entry is made as follows.
> > PTID CODE UNITS
> > 1 100 2
> > 1 100 -2
> > 1 110 2
> >
> > This is actually one visit for code 110 and the patient received 2
> > units of service. Thanks to a member's advice, I used:
> >
> > SELECT ptid, code, sum(units) AS unit
> > FROM PTDB
> > GROUP BY ptid, code
> > HAVING (((sum(units))<>0));
> >
> > This gives me a correct unit of service (I checked manually), but I
> > still need a field with a count of 1 for the visit. Most reports focus
> > on the number of visits taken, not how long much time you spent in the
> > office. Is there a way to get both sum of units and count of visits?
> > This is pretty basic stuff to most people, but it's killing me. Thks.
> >
>
> Air SQL:
>
> SELECT sum(1) AS visits, ptid, code, sum(units) AS unit FROM PTDB GROUP
> BY ptid, code HAVING (((sum(units))<>0));
>
> Only records that have not been cancelled will show up so the number of
> visits should be the same as the number of records returned by the query.
>
> James A. Fortune
> (E-Mail Removed)
>
> Wisconsin produces more cranberries than any other state. --
> http://www.wiscran.org/