<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -701,6 +701,12 @@ class ReportsController &lt; ApplicationController
     return
   end
 
+  def missed_appointments
+    session[:list_of_patients] = Report.missed_appointments(params[:date])
+    redirect_to :controller =&gt; &quot;cohort_tool&quot; ,:action =&gt; &quot;list&quot;,
+    :report_type =&gt; &quot;#{params[:date].to_date.strftime(&quot;%d-%b-%Y&quot;)} missed appointments patient list&quot;
+  end
+
 end
 
 </diff>
      <filename>app/controllers/reports_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -272,5 +272,26 @@ class Report &lt; OpenMRS
 
  end
 
+ def self.missed_appointments(date = Date.today)
+   app_date = date.to_date
+   encounter_ids = Array.new()
+   encounter_ids &lt;&lt; EncounterType.find_by_name(&quot;Barcode scan&quot;).id
+   encounter_ids &lt;&lt; EncounterType.find_by_name(&quot;TB Reception&quot;).id
+   encounter_ids &lt;&lt; EncounterType.find_by_name(&quot;General Reception&quot;).id
+   encounter_ids &lt;&lt; EncounterType.find_by_name(&quot;Move file from dormant to active&quot;).id
+   encounter_ids &lt;&lt; EncounterType.find_by_name(&quot;Update outcome&quot;).id
+   concept_id = Concept.find_by_name(&quot;Appointment date&quot;).concept_id rescue nil
+
+   patient_ids = Observation.find(:all,:select =&gt; &quot;patient_id&quot;,:conditions =&gt; [&quot;voided = 0 AND concept_id = ? AND Date(value_datetime) = ?&quot;,concept_id,app_date],:group =&gt;&quot;patient_id&quot;).collect{|ob|ob.patient_id}.join(&quot;,&quot;) rescue nil
+  
+   return if patient_ids.blank?
+
+   patients = Patient.find_by_sql(&quot;SELECT * FROM patient p WHERE patient_id IN (#{patient_ids}) AND NOT EXISTS (SELECT * FROM obs o WHERE o.patient_id = p.patient_id AND o.voided - 0 AND DATE(o.obs_datetime) = '#{app_date}') AND NOT EXISTS (SELECT * FROM orders o INNER JOIN encounter e ON e.encounter_id = o.encounter_id AND o.voided = 0 WHERE e.patient_id = p.patient_id AND DATE(e.encounter_datetime) = '#{app_date}' AND NOT e.encounter_type IN (#{encounter_ids}))&quot;)
+
+   patients = CohortTool.patients_to_show(patients)
+   arv_code = Location.current_arv_code
+   patients.sort { |a,b| a[1]['arv_number'].to_s.gsub(arv_code,'').strip.to_i &lt;=&gt; b[1]['arv_number'].to_s.       gsub(arv_code,'').strip.to_i }
+ end
+
 end
 </diff>
      <filename>app/models/report.rb</filename>
    </modified>
    <modified>
      <diff>@@ -43,7 +43,7 @@ table{
     &lt;td&gt;ARV Number&lt;/td&gt;
     &lt;td&gt;National ID&lt;/td&gt;
     &lt;td&gt;Visit Date&lt;/td&gt;
-    &lt;%if @report_type==&quot;Patients with dispensations without prescriptions&quot; %&gt;
+    &lt;%if @report_type==&quot;Patients with missing prescriptions&quot; %&gt;
       &lt;td&gt;Dispensed drugs&lt;/td&gt;
     &lt;%else%&gt;
       &lt;td&gt;Prescribed drugs&lt;/td&gt;</diff>
      <filename>app/views/cohort_tool/dispensations.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -77,3 +77,4 @@ table{
     &lt;input id=&quot;mastercard&quot; type=&quot;submit&quot; value=&quot;Mastercards&quot; name=&quot;commit&quot;/&gt;
   &lt;% end %&gt;
 &lt;% end %&gt;
+</diff>
      <filename>app/views/cohort_tool/list.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -83,10 +83,9 @@
     element.focus();
   }
 
-
   function showMessage(what_to_show){
     element = document.getElementById('popupmessage')
-    if (patient_id){
+    if(patient_id){
       element.style.display = &quot;block&quot;;
     }
   }
@@ -98,6 +97,7 @@
       &lt;div&gt;
          &lt;input id=&quot;barcode&quot; name=&quot;barcode&quot; type=&quot;text&quot;&gt;&lt;/input&gt;&lt;/br&gt;Total number of appointments on:&lt;/br&gt;
          &lt;%= &quot;#{@date.strftime('%A  %d-%B-%Y')}&quot; %&gt;&lt;%= &quot;&amp;nbsp;&quot;*2%&gt;(&lt;%=  @patients.length rescue nil %&gt;)
+         &lt;button id='missed_app' onmousedown=&quot;javascript:document.location='/reports/missed_appointments?date=&lt;%=@date%&gt;'&quot;&gt;Missed appointments&lt;/button&gt;
          &lt;%= javascript_include_tag &quot;barcode&quot;%&gt;
       &lt;/div&gt;
     &lt;/form&gt;
@@ -150,3 +150,4 @@
 &lt;script type=&quot;text/javascript&quot;&gt;
    barcodeFocusTimeoutId = window.setTimeout(&quot;focusForBarcodeInput()&quot;, setFocusTimeout);
 &lt;/script&gt;
+</diff>
      <filename>app/views/reports/appointment_dates.rhtml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b8663704f1421ffacc274436387acb790bca7234</id>
    </parent>
  </parents>
  <author>
    <name>mwatha</name>
    <email>ace@lalanje.(none)</email>
  </author>
  <url>http://github.com/baobab/bart/commit/651a5319ff2c6e7e84f319c3f6878bec324f1f24</url>
  <id>651a5319ff2c6e7e84f319c3f6878bec324f1f24</id>
  <committed-date>2009-10-27T01:22:52-07:00</committed-date>
  <authored-date>2009-10-27T01:22:52-07:00</authored-date>
  <message>adding a page to display list of patients who have missed there app daes</message>
  <tree>73172b2ac58cb14adca7a8e7d906386c3407f3fa</tree>
  <committer>
    <name>mwatha</name>
    <email>ace@lalanje.(none)</email>
  </committer>
</commit>
