Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once "../../dao/import/cnes/CnesImportDAO.php";
- include_once "../../model/import/cnes/*.php";
- class CnesImportController {
- private $xml;
- private $cnesImportDAO;
- public function importCnes($xml) {
- $this->xml = simplexml_load_file($xml); // set the xml var with the uploaded xml file
- $this->cnesImportDAO = new CnesImportDAO(); // set the dao with an dao object
- $this->cnesImportDAO->cleanAll(); // clean the cnes tables, for updating the data
- if ($this->readInsertEstabelecimento() && $this->readInsertProfissional())
- return true;
- else
- return false;
- }
- // 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
- public function readInsertEstabelecimento() {
- foreach ($this->xml->IDENTIFICACAO->ESTABELECIMENTOS->DADOS_GERAIS_ESTABELECIMENTOS as $estab) {
- $estabelecimento = new Estabelecimento( // creates the object
- $estab['NM_FANTA'],
- $estab['CNPJ'],
- $estab['CNES'],
- $estab['CO_ESF_ADM'],
- $estab['TP_UNID_ID'],
- $estab['TELEFONE1'],
- $estab['TELEFONE2'],
- $estab['FAX'],
- $estab['E_MAIL'],
- $estab->ENDERECO->DADOS_ENDERECO['CO_CEP'],
- $estab->ENDERECO->DADOS_ENDERECO['SG_UF'],
- $estab->ENDERECO->DADOS_ENDERECO['CO_IBGE_MUN'],
- $estab->ENDERECO->DADOS_ENDERECO['NUMERO'],
- $estab->ENDERECO->DADOS_ENDERECO['COMPLEMENT'],
- $estab->ENDERECO->DADOS_ENDERECO['PONTO_REF'],
- $estab->COMPLEXIDADE->DADOS_COMPLEXIDADE[0]['SG_COMPLEXIDADE'],
- $estab->COMPLEXIDADE->DADOS_COMPLEXIDADE[1]['SG_COMPLEXIDADE'],
- $estab->COMPLEXIDADE->DADOS_COMPLEXIDADE[2]['SG_COMPLEXIDADE'],
- $estab->ENDERECO->DADOS_ENDERECO['BAIRRO'],
- $estab->ENDERECO->DADOS_ENDERECO['LOGRADOURO'],
- $this->xml->IDENTIFICACAO['DATA'],
- $this->xml->IDENTIFICACAO['ORIGEM'],
- $this->xml->IDENTIFICACAO['DESTINO'],
- $this->xml->IDENTIFICACAO['CO_IBGE_MUN']
- );
- $this->cnesImportDAO->insertEstabelecimento($estabelecimento); // insert it
- foreach ($estab->EQUIPES->DADOS_EQUIPES as $equipe) {
- $equipe = new Equipe( // creates the object
- $estab['CNES'],
- $equipe['TP_EQUIPE'],
- $equipe['SG_EQUIPE'],
- $equipe['DS_EQUIPE'],
- $equipe['CO_INE'],
- $equipe['CO_AREA'],
- $equipe['DS_AREA'],
- $equipe['NM_REFERENCIA'],
- $equipe['DT_DESATIVACAO']
- );
- $this->cnesImportDAO->insertEquipeEstabelecimento($equipe); // insert it
- }
- }
- return true;
- }
- public function readInsertProfissional() {
- foreach ($this->xml->IDENTIFICACAO->PROFISSIONAIS->DADOS_PROFISSIONAIS as $pro) {
- $profissional = new Profissional( // creates the object
- $pro['NM_PROF'],
- $pro['CPF_PROF'],
- $pro['CO_CNS'],
- $pro['DT_NASC'],
- $pro['SEXO'],
- $pro['CONSELHO_ID'],
- $pro['SG_UF_EMIS'],
- $pro['NU_REGISTRO'],
- $pro['E_MAIL'],
- $pro['TELEFONE'],
- $pro->ENDERECO->DADOS_ENDERECO['CO_CEP'],
- $pro->ENDERECO->DADOS_ENDERECO['SG_UF'],
- $pro->ENDERECO->DADOS_ENDERECO['CO_IBGE_MUN'],
- $pro->ENDERECO->DADOS_ENDERECO['BAIRRO'],
- $pro->ENDERECO->DADOS_ENDERECO['LOGRADOURO'],
- $pro->ENDERECO->DADOS_ENDERECO['NUMERO'],
- $pro->ENDERECO->DADOS_ENDERECO['COMPLEMENT'],
- $pro->ENDERECO->DADOS_ENDERECO['PONTO_REF'],
- $this->xml->IDENTIFICACAO['DATA'],
- $this->xml->IDENTIFICACAO['ORIGEM'],
- $this->xml->IDENTIFICACAO['DESTINO'],
- $this->xml->IDENTIFICACAO['CO_IBGE_MUN']
- );
- $this->cnesImportDAO->insertProfissional($profissional); // insert it
- foreach ($pro->LOTACOES->DADOS_LOTACOES as $lot) {
- $lotacao = new Lotacao( // creates the object
- $pro['CPF_PROF'],
- $lot['CNES'],
- $lot['CO_INE'],
- $lot['CO_CBO']
- );
- $this->cnesImportDAO->insertLotacaoProfissional($lotacao); // insert it
- }
- }
- return true;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment