DnaController.php 13 KB

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