# Proposta de indexação do GOIASBIOMETRICO
## CIVIL REQUEST
```bash
curl --location --request POST 'https://apigoiasbiometrico.ssp.go.gov.br/indexar/CIVIL' \
--header 'Content-Type: application/json' \
--data-raw '{
"tamanhoLote": 100,
"dataUltimoRegistro": 1592249000000 //data do lado do integrador
}'
```
## CIVIL RESPONSE
```json
{
"dataUltimoRegistro": 1592249196891,
"registro": [
{
"dataRegistro": 0, //este campo não está na query abaixo
"nome": "",
"mae": "",
"nomePai": "",
"cpf": "",
"rgNumero": "",
"rgOrgao": "",
"pisPasep": "",
"sexo": "",
"estadoCivil": "",
"telefone": "",
"dataObito": 0,
"nascimento": "",
"nascimentoData": 0,
"endereco": "",
"observacao": "",
"matriculaBase": "",
"rgMilitar": "",
"nascimentoMunicipio": "",
"nascimentoUF": "",
"enderecoLogradouro": "",
"enderecoQuadra": "",
"enderecoLote": "",
"enderecoNumero": "",
"enderecoComplemento": "",
"enderecoBairro": "",
"enderecoCidade": "",
"enderecoEstado": "",
"obitoOBS": "",
"obito": false
}
// + 99 registros aqui
]
}
```
## QUERY PARA OBTENÇÃO DAS INFORMAÇÕES
Esta query é usada hoje no mportal
```sql
SELECT
t5.Nome nome,
t5.NomeMae nomeMae,
t5.nomePai nomePai,
docCPFPis.CPF cpf,
t4.Numero rgNumero,
'SSP-GO' rgOrgao,
docCPFPis.NumeroPis pisPasep,
t8.Descricao sexo,
t9.Descricao estadoCivil,
t6.Data nascimentoData,
munNasc.Nome nascimentoMunicipio,
ufNasc.Sigla nascimentoUF,
endrc.Logradouro enderecoLogradouro,
endrc.Observacao enderecoQuadraLote,
endrc.Numero enderecoNumero,
endrc.Complemento enderecoComplemento,
baiEnd.Nome enderecoBairro,
muniEnd.Nome enderecoCidade,
ufEnd.Nome enderecoEstado,
t14.Numero telefone,
t4.matriculaBase,
rgMilitar.Numero rgMilitar,
t18.Observacao obitoOBS,
t3.Observacao observacao,
CASE WHEN t1.ObitoId is null THEN 0 ELSE 1 END obito
FROM [Documento] t2 with (nolock)
LEFT JOIN [Pessoa] t1 with (nolock) ON (t2.CivilId = t1.CivilId) AND t2.FlagExclusao = 0
LEFT JOIN [Solicitacao] t3 WITH(NOLOCK) ON (t2.SolicitacaoId = t3.Id)
LEFT JOIN [RG] t4 WITH(NOLOCK) ON (t2.Id = t4.Id AND t4.FlagExclusao = 0)
LEFT JOIN [Filiacao] t5 WITH(NOLOCK) ON (t4.FiliacaoId = t5.Id)
LEFT JOIN [Nascimento] t6 WITH(NOLOCK) ON (t4.NascimentoId = t6.Id)
LEFT JOIN [Pais] paisNasc WITH(NOLOCK) ON t6.PaisId = paisNasc.Id
LEFT JOIN [IBGE.UF] ufNasc WITH(NOLOCK) ON t6.UF = ufNasc.CodUF
LEFT JOIN [IBGE.Municipio] munNasc WITH(NOLOCK) ON t6.MunicipioId = munNasc.CodMunicipio
LEFT JOIN [Endereco] endrc WITH(NOLOCK) ON (t4.EnderecoId = endrc.Id)
LEFT JOIN [Pessoa.Sexo] t8 WITH(NOLOCK) ON t4.SexoId = t8.Id
LEFT JOIN [EstadoCivil] t9 WITH(NOLOCK) ON t4.EstadoCivilId = t9.Id
LEFT JOIN [IBGE.UF] ufEnd WITH(NOLOCK) ON endrc.CodUF = ufEnd.CodUF
LEFT JOIN [IBGE.Municipio] muniEnd WITH(NOLOCK) ON endrc.CodMunicipio = muniEnd.CodMunicipio
LEFT JOIN [IBGE.Bairro] baiEnd WITH(NOLOCK) ON endrc.CodBairro = baiEnd.CodBairro
LEFT JOIN [RG.Telefones] t13 WITH(NOLOCK) ON t4.Id = t13.RGId and t13.FlagExclusao = 0
LEFT JOIN [Telefone] t14 WITH(NOLOCK) ON t13.TelefoneId = t14.Id and t14.FlagExclusao = 0
LEFT JOIN
(SELECT SolicitacaoRGId,
CPF,
NumeroPis
FROM [Solicitacao.RG.Documentos] t15 WITH (NOLOCK)
INNER JOIN [Civil.Documento] docs WITH(NOLOCK) ON t15.DocumentoId = docs.Id AND docs.TipoId = 3
LEFT JOIN [Civil.Doc.Outros] docCPFPis WITH(NOLOCK) ON docs.Id = docCPFPis.Id WHERE
t15.FlagExclusao = 0 and docs.FlagExclusao = 0 and docCPFPis.FlagExclusao=0) docCPFPis ON t2.SolicitacaoId = docCPFPis.SolicitacaoRGId
LEFT JOIN
(SELECT SolicitacaoRGId,
Numero,
OrgaoExpedidor,
Sigla
FROM [Solicitacao.RG.Documentos] t15 WITH(NOLOCK)
INNER JOIN [Civil.Documento] docs WITH(NOLOCK) ON t15.DocumentoId = docs.Id AND docs.TipoId = 5
LEFT JOIN [Civil.Doc.RGMilitar] rgMilitar WITH(NOLOCK) ON docs.Id = rgMilitar.Id
LEFT JOIN [IBGE.UF] rgUFExpMilitar WITH(NOLOCK) ON rgUFExpMilitar.CodUF = rgMilitar.UFExpedidor WHERE
t15.FlagExclusao = 0 and docs.FlagExclusao = 0 and rgMilitar.FlagExclusao=0) rgMilitar ON t2.SolicitacaoId = rgMilitar.SolicitacaoRGId
LEFT JOIN [Obito] t18 WITH(NOLOCK) ON t1.ObitoId = t18.Id
LEFT JOIN [Solicitacao.RG] t19 WITH (NOLOCK) on t19.id = t2.SolicitacaoId
where
t2.flagAtivo = 1
AND t2.TipoId IN (1, 2)
```