<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\SurgeryNoteModel;
use Session;
class SurgeryNoteController extends Controller
{
    function surgerynotes(){
        $result = $this->getNoteName();
        return view('masters/surgerynotes',['data'=>$result]);
    }
    function viewSurgeryNoteList(Request $req){
        $result = SurgeryNoteModel::all();
        return view('masters/viewsurgerynotelist',['data'=>$result]);
    }

    function getNoteName(){
        $result = SurgeryNoteModel::select('Name  as Type')->distinct()->get();
        return $result;
    }
    function saveSurgeryNote(Request $req){
        if($req->action == 'Save'){
            $Package = new SurgeryNoteModel;
        }
        else{
            $Package = SurgeryNoteModel::find($req->id);
        }
        $Package->Name = $req->Name; 
        $Package->Details = $req->Details;
        $Package->Status = $req->Status;
        $Package->CreatedBy = 19;
        $Package->ModifiedBy = 19;
        $Package->save();
        return 1;
    }

    function editSurgeryNote(Request $req){
        $data = SurgeryNoteModel::find($req->id);
        return json_encode($data);
    }

    function deleteSurgeryNote(Request $req){
        $data=SurgeryNoteModel::find($req->id)->delete();
        return 1;
    }
}
