2021-10-11 00:14:08 +00:00
|
|
|
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class NanoHealthController extends CI_Controller
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('wallet_model');
|
|
|
|
$this->load->model('nano_health_model');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function updateConfigYearsPricesGrid(){
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$configId = $_POST['config_id'];
|
|
|
|
$grid = $_POST['grid'] ?? [];
|
|
|
|
|
|
|
|
$this->db->delete('nh_years_prices_grid',['nh_network_config_id' => $configId]);
|
2021-10-26 14:37:13 +00:00
|
|
|
if(sizeof($grid) > 0){
|
|
|
|
$this->db->insert_batch('nh_years_prices_grid',$grid);
|
|
|
|
}
|
2021-10-11 00:14:08 +00:00
|
|
|
|
|
|
|
echo json_encode("200");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateConfigMonthsPricesGrid(){
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$configId = $_POST['config_id'];
|
|
|
|
$grid = $_POST['grid'] ?? [];
|
|
|
|
|
|
|
|
$this->db->delete('nh_months_prices_grid',['nh_network_config_id' => $configId]);
|
2021-10-26 14:37:13 +00:00
|
|
|
if(sizeof($grid) > 0){
|
|
|
|
$this->db->insert_batch('nh_months_prices_grid',$grid);
|
|
|
|
}
|
2021-10-11 00:14:08 +00:00
|
|
|
echo json_encode("200");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storeAct(){
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$id = $_POST['id'];
|
|
|
|
$_POST['nh_network_config_id'] = $_POST['config_id'];
|
|
|
|
unset($_POST['config_id']);
|
|
|
|
|
|
|
|
if(!empty($id)){
|
|
|
|
$this->db->where('id',$id);
|
|
|
|
$this->db->update('nh_acts',$_POST);
|
|
|
|
}else{
|
|
|
|
$this->db->insert('nh_acts',$_POST);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode("200");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 14:33:02 +00:00
|
|
|
public function deleteAct(){
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$this->db->delete('nh_acts', ['id' => $_POST['id']]);
|
|
|
|
echo json_encode(['code' => 200 ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:01:59 +00:00
|
|
|
public function createValidatingAgent()
|
2021-10-14 14:33:02 +00:00
|
|
|
{
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
2021-11-04 17:01:59 +00:00
|
|
|
$emailExist = $this->db->get_where('nh_validating_agents', ['email' => $_POST['email']]);
|
2021-10-14 14:33:02 +00:00
|
|
|
if ($emailExist->num_rows() == 0) {
|
|
|
|
do {
|
|
|
|
$token = bin2hex(openssl_random_pseudo_bytes(16));
|
2021-11-04 17:01:59 +00:00
|
|
|
$tokenExist = $this->db->get_where('nh_validating_agents',['token' => $token]);
|
2021-10-14 14:33:02 +00:00
|
|
|
} while ($tokenExist->num_rows() > 0);
|
|
|
|
|
|
|
|
$_POST['token'] = $token;
|
2021-11-04 17:01:59 +00:00
|
|
|
$query = $this->db->insert('nh_validating_agents', $_POST);
|
2021-10-14 14:33:02 +00:00
|
|
|
|
|
|
|
if ($query) {
|
|
|
|
|
2021-11-04 17:01:59 +00:00
|
|
|
$link = base_url("Agent_password/?token=" . $token);
|
2021-10-14 14:33:02 +00:00
|
|
|
$this->load->library('email');
|
|
|
|
|
|
|
|
$this->email->from('noreply@ilink-app.com', 'iLink World');
|
|
|
|
$this->email->to($_POST['email']);
|
|
|
|
|
2021-11-04 17:01:59 +00:00
|
|
|
$this->email->subject($this->lang->line($_POST['role'] == 'DOCTOR' ? "mail_title_validating_doctor" : "mail_title_validating_agent"));
|
|
|
|
$this->email->message($_POST['firstname'] . ' ' . $_POST['lastname'] . ' ' . $this->lang->line($_POST['role'] == 'DOCTOR' ? "mail_body_validating_doctor" : "mail_body_validating_agent") . ' ' . $link);
|
2021-10-14 14:33:02 +00:00
|
|
|
|
|
|
|
$this->email->send();
|
|
|
|
|
|
|
|
echo json_encode(['code' => 200]);
|
|
|
|
} else {
|
|
|
|
echo json_encode(['code' => 500, 'message' => $this->lang->line("Une erreur s'est produite")]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo json_encode(['code'=> 419 , 'message' => $this->lang->line("L'email entré est déjà utilisé")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:01:59 +00:00
|
|
|
public function updateValidatingAgent()
|
2021-10-14 14:33:02 +00:00
|
|
|
{
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
2021-11-04 17:01:59 +00:00
|
|
|
$emailExist = $this->db->get_where('nh_validating_agents', ['id !=' => $_POST['id'], 'email' => $_POST['email']]);
|
2021-10-14 14:33:02 +00:00
|
|
|
if ($emailExist->num_rows() == 0) {
|
|
|
|
$this->db->where('id',$_POST['id']);
|
2021-11-04 17:01:59 +00:00
|
|
|
$this->db->update('nh_validating_agents',$_POST);
|
2021-10-14 14:33:02 +00:00
|
|
|
echo json_encode(['code' => 200]);
|
|
|
|
}else{
|
|
|
|
echo json_encode(['code'=> 419 , 'message' => $this->lang->line("L'email entré est déjà utilisé")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:01:59 +00:00
|
|
|
public function deleteValidatingAgent(){
|
2021-10-14 14:33:02 +00:00
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
2021-11-04 17:01:59 +00:00
|
|
|
$this->db->delete('nh_validating_agents', ['id' => $_POST['id']]);
|
2021-10-14 14:33:02 +00:00
|
|
|
echo json_encode(['code' => 200]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storeProviderClass(){
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$id = $_POST['id'];
|
|
|
|
$_POST['nh_network_config_id'] = $_POST['config_id'];
|
|
|
|
unset($_POST['config_id']);
|
|
|
|
|
|
|
|
if(!empty($id)){
|
|
|
|
$this->db->where('id',$id);
|
|
|
|
$this->db->update('nh_provider_classes',$_POST);
|
|
|
|
}else{
|
|
|
|
$this->db->insert('nh_provider_classes',$_POST);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(['code' => 200 ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteProviderClass(){
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$this->db->delete('nh_provider_classes', ['id' => $_POST['id']]);
|
|
|
|
echo json_encode(['code' => 200 ]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 10:59:03 +00:00
|
|
|
public function validateSubscription()
|
|
|
|
{
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$subscription_id = $_POST['subscription_id'];
|
|
|
|
$url = NANO_SANTE_SERVICE_URL.'/insurances/subscriptions/'.$subscription_id.'/validate';
|
|
|
|
$ch = curl_init($url);
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
|
|
/* set the content type json */
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
|
'Content-Type:application/json',
|
|
|
|
'Authorization:'.NANO_SANTE_SERVICE_TOKEN,
|
|
|
|
'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en'
|
|
|
|
));
|
|
|
|
/* set return type json */
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$body = new \stdClass();
|
|
|
|
$body->agent_id = $this->input->post('agent_id');
|
2021-11-04 17:01:59 +00:00
|
|
|
$body->nh_validating_agent_id = $this->input->post('nh_validating_agent_id');
|
2021-10-27 10:59:03 +00:00
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
|
|
|
|
|
|
|
|
/* execute request */
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
/* close cURL resource */
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
echo $result;
|
|
|
|
} else {
|
|
|
|
echo json_encode(['status' => 500]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rejectSubscription()
|
|
|
|
{
|
|
|
|
if($this->isLogged()) {
|
|
|
|
if (isset($_POST)) {
|
|
|
|
$subscription_id = $_POST['subscription_id'];
|
|
|
|
$url = NANO_SANTE_SERVICE_URL.'/insurances/subscriptions/'.$subscription_id.'/reject';
|
|
|
|
$ch = curl_init($url);
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
|
|
|
/* set the content type json */
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
|
'Content-Type:application/json',
|
|
|
|
'Authorization:'.NANO_SANTE_SERVICE_TOKEN,
|
|
|
|
'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en'
|
|
|
|
));
|
|
|
|
/* set return type json */
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$body = new \stdClass();
|
|
|
|
$body->agent_id = $this->input->post('agent_id');
|
2021-11-04 17:01:59 +00:00
|
|
|
$body->nh_validating_agent_id = $this->input->post('nh_validating_agent_id');
|
2021-11-05 16:15:59 +00:00
|
|
|
$body->type = $this->input->post('type');
|
2021-10-27 10:59:03 +00:00
|
|
|
$body->reason = $this->input->post('reason');
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
|
|
|
|
|
|
|
|
/* execute request */
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
/* close cURL resource */
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
echo $result;
|
|
|
|
} else {
|
|
|
|
echo json_encode(['status' => 500]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:14:08 +00:00
|
|
|
private function isLogged()
|
|
|
|
{
|
|
|
|
if (!$this->session->userdata('email')) {
|
|
|
|
$this->session->set_flashdata('error', 'log in first');
|
|
|
|
|
|
|
|
$data['alert'] = "ok";
|
|
|
|
$data['message'] = "Login first!";
|
|
|
|
$this->load->view('login', $data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|