<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\OtConsentModel;
use App\Models\QueueManagement;

class OtConsentController extends Controller
{
    function OtConsent(){
        return view('/ipd/add-ot-consent');
    }

    function saveOtConsent(Request $req){
        if($req->action == 'Save'){
        $OtConsent = new OtConsentModel;
        }
        else{
        $OtConsent = OtConsentModel::find($req->saveid);   
        }
        $OtConsent->ConsentType = $req->ConsentType; 
        $OtConsent->Language = $req->Language; 
        $OtConsent->dtentrydate = $req->dtentrydate;
        $OtConsent->dtentrytime = $req->dtentrytime;
        $OtConsent->txtplace = $req->txtplace; 
        $OtConsent->txtmrdno = $req->txtmrdno; 
        $OtConsent->txtptname = $req->txtptname; 
        $OtConsent->txtage = $req->txtage; 
        $OtConsent->txtmobile = $req->txtmobile; 
        $OtConsent->txtaddress = $req->txtaddress; 
        $OtConsent->txtwitness1 = $req->txtwitness1; 
        $OtConsent->txtcontactno1 = $req->txtcontactno1; 
        $OtConsent->txtrelationship1 = $req->txtrelationship1; 
        $OtConsent->txtwitness2 = $req->txtwitness2; 
        $OtConsent->txtcontactno2 = $req->txtcontactno2; 
        $OtConsent->txtrelationship2 = $req->txtrelationship2; 
        $OtConsent->txtsurgerytreatment = $req->txtsurgerytreatment; 
        $OtConsent->txtdiagnosis = $req->txtdiagnosis; 
        $OtConsent->txtinvestigation = $req->txtinvestigation; 
        $OtConsent->txtprognosis = $req->txtprognosis; 
        $OtConsent->txtfitness = $req->txtfitness;
        $OtConsent->CreatedDate = date('Y-m-d');
        $OtConsent->save();
        return $OtConsent->id;
       
        
    }

    function printOtConsent($id){
        $result = OtConsentModel::find($id);
        $mrdno = $result->txtmrdno;
        $result2 = QueueManagement::select('ConsultantName')->where('MrdNo',$mrdno)->orderBy('InDate','desc')->limit(1)->get();
        $drname = $result2[0]->ConsultantName;
        return view('/ipd/view-print-ot-consent',['data'=>$result,'drname'=>$drname]);
    }
}