Rapport-Laravel/app/Http/Controllers/DoctorController.php

75 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\LambdaRequest;
use App\Models\Doctor;
use DB;
class DoctorController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->_service = 'ums';
$this->_module = 'contact';
$this->_viewname = 'doctor';
$this->_title = 'Doctors';
$this->_base_url = '/doctor';
}
public function list(Request $request)
{
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module . '/get_my_contacts');
$fields = $this->get_list_fields();
return $this->view('list')->with([
'title' => $this->_title,
'fields' => $fields,
'base_url' => $this->_base_url,
'items' => $response->data->items,
'buttons' => $this->get_list_buttons()
]);
}
public function createdoctor(Request $request)
{
return Doctor::create($request->only(['msl_code', 'email', 'contact_id', 'name', 'phone']))->id;
}
protected function get_list_fields()
{
return [
'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']],
'name' => ['title' => 'Name', 'type' => 'text'],
'msl_code' => ['title' => 'MSL Code', 'type' => 'text']
];
}
protected function get_form_fields($type, $values)
{
$response = LambdaRequest::signedrequest('get', 'ums', 'contactattribute/get_all');
// echo '<pre>'; print_r($response); exit;
$fields = [
'name' => ['title' => 'Name', 'type' => 'text', 'required' => true],
'email' => ['title' => 'Email', 'type' => 'email', 'required' => true],
'phone' => ['title' => 'Phone', 'type' => 'text', 'required' => true],
'msl_code' => ['title' => 'MSL Code', 'type' => 'text'],
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']],
];
foreach ($response->data->items as $item) {
$values = [];
if (in_array($item->type, ['select', 'radio', 'checkbox'])) {
foreach ($item->options as $op) {
$values[$op->value] = $op->display;
}
}
$fields[$item->code] = ['title' => $item->attribute, 'type' => $item->type, 'required' => $item->required == 'yes' ? true : false, 'values' => $values];
}
return $fields;
}
}