Guest User

Untitled

a guest
Jan 4th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.82 KB | None | 0 0
  1. <?php
  2.  
  3. include_once "../../dao/import/cnes/CnesImportDAO.php";
  4. include_once "../../model/import/cnes/*.php";
  5.  
  6. class CnesImportController {
  7.     private $xml;
  8.     private $cnesImportDAO;
  9.    
  10.     public function importCnes($xml) {
  11.         $this->xml = simplexml_load_file($xml); // set the xml var with the uploaded xml file
  12.         $this->cnesImportDAO = new CnesImportDAO(); // set the dao with an dao object
  13.         $this->cnesImportDAO->cleanAll(); // clean the cnes tables, for updating the data
  14.         if ($this->readInsertEstabelecimento() && $this->readInsertProfissional())
  15.             return true;
  16.         else
  17.             return false;
  18.     }
  19.    
  20.     // at each iteration in the fors below, the data are read from the xml file and a object containing the data in question is created and inserted into db through the dao
  21.    
  22.     public function readInsertEstabelecimento() {
  23.         foreach ($this->xml->IDENTIFICACAO->ESTABELECIMENTOS->DADOS_GERAIS_ESTABELECIMENTOS as $estab) {  
  24.             $estabelecimento = new Estabelecimento( // creates the object
  25.                 $estab['NM_FANTA'],
  26.                 $estab['CNPJ'],
  27.                 $estab['CNES'],
  28.                 $estab['CO_ESF_ADM'],
  29.                 $estab['TP_UNID_ID'],
  30.                 $estab['TELEFONE1'],
  31.                 $estab['TELEFONE2'],
  32.                 $estab['FAX'],
  33.                 $estab['E_MAIL'],
  34.                 $estab->ENDERECO->DADOS_ENDERECO['CO_CEP'],
  35.                 $estab->ENDERECO->DADOS_ENDERECO['SG_UF'],
  36.                 $estab->ENDERECO->DADOS_ENDERECO['CO_IBGE_MUN'],
  37.                 $estab->ENDERECO->DADOS_ENDERECO['NUMERO'],
  38.                 $estab->ENDERECO->DADOS_ENDERECO['COMPLEMENT'],
  39.                 $estab->ENDERECO->DADOS_ENDERECO['PONTO_REF'],
  40.                 $estab->COMPLEXIDADE->DADOS_COMPLEXIDADE[0]['SG_COMPLEXIDADE'],
  41.                 $estab->COMPLEXIDADE->DADOS_COMPLEXIDADE[1]['SG_COMPLEXIDADE'],
  42.                 $estab->COMPLEXIDADE->DADOS_COMPLEXIDADE[2]['SG_COMPLEXIDADE'],
  43.                 $estab->ENDERECO->DADOS_ENDERECO['BAIRRO'],
  44.                 $estab->ENDERECO->DADOS_ENDERECO['LOGRADOURO'],
  45.                 $this->xml->IDENTIFICACAO['DATA'],
  46.                 $this->xml->IDENTIFICACAO['ORIGEM'],
  47.                 $this->xml->IDENTIFICACAO['DESTINO'],
  48.                 $this->xml->IDENTIFICACAO['CO_IBGE_MUN']
  49.             );
  50.             $this->cnesImportDAO->insertEstabelecimento($estabelecimento); // insert it
  51.             foreach ($estab->EQUIPES->DADOS_EQUIPES as $equipe) {
  52.                 $equipe = new Equipe( // creates the object
  53.                 $estab['CNES'],
  54.                 $equipe['TP_EQUIPE'],
  55.                 $equipe['SG_EQUIPE'],
  56.                 $equipe['DS_EQUIPE'],
  57.                 $equipe['CO_INE'],
  58.                 $equipe['CO_AREA'],
  59.                 $equipe['DS_AREA'],
  60.                 $equipe['NM_REFERENCIA'],
  61.                 $equipe['DT_DESATIVACAO']
  62.                 );
  63.                 $this->cnesImportDAO->insertEquipeEstabelecimento($equipe); // insert it
  64.             }
  65.         }
  66.         return true;
  67.     }
  68.    
  69.     public function readInsertProfissional() {
  70.         foreach ($this->xml->IDENTIFICACAO->PROFISSIONAIS->DADOS_PROFISSIONAIS as $pro) {
  71.             $profissional = new Profissional( // creates the object
  72.                 $pro['NM_PROF'],
  73.                 $pro['CPF_PROF'],
  74.                 $pro['CO_CNS'],
  75.                 $pro['DT_NASC'],
  76.                 $pro['SEXO'],
  77.                 $pro['CONSELHO_ID'],
  78.                 $pro['SG_UF_EMIS'],
  79.                 $pro['NU_REGISTRO'],
  80.                 $pro['E_MAIL'],
  81.                 $pro['TELEFONE'],
  82.                 $pro->ENDERECO->DADOS_ENDERECO['CO_CEP'],
  83.                 $pro->ENDERECO->DADOS_ENDERECO['SG_UF'],
  84.                 $pro->ENDERECO->DADOS_ENDERECO['CO_IBGE_MUN'],
  85.                 $pro->ENDERECO->DADOS_ENDERECO['BAIRRO'],
  86.                 $pro->ENDERECO->DADOS_ENDERECO['LOGRADOURO'],
  87.                 $pro->ENDERECO->DADOS_ENDERECO['NUMERO'],
  88.                 $pro->ENDERECO->DADOS_ENDERECO['COMPLEMENT'],
  89.                 $pro->ENDERECO->DADOS_ENDERECO['PONTO_REF'],
  90.                 $this->xml->IDENTIFICACAO['DATA'],
  91.                 $this->xml->IDENTIFICACAO['ORIGEM'],
  92.                 $this->xml->IDENTIFICACAO['DESTINO'],
  93.                 $this->xml->IDENTIFICACAO['CO_IBGE_MUN']
  94.             );
  95.             $this->cnesImportDAO->insertProfissional($profissional);  // insert it
  96.             foreach ($pro->LOTACOES->DADOS_LOTACOES as $lot) {
  97.                 $lotacao = new Lotacao( // creates the object
  98.                     $pro['CPF_PROF'],
  99.                     $lot['CNES'],
  100.                     $lot['CO_INE'],
  101.                     $lot['CO_CBO']
  102.                 );
  103.                 $this->cnesImportDAO->insertLotacaoProfissional($lotacao); // insert it
  104.             }
  105.         }
  106.         return true;
  107.     }
  108. }
  109.  
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment