customer; return view('app.patient.invoicing.invoice-transactions', compact('patient', 'invoice', 'customer')); } public function invoicingInvoiceTransactionsInPopup(Request $request, Client $patient, Invoice $invoice) { $customer = $invoice->customer; return view('app.patient.invoicing.invoice-transactions-in-popup', compact('patient', 'invoice', 'customer')); } public function claimsResolver(Request $request, Client $patient) { $notes = $patient->notesAscending; $hcpSignedNotesCount = 0; foreach($notes as $note){ if($note->is_signed_by_hcp){ $hcpSignedNotesCount += 1; } } $data = [ 'dog' => 'bark', 'patient' => $patient, 'hcpSignedNotesCount' => $hcpSignedNotesCount ]; return view('app.patient.claims-resolver', $data); } public function dashboard(Request $request, Client $patient ) { $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get(); $facilities = []; // Facility::where('is_active', true)->get(); // get assigned devices $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true")); $assignedDeviceIDs = array_map(function($_x) { return $_x->device_id; }, $assignedDeviceIDs); // get all except assigned ones $devices = BDTDevice::where('is_active', true) ->whereNotIn('id', $assignedDeviceIDs) ->orderBy('imei', 'asc') ->get(); $assignedDeviceIDs = null; unset($assignedDeviceIDs); $availableDevices = count($devices); $patientDeviceIDs = ClientBDTDevice::select('id')->where('client_id', $patient->id)->where('is_active', true)->get()->toArray(); $patientDeviceIDs = array_map(function ($_x) { return $_x["id"]; }, $patientDeviceIDs); $dxInfoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'dx') ->where('is_removed', false) ->orderBy('content_text', 'asc') ->get(); $clientMemos = ClientMemoView::where('client_id', $patient->id)->where('is_cancelled', false)->orderBy('created_at', 'DESC')->get(); $shortCutsObject = []; foreach ($this->pro->allShortcuts() as $shortcut) { // %replaceables% $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text); $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text); $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text); $shortCutsObject[] = [ "name" => $shortcut->shortcut, "value" => $shortcut->text ]; } $recentMeasurements = $patient->recentMeasurements; $latestVitals = Point::where('client_id', $patient->id)->where('category', 'VITALS')->orderBy('id', 'DESC')->first(); $nonCoreVisitNotes = $patient->nonCoreVisitNotes; $disallowPointEdits = $nonCoreVisitNotes && count($nonCoreVisitNotes); return view('app.patient.dashboard', compact('patient', 'facilities', 'devices', 'dxInfoLines', 'clientMemos', 'shortCutsObject', 'availableDevices', 'patientDeviceIDs', 'recentMeasurements', 'latestVitals', 'disallowPointEdits')); } public function canvasMigrate(Request $request, Client $patient ) { $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get(); $facilities = []; // Facility::where('is_active', true)->get(); // get assigned devices $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true")); $assignedDeviceIDs = array_map(function($_x) { return $_x->device_id; }, $assignedDeviceIDs); // get all except assigned ones $devices = BDTDevice::where('is_active', true) ->whereNotIn('id', $assignedDeviceIDs) ->orderBy('imei', 'asc') ->get(); $assignedDeviceIDs = null; unset($assignedDeviceIDs); $dxInfoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'dx') ->where('is_removed', false) ->orderBy('content_text', 'asc') ->get(); return view('app.patient.canvas-migrate', compact('patient', 'facilities', 'devices', 'dxInfoLines')); } public function canvas(Request $request, Client $patient){ return view('app.patient.canvas_dump', compact('patient')); } public function intake(Request $request, Client $patient ) { $files = File::allFiles(resource_path('views/app/intake-templates')); $templates = []; foreach ($files as $file) { $templates[] = str_replace(".blade.php", "", $file->getFilename()); } return view('app.patient.intake', compact('patient', 'templates')); } public function carePlan(Request $request, Client $patient ) { return view('app.patient.care-plan', compact('patient')); } public function medications(Request $request, Client $patient ) { $infoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'rx') ->where('is_removed', false) ->orderBy('content_text', 'asc') ->get(); return view('app.patient.medications', compact('patient', 'infoLines')); } public function dxAndFocusAreas(Request $request, Client $patient ) { $dxInfoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'dx') ->where('is_removed', false) ->orderBy('content_text', 'asc') ->get(); return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines')); } public function careTeam(Request $request, Client $patient ) { $infoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'care_team') ->where('is_removed', false) ->get(); return view('app.patient.care-team', compact('patient', 'infoLines')); } public function devices(Request $request, Client $patient ) { // get assigned devices $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true")); $assignedDeviceIDs = array_map(function($_x) { return $_x->device_id; }, $assignedDeviceIDs); // get all except assigned ones $devices = BDTDevice::where('is_active', true) ->whereNotIn('id', $assignedDeviceIDs) ->orderBy('imei', 'asc') ->get(); $assignedDeviceIDs = null; unset($assignedDeviceIDs); return view('app.patient.devices', compact('patient', 'devices')); } public function measurements(Request $request, Client $patient ) { $measurements = Measurement::where('client_id', $patient->id)->where('is_active', true)->orderByRaw('ts DESC NULLS LAST')->paginate(30); return view('app.patient.measurements', compact('patient', 'measurements')); } public function labsAndStudies(Request $request, Client $patient ) { return view('app.patient.labs-and-studies', compact('patient')); } public function history(Request $request, Client $patient ) { $infoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'LIKE', 'history_%') ->where('is_removed', false) ->get(); return view('app.patient.history', compact('patient', 'infoLines')); } public function memos(Request $request, Client $patient ) { return view('app.patient.memos', compact('patient')); } public function memosThread(Request $request, Client $patient ) { return view('app.patient.memos-thread', compact('patient')); } public function messagesThread(Request $request, Client $patient ) { return view('app.patient.messages-thread', compact('patient')); } public function sms(Request $request, Client $patient ) { return view('app.patient.sms', compact('patient')); } public function outgoingSmsLog(Request $request, Client $patient ) { return view('app.patient.outgoing-sms-log', compact('patient')); } public function reviewRequests(Request $request, Client $patient){ $pro = $this->performer->pro; $reviewRequests = ClientReviewRequest::where('client_id', $patient->id); if($pro->pro_type !== 'ADMIN'){ $reviewRequests = $reviewRequests->where('pro_id', $pro->id)->where('is_active', true); } $reviewRequests = $reviewRequests->orderBy('created_at', 'DESC')->paginate(50); return view('app.patient.review-requests.list', compact('patient', 'reviewRequests')); } public function smsNumbers(Request $request, Client $patient ) { return view('app.patient.sms-numbers', compact('patient')); } public function immunizations(Request $request, Client $patient ) { return view('app.patient.immunizations', compact('patient')); } public function allergies(Request $request, Client $patient ) { $infoLines = ClientInfoLine::where('client_id', $patient->id) ->where('category', 'allergy') ->where('is_removed', false) ->get(); return view('app.patient.allergies', compact('patient', 'infoLines')); } public function notes(Request $request, Client $patient, $filter = 'active') { $pros = $this->pros; return view('app.patient.notes', compact('patient','pros', 'filter')); } public function genericBills(Request $request, Client $patient) { return view('app.patient.generic-bills', compact('patient')); } public function rmSetup(Request $request, Client $patient) { // get assigned devices $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true")); $assignedDeviceIDs = array_map(function($_x) { return $_x->device_id; }, $assignedDeviceIDs); // get all except assigned ones $devices = BDTDevice::where('is_active', true) ->whereNotIn('id', $assignedDeviceIDs) ->orderBy('imei', 'asc') ->get(); $assignedDeviceIDs = null; unset($assignedDeviceIDs); return view('app.patient.rm-setup', compact('patient', 'devices')); } public function handouts(Request $request, Client $patient ) { $clientHandouts = HandoutClient::where('client_id', $patient->id)->get(); $handouts = Handout::where('is_active', true)->orderBy('display_name', 'ASC')->get(); return view('app.patient.handouts', compact('patient', 'clientHandouts', 'handouts')); } public function settings(Request $request, Client $patient ) { $companies = Company::all(); return view('app.patient.settings', compact('patient', 'companies')); } public function smsReminders(Request $request, Client $patient ) { return view('app.patient.sms-reminders', compact('patient')); } public function measurementConfirmationNumbers(Request $request, Client $patient ) { return view('app.patient.measurement-confirmation-numbers', compact('patient')); } public function pros(Request $request, Client $patient ) { return view('app.patient.pros', compact('patient')); } public function proChanges(Request $request, Client $patient ) { return view('app.patient.client-pro-changes', compact('patient')); } public function account(Request $request, Client $patient ) { return view('app.patient.account', compact('patient')); } public function careChecklist(Request $request, Client $patient ) { return view('app.patient.care-checklist', compact('patient')); } public function documents(Request $request, Client $patient ) { return view('app.patient.documents', compact('patient')); } public function incomingReports(Request $request, Client $patient, IncomingReport $currentReport = null) { return view('app.patient.incoming-reports', compact('patient', 'currentReport')); } public function education(Request $request, Client $patient ) { return view('app.patient.education', compact('patient')); } public function messaging(Request $request, Client $patient ) { return view('app.patient.messaging', compact('patient')); } public function duplicate(Request $request, Client $patient ) { return view('app.patient.duplicate', compact('patient')); } public function careMonths(Request $request, Client $patient ) { $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get(); $notes = Note::where('is_cancelled', false)->get(); return view('app.patient.care-months', compact('patient', 'careMonths', 'notes')); } public function presence(Request $request, Client $patient ) { return json_encode([ "online" => $patient->is_online ]); } public function embedSection(Request $request, Client $patient, $section, $selectable) { return view('app.patient.partials.' . $section, compact('patient', 'selectable')); } public function calendar(Request $request, Client $patient, Appointment $currentAppointment) { $pros = []; if($this->pro && $this->pro->pro_type != 'ADMIN') { $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id)->get(); $accessibleProIds = []; foreach($accessiblePros as $accessiblePro){ $accessibleProIds[] = $accessiblePro->accessible_pro_id; } $accessibleProIds[] = $this->pro->id; // for dna, add pros accessible via pro teams if($this->performer->pro->isDefaultNA()) { $teams = $this->performer->pro->teamsWhereAssistant; foreach ($teams as $team) { if(!in_array($team->mcp_pro_id, $accessibleProIds)) { $accessibleProIds[] = $team->mcp_pro_id; } } } $pros = Pro::whereIn('id', $accessibleProIds)->get(); } $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("14 days")); $dateLastWeek = date_format($dateLastWeek, "Y-m-d"); $appointments = Appointment::where('client_id', $patient->id) ->orderBy('raw_date', 'desc')->orderBy('raw_start_time', 'desc') ->where('raw_date', '>=', $dateLastWeek) ->get(); $appointmentProIDs = $appointments->map(function($_item) { return $_item->pro_id; }); $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get(); return view('app.patient.appointment-calendar', compact('pros', 'patient', 'currentAppointment', 'appointments', 'appointmentPros')); } public function flowsheets(Request $request, Client $patient, $filter = '') { $pros = $this->pros; return view('app.patient.flowsheets', compact('patient', 'pros', 'filter')); } public function vitalsSettings(Request $request, Client $patient) { return view('app.patient.vitals-settings', compact('patient')); } public function vitalsGraph(Request $request, Client $patient, $filter = '') { $pros = $this->pros; return view('app.patient.vitals-graph', compact('patient', 'pros', 'filter')); } public function sleepStudy(Request $request, Client $patient) { return view('app.patient.sleep-study', compact('patient')); } public function sleepStudyStep(Request $request, Client $patient) { return view('app.patient.sleep-study.' . $request->input('step'), compact('patient')); } public function tickets(Request $request, Client $patient, $type = '', String $currentTicket = '') { $pros = $this->pros; $allPros = Pro::all(); $qlTicket = $currentTicket; if(!!$currentTicket) { $qlTicket = Ticket::where('uid', $currentTicket)->first(); if($qlTicket) { $currentTicket = $qlTicket; } } return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket')); } protected function getDefaultFacility(){ $defaultFacility = Facility::where('name', 'Ultra Care Pharmacy')->where('address_city', 'Baltimore')->first(); return $defaultFacility; } public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') { $this->updateDefaultPatientPharmacy($patient); if(!!$currentErx) { $currentErx = Erx::where('uid', $currentErx)->first(); } $note = $patient->coreNote; $defaultFacility = $this->getDefaultFacility(); $patient->refresh(); return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note', 'defaultFacility')); } protected function updateDefaultPatientPharmacy(Client $patient){ $prescriptions = $patient->prescriptions; if(!count($prescriptions)) return; $defaultFacility = $this->getDefaultFacility(); if(!$defaultFacility) return; foreach($prescriptions as $prescription){ if($prescription->logistics_detail_json) continue; $this->setPrescriptionDefaultPharmacy($prescription, $defaultFacility); } } private function setPrescriptionDefaultPharmacy(Erx $prescription, Facility $facility){ $data = [ 'uid' => $prescription->uid, 'logisticsDetailJson' => json_encode([ 'facilityName' => $facility->name, 'facilityCity' => $facility->address_city, 'facilityState' => $facility->address_state, 'facilityAddressMemo' => '', 'facilityPhone' => $facility->phone, 'facilityFax' => $facility->fax, 'facilityZip' => $facility->address_zip, ]) ]; $response = $this->callJavaApi('/erx/updateLogisticsDetail', $data); } public function prescriptionsPopup(Request $request, Client $patient, String $type = '', String $currentErx = '') { if(!!$currentErx) { $currentErx = Erx::where('uid', $currentErx)->first(); } $note = null; if($request->input('noteUid')) { $note = Note::where('uid', $request->input('noteUid'))->first(); } return view('app.patient.prescriptions-popup.list-popup', compact('patient', 'type', 'currentErx', 'note')); } public function prescriptionsList(Request $request, Client $patient, String $type = '', String $currentErx = '') { if(!!$currentErx) { $currentErx = Erx::where('uid', $currentErx)->first(); } $note = null; if($request->input('noteUid')) { $note = Note::where('uid', $request->input('noteUid'))->first(); } return view('app.patient.prescriptions.list', compact('patient', 'type', 'currentErx', 'note')); } public function downloadPrescriptionAsPdf(Request $request, Erx $prescription){ if($request->input('html')) { return view('app.patient.prescriptions.pdf.pdf-preview', compact('prescription')); } else { $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview', compact('prescription')); return $pdf->download($prescription->created_at .'_' . 'erx.pdf'); } } public function transmitPrescription(Request $request, Erx $prescription){ // re-generate pdf with cover sheet as first page and save it to FS $filePath = config('app.temp_dir') . "/{$prescription->uid}.pdf"; $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview-with-cover-sheet', compact('prescription')); $pdf->save($filePath); // send it along with the rest of the params to /api/erx/transmit [multi-part POST] $url = config('stag.backendUrl') . '/erx/transmit'; $params = [ "uid" => $request->input('uid'), "toWho" => $request->input('toWho'), "toEmail" => $request->input('toEmail'), "toFaxNumber" => $request->input('toFaxNumber'), "toFaxNumberAttentionLine" => $request->input('toFaxNumberAttentionLine'), "toFaxNumberCoverSheetMemo" => $request->input('toFaxNumberCoverSheetMemo'), ]; if($request->input('copyToPatient')) { $params["copyToPatientFaxNumber"] = $request->input('copyToPatientFaxNumber'); $params["copyToPatientEmail"] = $request->input('copyToPatientEmail'); } $pdf = fopen($filePath, 'r'); $response = Http ::attach('pdfSystemFile', $filePath, "{$prescription->uid}.pdf") ->withHeaders(['sessionKey' => $request->cookie('sessionKey')]) ->post($url, $params) ->json(); return $response; } public function supplyOrders(Request $request, Client $patient, SupplyOrder $supplyOrder = null) { $products = Product::where('is_active', true)->orderBy('created_at', 'desc')->get(); return view('app.patient.supply-orders', compact('patient', 'supplyOrder', 'products')); } public function shipments(Request $request, Client $patient, Shipment $shipment = null) { return view('app.patient.shipments', compact('patient', 'shipment')); } public function appointments(Request $request, Client $patient, $forPro = 'all', $status = 'all') { $pros = $this->pros; $appointments = $patient->appointmentsForProByStatus($forPro, strtoupper($status)); $appointmentProIDs = $appointments->map(function($_item) { return $_item->pro_id; }); $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get(); return view('app.patient.appointments', compact('patient', 'pros', 'appointments', 'appointmentPros', 'forPro', 'status')); } public function mcpRequests(Request $request, Client $patient) { return view('app.patient.mcp-requests', compact('patient')); } public function eligibleRefreshes(Request $request, Client $patient) { return view('app.patient.eligible-refreshes', compact('patient')); } public function insuranceCoverage(Request $request, Client $patient) { $mbPayers = MBPayer::all(); return view('app.patient.insurance-coverage', compact('patient', 'mbPayers')); } public function clientPrimaryCoverages(Request $request, Client $patient) { $mbPayers = MBPayer::all(); return view('app.patient.client-primary-coverages', compact('patient', 'mbPayers')); } public function primaryCoverage(Request $request, Client $patient) { $mbPayers = MBPayer::all(); return view('app.patient.primary-coverage', compact('patient', 'mbPayers')); } public function primaryCoverageForm(Request $request, Client $patient) { $mbPayers = MBPayer::all(); return view('app.patient.primary-coverage-form', compact('patient', 'mbPayers')); } public function primaryCoverageManualDeterminationModal(Request $request, Client $patient) { $coverageUid = $request->get('coverageUid'); $coverage = ClientPrimaryCoverage::where('uid', $coverageUid)->first(); if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICARE'){ return view('app.patient.primary-coverage-manual-determination-medicare-modal', compact('patient', 'coverage')); } if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICAID'){ return view('app.patient.primary-coverage-manual-determination-medicaid-modal', compact('patient', 'coverage')); } if($patient->latestClientPrimaryCoverage->plan_type === 'COMMERCIAL'){ return view('app.patient.primary-coverage-manual-determination-commercial-modal', compact('patient', 'coverage')); } return "Plan Type is missing!"; } public function mbClaim(Request $request, MBClaim $mbClaim) { return view('app.patient.mb-claim-single', compact('mbClaim')); } public function accounts(Request $request, Client $patient) { return view('app.patient.accounts', compact('patient')); } public function companies(Request $request, Client $patient) { $companies = Company::where('is_active', true)->get(); $companyClientStatusMap = []; $companyClientStatusMap['NEW'] = 'New'; $companyClientStatusMap['ELIGIBILITY_VERIFIED'] = 'Eligibility Verified'; $companyClientStatusMap['ELIGIBILITY_PENDING'] = 'Eligibility Pending'; $companyClientStatusMap['NOT_ELIGIBLE'] = 'Not Eligible'; $companyClientStatusMap['INITIAL_CONSULT'] = 'Initial Consult'; $companyClientStatusMap['HST_DELIVERED'] = 'HST Delivered'; $companyClientStatusMap['STUDY_PENDING'] = 'Study Pending'; $companyClientStatusMap['STUDY_COMPLETED'] = 'Study Completed'; $companyClientStatusMap['STUDY_INTERPRETED'] = 'Study Interpreted'; $companyClientStatusMap['POST_HST_VISIT'] = 'Post HST Visit'; $companyClientStatusMap['CPAP_RX'] = 'CPAP Rx'; $companyClientStatusMap['ORAL_APPLIANCE_RX'] = 'Oral Appliance Rx'; $companyClientStatusMap['NOT_INTERESTED'] = 'Not Interested'; $companyClientStatusMap['IN_LAB_STUDY'] = 'In Lab Study'; $companyClientStatusMap['UNRESPONSIVE'] = 'Unresponsive'; return view('app.patient.companies', compact('patient', 'companies', 'companyClientStatusMap')); } public function rtm(Request $request, Client $patient) { return view('app.patient.rtm', compact('patient')); } public function careMonthMatrix(Request $request, CareMonth $careMonth) { return view('app.patient.care-month.matrix', [ 'patient' => $careMonth->patient, 'careMonth' => $careMonth, ]); } public function clientProAccess(Request $request, Client $patient) { $rows = ClientProAccess::where('client_id', $patient->id)->get(); return view('app.patient.client-pro-access', compact('patient', 'rows')); } public function clientDocuments(Request $request, Client $patient){ $templates = get_doc_templates(); $companyProIDs = DB::select('SELECT company_pro_id FROM company_pro_document WHERE related_client_id = ?', [$patient->id]); $companyProIDInts = []; foreach($companyProIDs as $cpId){ $companyProIDInts[] = $cpId->company_pro_id; } $companyPros = CompanyPro::whereIn('id', $companyProIDInts)->get(); return view('app.patient.client-documents', compact('templates', 'companyPros', 'patient')); } public function clientDocumentsRequests(Request $request, Client $patient){ $templates = $this->getTemplates(); $companyClients = CompanyClient::where('client_id', $patient->id)->get(); $companyClientsIds = CompanyClient::where('client_id', $patient->id)->pluck('id')->toArray(); $documents = CompanyProDocument::whereIn('company_client_id', $companyClientsIds)->orderBy('created_at', 'DESC')->paginate(50); return view('app.patient.client-documents-requests', compact('templates', 'patient', 'companyClients', 'documents')); } private function getTemplates(){ return get_doc_templates(); } public function insuranceCards(Request $request, Client $patient){ $insuranceCards = InsuranceCard::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->get(); return view('app.patient.insurance-cards', compact('patient', 'insuranceCards')); } public function insuranceCard(Request $request, Client $patient, InsuranceCard $card){ return view('app.patient.insurance-card', compact('patient', 'card')); } public function insuranceCardPutInfo(Request $request, Client $patient, InsuranceCard $card){ //Use java, but currently java is not updating card info columns $data = $request->except(['uid']); foreach($data as $key=>$value){ if($key === 'frontImageUrl') $card->front_image_url = $value; if($key === 'backImageUrl') $card->back_image_url = $value; } $card->save(); return $this->pass($card->uid); } public function insuranceCoverageHistory(Request $request, Client $patient){ $insuranceCoverageHistory = ClientPrimaryCoverage::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->get(); return view('app.patient.insurance-coverage-history', compact('patient', 'insuranceCoverageHistory')); } public function protocolBuilder(Request $request, Client $patient) { return view('app.patient.rtm.protocol-builder', compact('patient')); } public function checkIfCptCodeIsSubmitted(Request $request){ $clientUid = $request->get('clientUid'); $cptCode = $request->get('code'); if(!$clientUid || !$cptCode) return $this->fail('Error'); $client = Client::where('uid', $clientUid)->first(); $notes = $client->notes; $isCptSubmitted = false; foreach($notes as $note){ $noteClaims = $note->claims; foreach($noteClaims as $noteClaim){ foreach($noteClaim->lines as $claimLine){ if($claimLine->cpt == $cptCode){ if($noteClaim->status == 'SUBMITTED'){ $isCptSubmitted = true; } } } } } if($isCptSubmitted) return $this->pass('SUBMITTED'); return $this->pass('NOT_SUBMITTED'); } public function surveys(Request $request, Client $patient) { $filters = $request->all(); $entityTypes = Survey::ALLOWED_ENTITIES; $surveyFormsPath = resource_path(Survey::FORM_PATH); $filesInFolder = File::allFiles($surveyFormsPath); $forms = []; foreach ($filesInFolder as $path) { $file = pathinfo($path); $fileName = $file['filename']; $internalName = explode('.', $fileName)[0]; $forms[] = $internalName; } $records = Survey::where('entity_uid', $patient->uid); $searchString = $request->get('string'); if($searchString){ $searchString = strtolower($searchString); $records = $records->where(function ($q) use ($searchString) { return $q->orWhereRaw('LOWER(title::text) ILIKE ?', ['%' . $searchString . '%']) ->orWhereRaw('LOWER(internal_name::text) ILIKE ?', ['%' . $searchString . '%']) ->orWhereRaw('survey_data ILIKE ?', ['%' . $searchString . '%']); }); } $entityType = $request->get('entity_type'); if($entityType){ $records = $records->where('entity_type', $entityType); } $records = $records->orderBy('created_at', 'DESC')->paginate(5); $layout = 'layouts.patient'; $isPopup = false; if($request->get('popup')){ $layout = 'layouts.popup'; $isPopup = true; } return view('app.patient.surveys.list', compact('forms', 'records', 'entityTypes', 'filters', 'patient', 'layout', 'isPopup')); } public function surveysCreate(Request $request, Client $patient){ $validator = Validator::make($request->all(), [ 'entityType' => 'required|string', 'entityUid' => 'required|string', 'internalName' => 'required|string' ]); if ($validator->fails()) { return $this->fail('Invalid data provided!'); } $internalName = $request->get('internalName'); $entityType = $request->get('entityType'); $entityUid = $request->get('entityUid'); $surveyService = new SurveyService($internalName); $defaultHtml = $surveyService->defaultHTML; if(!$defaultHtml) return $this->fail('No default HTML template found for ' . $internalName); $initializedData = $surveyService->getInitializedData($entityType, $entityUid); $data = [ 'internalName' => $internalName, 'title' => $request->get('title'), 'entityType' => $entityType, 'entityUid' => $entityUid, 'surveyHTML' => $defaultHtml, 'surveyDataJSON' => json_encode($initializedData) ]; $response = $this->callJavaApi('/survey/create', $data); if(!$response['success']){ return $this->fail(@$response['message']); } return $this->pass(); } public function getEntityRecords(Request $request, Client $patient) { $term = $request->get('term'); $type = $request->get('type'); if(!in_array($type, Survey::ALLOWED_ENTITIES)){ return $this->fail('Invalid entity type'); } $records = []; if($type === 'Client'){ $clients = Client::query(); $clients = $clients->where('is_active', true); $clients = $clients->where(function ($q) use ($term) { return $q->orWhereRaw('LOWER(name_first::text) ILIKE ?', ['%' . $term . '%']) ->orWhereRaw('LOWER(name_last::text) ILIKE ?', ['%' . $term . '%']) ->orWhereRaw('LOWER(email_address::text) ILIKE ?', ['%' . $term . '%']) ->orWhereRaw('cell_number ILIKE ?', ['%' . $term . '%']); }); $clients = $clients->orderBy('name_first', 'ASC')->limit(10)->get(); $clientsData = $clients->map(function($client) { return [ "uid" => $client->uid, "id" => $client->id, "text" => $client->displayName(), ]; }); return json_encode([ "results" => $clientsData ]); } return $this->pass($records); } public function patientRequests(Request $request, Client $patient) { $patientRequests = PatientRequest::where('client_id', $patient->id)->paginate(30); $data = [ 'patientRequests' => $patientRequests, 'patient' => $patient ]; return view('app.patient.patient-requests', $data); } public function patientRequestCreateInvoice(Request $request, Client $client){ $params = $request->all(); $response = $this->callJavaApi('/invoice/create', $params); if(!$response['success']){ return $this->fail(@$response['message']); } $invoiceUid = $response['data']; $invoice = Invoice::where('uid', $invoiceUid)->first(); $patientRequest = PatientRequest::where('uid', $params['patientRequestUid'])->first(); $patientRequest->invoice_id = $invoice->id; $patientRequest->save(); return $this->pass(); } }