DnaController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Appointment;
  4. use App\Models\BDTDevice;
  5. use App\Models\Bill;
  6. use App\Models\CareMonth;
  7. use App\Models\Client;
  8. use App\Models\ClientBDTDevice;
  9. use App\Models\ClientInfoLine;
  10. use App\Models\ClientProAccess;
  11. use App\Models\Erx;
  12. use App\Models\Facility;
  13. use App\Models\Handout;
  14. use App\Models\IncomingReport;
  15. use App\Models\MBClaim;
  16. use App\Models\MBPayer;
  17. use App\Models\Note;
  18. use App\Models\NoteTemplate;
  19. use App\Models\Pro;
  20. use App\Models\Product;
  21. use App\Models\ProProAccess;
  22. use App\Models\ProTeam;
  23. use App\Models\ProTransaction;
  24. use App\Models\SectionTemplate;
  25. use App\Models\Shipment;
  26. use App\Models\SupplyOrder;
  27. use App\Models\Ticket;
  28. use Illuminate\Http\Request;
  29. use Illuminate\Support\Facades\DB;
  30. use Illuminate\Support\Facades\File;
  31. use Illuminate\Support\Facades\Http;
  32. use PDF;
  33. use App\Models\DnaPatient;
  34. class DnaController extends Controller
  35. {
  36. public function patients(Request $request)
  37. {
  38. $filters = $request->all();
  39. $patients = DnaPatient::whereNull('shadow_pro_id')->where('default_na_pro_id', $this->performer->pro->id);
  40. //Also include the ones given access to:
  41. $proAccessClientIDs = ClientProAccess::where('pro_id', $this->performer->pro->id)->pluck('client_id')->toArray();
  42. $patients = $patients->orWhereIn('id', $proAccessClientIDs);
  43. if ($request->input('name')) {
  44. $name = trim($request->input('name'));
  45. if ($name) {
  46. $patients = $patients->where(function ($q) use ($name) {
  47. return $q->where('display_name', 'ILIKE', '%' . $name . '%');
  48. });
  49. }
  50. }
  51. if ($request->input('home_address_state')) {
  52. if($request->input('home_address_state') == 'NONE'){
  53. $patients = $patients->whereNull('mailing_address_state');
  54. }else if($request->input('home_address_state') == 'NOT_MD'){
  55. $patients = $patients->where('mailing_address_state', '<>' , 'MD');
  56. }else{
  57. $patients = $patients->where('mailing_address_state', '=' , $request->input('home_address_state'));
  58. }
  59. }
  60. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2', false);
  61. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  62. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2', false);
  63. $this->filterMultiQuery($request, $patients, 'most_recent_completed_mcp_note_date', 'last_visit_category', 'last_visit_value_1', 'last_visit_value_2');
  64. $this->filterMultiQuery($request, $patients, 'next_mcp_appointment_date', 'next_appointment_category', 'next_appointment_value_1', 'next_appointment_value_2');
  65. switch($request->input('status')) {
  66. case 'ACTIVE':
  67. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  68. break;
  69. case 'AWAITING_VISIT':
  70. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  71. break;
  72. case 'INACTIVE':
  73. $patients->where('is_active', '<>', true);
  74. break;
  75. }
  76. $sortBy = $request->input('sort_by') ?: 'name_first';
  77. $sortDir = $request->input('sort_dir') ?: 'ASC';
  78. $patients = $patients->orderByRaw("$sortBy $sortDir NULLS LAST");
  79. $patients = $patients->orderBy('created_at', 'DESC')->paginate(20);
  80. return view('app.dna.patients', compact('patients', 'filters'));
  81. }
  82. public function encounters(Request $request)
  83. {
  84. $filters = $request->all();
  85. $notes = Note::query();
  86. $notes = $notes->where('ally_pro_id', $this->performer->pro->id);
  87. $this->filterMultiQuery($request, $notes, 'effective_time', 'date_category', 'date_value_1', 'date_value_2');
  88. $this->filterSimpleQuery($request, $notes, 'new_or_fu_or_na', 'new_or_fu_or_na');
  89. $notes = $notes->orderBy('created_at', 'DESC')->paginate(20);
  90. return view('app.dna.encounters', compact('notes', 'filters'));
  91. }
  92. public function notes(Request $request)
  93. {
  94. $data = [];
  95. return view('app.dna.notes', $data);
  96. }
  97. public function appointments(Request $request)
  98. {
  99. $filters = $request->all();
  100. $appointments = Appointment::select('appointment.*')
  101. ->join('client', 'client.id', '=', 'appointment.client_id')
  102. ->where('client.default_na_pro_id', $this->performer->pro->id);
  103. $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
  104. $this->filterSimpleQuery($request, $appointments, 'status', 'status');
  105. $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);
  106. return view('app.dna.appointments', compact('appointments', 'filters'));
  107. }
  108. public function careMonths(Request $request){
  109. $filters = $request->all();
  110. $careMonths = CareMonth::select('care_month.*')
  111. ->join('client', 'client.id', '=', 'care_month.client_id')
  112. ->where('client.default_na_pro_id', $this->performer->pro->id);
  113. $this->filterMultiQuery($request, $careMonths, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
  114. $this->filterSimpleQuery($request, $careMonths, 'status', 'status');
  115. $careMonths = $careMonths->orderBy('created_at', 'DESC')->paginate(20);
  116. return view('app.dna.care-months', compact('careMonths', 'filters'));
  117. }
  118. public function financialTransactions(Request $request){
  119. $filters = $request->all();
  120. $financialTransactions = ProTransaction::select('pro_transaction.*')
  121. ->join('bill', 'bill.id', '=', 'pro_transaction.bill_id')
  122. ->where('bill.generic_pro_id', $this->performer->pro->id);
  123. $financialTransactions = $financialTransactions->orderBy('created_at', 'DESC')->paginate(20);
  124. return view('app.dna.financial-transactions', compact('financialTransactions', 'filters'));
  125. }
  126. public function myBills(Request $request){
  127. $performerProID = $this->performer->pro->id;
  128. $filters = $request->all();
  129. $bills = Bill::where(function($q) use ($performerProID){
  130. return $q->where('na_pro_id', '=', $performerProID )->orWhere('generic_pro_id', '=', $performerProID);
  131. });
  132. $this->filterMultiQuery($request, $bills, 'effective_date', 'date_category', 'date_value_1', 'date_value_2');
  133. $this->filterMultiQuery($request, $bills, 'na_expected_payment_amount', 'amount_category', 'amount_value_1', 'amount_value_2');
  134. $status = $request->get('status');
  135. if($status){
  136. if($status === 'VERIFIED') $bills = $bills->where('is_verified', true);
  137. if($status === 'ACTIVE') $bills = $bills->where('is_cancelled', false);
  138. if($status === 'CANCELLED') $bills = $bills->where('is_cancelled', true);
  139. if($status === 'SUBMITTED') $bills = $bills->where('is_submitted', true);
  140. }
  141. $bills = $bills->orderBy('effective_date', 'DESC')->paginate(20);
  142. return view('app.dna.my-bills', compact('bills', 'filters'));
  143. }
  144. public function myClinicalTeams(Request $request){
  145. $filters = $request->all();
  146. $teams = ProTeam::where('assistant_pro_id', $this->performer->pro->id);
  147. $teams = $teams->orderBy('created_at', 'DESC')->paginate(20);
  148. return view('app.dna.my-clinical-teams', compact('teams', 'filters'));
  149. }
  150. public function bills(Request $request)
  151. {
  152. $data = [];
  153. return view('app.dna.bills', $data);
  154. }
  155. public function erx_and_orders(Request $request)
  156. {
  157. $data = [];
  158. return view('app.dna.erx_and_orders', $data);
  159. }
  160. public function reports(Request $request)
  161. {
  162. $data = [];
  163. return view('app.dna.reports', $data);
  164. }
  165. public function supply_orders(Request $request)
  166. {
  167. $data = [];
  168. return view('app.dna.supply_orders', $data);
  169. }
  170. public function new_patients_awaiting_visit(Request $request){
  171. $data = [];
  172. return view('app.dna.new_patients_awaiting_visit', $data);
  173. }
  174. public function notes_pending_signature(Request $request){
  175. $data = [];
  176. return view('app.dna.notes_pending_signature', $data);
  177. }
  178. public function notes_pending_billing(Request $request){
  179. $data = [];
  180. return view('app.dna.notes_pending_billing', $data);
  181. }
  182. public function reports_pending_signature(Request $request){
  183. $data = [];
  184. return view('app.dna.reports_pending_signature', $data);
  185. }
  186. public function patients_without_appointments(Request $request){
  187. $data = [];
  188. return view('app.dna.patients_without_appointments', $data);
  189. }
  190. public function patients_overdue_for_visit(Request $request){
  191. $data = [];
  192. return view('app.dna.patients_overdue_for_visit', $data);
  193. }
  194. public function cancelled_appointments_pending_review(Request $request){
  195. $data = [];
  196. return view('app.dna.cancelled_appointments_pending_review', $data);
  197. }
  198. public function cancelled_bills_pending_review(Request $request){
  199. $data = [];
  200. return view('app.dna.cancelled_bills_pending_review', $data);
  201. }
  202. public function cancelled_supply_orders_pending_review(Request $request){
  203. $data = [];
  204. return view('app.dna.cancelled_supply_orders_pending_review', $data);
  205. }
  206. public function erx_and_orders_pending_signature(Request $request){
  207. $data = [];
  208. return view('app.dna.erx_and_orders_pending_signature', $data);
  209. }
  210. public function supply_orders_pending_signature(Request $request){
  211. $data = [];
  212. return view('app.dna.supply_orders_pending_signature', $data);
  213. }
  214. //From the new spec
  215. public function myPatients(Request $request){
  216. $pro = $this->performer->pro;
  217. $records = $pro->patientsRecordsAsDna();
  218. return view('app.dna.dashboard.patients', compact('records'));
  219. }
  220. public function patientsAwaitingMcpVisit(Request $request){
  221. $pro = $this->performer->pro;
  222. $records = $pro->patientsAwaitingMcpVisitRecordsAsDna();
  223. return view('app.dna.dashboard.patients_awaiting_mcp_visit', compact('records'));
  224. }
  225. public function patientsWithoutAppointment(Request $request){
  226. $pro = $this->performer->pro;
  227. $records = $pro->patientsWithoutAppointmentRecordsAsDna();
  228. return view('app.dna.dashboard.patients_without_appointment', compact('records'));
  229. }
  230. public function encountersPendingMyReview(Request $request){
  231. $pro = $this->performer->pro;
  232. $records = $pro->encountersPendingMyReviewRecordsAsDna();
  233. return view('app.dna.dashboard.encounters_pending_my_review', compact('records'));
  234. }
  235. public function encountersInProgress(Request $request){
  236. $pro = $this->performer->pro;
  237. $records = $pro->encountersInProgressRecordsAsDna();
  238. return view('app.dna.dashboard.encounters_in_progress', compact('records'));
  239. }
  240. public function appointmentsPendingConfirmation(Request $request){
  241. $pro = $this->performer->pro;
  242. $records = $pro->appointmentsPendingConfirmationRecordsAsDna();
  243. return view('app.dna.dashboard.appointments_pending_confirmation', compact('records'));
  244. }
  245. public function cancelledAppointmentsPendingAck(Request $request){
  246. $pro = $this->performer->pro;
  247. $records = $pro->cancelledAppointmentsPendingAckRecordsAsDna();
  248. return view('app.dna.dashboard.cancelled_appointments_pending_ack', compact('records'));
  249. }
  250. public function reportsPendingAck(Request $request){
  251. $pro = $this->performer->pro;
  252. $records = $pro->reportsPendingAckRecordsAsDna();
  253. return view('app.dna.dashboard.reports_pending_ack', compact('records'));
  254. }
  255. public function supplyOrdersPendingMyAck(Request $request){
  256. $pro = $this->performer->pro;
  257. $records = $pro->supplyOrdersPendingMyAckRecordsAsDna();
  258. return view('app.dna.dashboard.supply_orders_pending_my_ack', compact('records'));
  259. }
  260. public function supplyOrdersPendingHcpApproval(Request $request){
  261. $pro = $this->performer->pro;
  262. $records = $pro->supplyOrdersPendingHcpApprovalRecordsAsDna();
  263. return view('app.dna.dashboard.supply_orders_pending_hcp_approval', compact('records'));
  264. }
  265. public function teamDashboard(ProTeam $team){
  266. $slug = $team->slug ?? $team->uid;
  267. $url = config('app.stagfe6_url') . '/flyers/json-list?slug=' . $slug;
  268. $arrContextOptions=array(
  269. "ssl"=>array(
  270. "verify_peer"=>false,
  271. "verify_peer_name"=>false,
  272. ),
  273. );
  274. $response = @file_get_contents($url, false, stream_context_create($arrContextOptions));
  275. $response = @json_decode($response);
  276. $flyerTemplates = [];
  277. if(isset($response->data)){
  278. $flyerTemplates = $response->data;
  279. }
  280. return view('app.dna.teams.dashboard', compact('team','flyerTemplates'));
  281. }
  282. }