List Next Treatment Plan Reviews

This query demonstrates the use of a subquery to create values in a column — nextreviewdate, in this case. Adjust the date range as needed.

        (SELECT MIN(nextreviewdate)
                 FROM sos.v_tpreviews
                 WHERE ptepisodenum = b.ptepisodenum
                 AND tpheadernum = c.tpheadernum
                 AND spv_signandfinalize = 1
                 AND rowstatus = 'O' ),c.nextreviewdate)
    )) AS nextreviewdate,
    (a.lastname+', '+a.firstname+' / ' AS "Patient",
    d.provcode AS "Primary Provider"
  sos.patients a
  JOIN sos.ptepisodes b ON a.ptnum = b.ptnum
  JOIN sos.tpheaders c ON b.ptepisodenum = c.ptepisodenum
  LEFT OUTER JOIN sos.providers d ON b.providernum = d.providernum
   a.flag = 0
   AND b.currentflag = 1
   AND a.dischargedate IS NULL
   AND nextreviewdate BETWEEN '2009-09-01' AND '2009-09-30'
ORDER BY "NextReviewDate","Patient"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.