Completed Patients With Address For Mail Merge

We are looking to send a brief survey to patients who have recently completed treatment.  We hope to use their feedback to improve our services.  Since insurance companies have been moving in the direction of wanting to see quality of service, this could come in handy.

We want a list of patients who have had a CPT code type of transaction within a prescribed time AND who have had no CPT code transaction in the last 90 days.

We would also like a column for Age and to export the results to Excel so that it will be easy to use the results as a mail merge file.

The query below includes both date of birth and age columns, and an OUTPUT line to do the export. Modify the file name in that line as you like, but no spaces unless you also surround the filename with quotation marks! The additions are in red. Excel format output is not available in all versions of the query utility, so we will output the results as an HTML file instead. You can open this file using Excel, and, if you like, re-save (File > Save as) in Excel format. Note also that this query demonstrates the use of NESTED SUBQUERIES:

SELECT
  lastname, firstname, id,
  lfeedate AS "Last Service",
  priprvcode AS "primary Provider",
  email,
  /*count(distict trandate) as SrvDateCount */
  (SELECT COUNT(DISTINCT a.trandate)
      FROM sos.journal a JOIN sos.jcharges b ON a.jnum = b.jnum
      WHERE a.ptnum = pt.ptnum
      AND servicenum IN
         (SELECT servicenum
         FROM sos.services
         WHERE srvcode IN ( '90801','90806','90847', '90853' ) ) )  
         /*replace 'A','B','C' above with the codes you want to count */
  AS "SrvDateCount",
  dob,
  sos.AGEINYEARS(dob,TODAY()) AS "Age"
FROM
  sos.rv_patients AS pt
WHERE
  IntakeDate BETWEEN (TODAY( ) - 240) AND TODAY()  
  /*automatically does last 8 months. Note that TODAY( ) returns the same 
  value AS "CURRENT DATE"*/
AND lfeedate < (CURRENT DATE - 90) AND SrvDateCount <= 93 ;OUTPUT TO c:\sos\survey.html FORMAT HTML

Leave a Reply

Your email address will not be published.

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.