|
|
|
|
@ -9,8 +9,14 @@
|
|
|
|
|
|
|
|
|
|
package siprp.medicina.locais_realizacao;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
import siprp.medicina.MedicinaConstants;
|
|
|
|
|
|
|
|
|
|
import com.evolute.utils.Singleton;
|
|
|
|
|
import com.evolute.utils.arrays.Virtual2DArray;
|
|
|
|
|
import com.evolute.utils.data.IDObject;
|
|
|
|
|
import com.evolute.utils.data.MappableObject;
|
|
|
|
|
import com.evolute.utils.db.DBManager;
|
|
|
|
|
import com.evolute.utils.db.Executer;
|
|
|
|
|
import com.evolute.utils.sql.Assignment;
|
|
|
|
|
@ -18,9 +24,9 @@ import com.evolute.utils.sql.Expression;
|
|
|
|
|
import com.evolute.utils.sql.Field;
|
|
|
|
|
import com.evolute.utils.sql.Select;
|
|
|
|
|
import com.evolute.utils.sql.Select2;
|
|
|
|
|
import com.evolute.utils.sql.Union;
|
|
|
|
|
import com.evolute.utils.sql.Update;
|
|
|
|
|
import com.evolute.utils.tables.ColumnizedMappable;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
@ -57,20 +63,50 @@ public class LocaisRealizacaoDataProvider
|
|
|
|
|
public ColumnizedMappable[] getEmpresasComMarcacoes( Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Select selectConsultas =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_consultas_datas", "trabalhadores_consultas", "trabalhadores", "estabelecimentos" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.trabalhadores_consultas_id" ).isEqual( new Field( "trabalhadores_consultas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_consultas.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) },
|
|
|
|
|
new String[]{ "estabelecimentos.empresa_id" },
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Select selectEcds =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores", "estabelecimentos" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) },
|
|
|
|
|
new String[]{ "estabelecimentos.empresa_id" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos", "empresas" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ),
|
|
|
|
|
new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT empresas.id", "empresas.designacao_social", "empresas.designacao_social_plain" },
|
|
|
|
|
new Field( "marcacoes_trabalhador.data" ).isEqual( data ),
|
|
|
|
|
new String[]{ "empresas.designacao_social_plain" },
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "empresas" },
|
|
|
|
|
new Integer[]{},
|
|
|
|
|
new Expression[]{},
|
|
|
|
|
new String[]{ "DISTINCT empresas.id", "empresas.designacao_social", "empresas.designacao_social_plain" },
|
|
|
|
|
new Field( "empresas.id" ).in( new Union( new Select[]{ selectConsultas, selectEcds }, new int[]{} ) ),
|
|
|
|
|
new String[]{ "empresas.designacao_social_plain" },
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
ColumnizedMappable empresas[] = new ColumnizedMappable[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < empresas.length; n++ )
|
|
|
|
|
@ -85,85 +121,155 @@ public class LocaisRealizacaoDataProvider
|
|
|
|
|
public ColumnizedMappable[] getEstabelecimentosComMarcacoesByEmpresa( Integer empresaID, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select selectConsultas =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_consultas_datas", "trabalhadores_consultas", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.trabalhadores_consultas_id" ).isEqual( new Field( "trabalhadores_consultas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_consultas.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "trabalhadores.estabelecimento_id" },
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Select selectEcds =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "trabalhadores.estabelecimento_id" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "marcacoes_trabalhador", "trabalhadores", "estabelecimentos" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT estabelecimentos.id", "estabelecimentos.nome", "estabelecimentos.nome_plain" },
|
|
|
|
|
new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "estabelecimentos.empresa_id" ).isEqual( empresaID ) ),
|
|
|
|
|
new String[]{ "estabelecimentos.nome_plain" },
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "estabelecimentos" },
|
|
|
|
|
new Integer[]{},
|
|
|
|
|
new Expression[]{},
|
|
|
|
|
new String[]{ "DISTINCT estabelecimentos.id", "estabelecimentos.nome", "estabelecimentos.nome_plain" },
|
|
|
|
|
new Field( "estabelecimentos.id" ).in( new Union( new Select[]{ selectConsultas, selectEcds }, new int[]{} ) ).and(
|
|
|
|
|
new Field( "estabelecimentos.inactivo" ).isEqual( "n" ) ).and(
|
|
|
|
|
new Field( "empresa_id" ).isEqual( empresaID ) ),
|
|
|
|
|
new String[]{ "estabelecimentos.nome_plain" },
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
ColumnizedMappable estabelecimentos[] = new ColumnizedMappable[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < estabelecimentos.length; n++ )
|
|
|
|
|
{
|
|
|
|
|
Integer id = ( Integer ) array.get( n, 0 );
|
|
|
|
|
String nome = ( String ) array.get( n, 1 );
|
|
|
|
|
System.out.println( id + " - " + nome );
|
|
|
|
|
estabelecimentos[ n ] = new ColumnizedMappable( id, nome );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("Estabelecimentos: " + estabelecimentos.length );
|
|
|
|
|
|
|
|
|
|
return estabelecimentos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumeroMarcacoesByEstabelecimentoAndTipo( Integer estabelecimentoID, int tipo, Date data )
|
|
|
|
|
public int getNumeroConsultasByEstabelecimentoAndDate( Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "marcacoes_trabalhador", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "COUNT( * )" },
|
|
|
|
|
new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and(
|
|
|
|
|
new Field( "marcacoes_trabalhador.tipo" ).isEqual( tipo ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_consultas_datas", "trabalhadores_consultas", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.trabalhadores_consultas_id" ).isEqual( new Field( "trabalhadores_consultas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_consultas.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "COUNT( DISTINCT trabalhadores.id )" },
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
if( array.columnLength() == 0 || array.get( 0, 0 ) == null )
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return ( ( Number ) array.get( 0, 0 ) ).intValue();
|
|
|
|
|
}
|
|
|
|
|
return ( ( Number ) array.get( 0, 0 ) ).intValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer[] getPrestadoresIDByEstabelecimentoAndTipo( Integer estabelecimentoID, int tipo, Date data )
|
|
|
|
|
public Integer[] getPrestadoresConsultaIdByEstabelecimentoAndDate( Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "marcacoes_trabalhador", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT prestador_id" },
|
|
|
|
|
new Field( "marcacoes_trabalhador.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoID ) ).and(
|
|
|
|
|
new Field( "marcacoes_trabalhador.tipo" ).isEqual( tipo ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
Integer ids[] = new Integer[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < ids.length; n++ )
|
|
|
|
|
Select selectExterno =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_consultas_datas", "trabalhadores_consultas", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.trabalhadores_consultas_id" ).isEqual( new Field( "trabalhadores_consultas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_consultas.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT trabalhadores_consultas_datas.prestador_id" },
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_consultas_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray arrayExterno = EXECUTER.executeQuery( selectExterno );
|
|
|
|
|
Integer ids[] = new Integer[ arrayExterno.columnLength() ];
|
|
|
|
|
for( int n = 0; n < arrayExterno.columnLength(); n++ )
|
|
|
|
|
{
|
|
|
|
|
ids[ n ] = ( Integer ) array.get( n, 0 );
|
|
|
|
|
ids[ n ] = ( Integer ) arrayExterno.get( n, 0 );
|
|
|
|
|
}
|
|
|
|
|
return ids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public void setPrestadorConsultaIdForEstabelecimentoAndDate( Integer estabelecimentoId, Date data, prestadorId )
|
|
|
|
|
// throws Exception
|
|
|
|
|
// {
|
|
|
|
|
// Select selectConsultas =
|
|
|
|
|
// new Select2(
|
|
|
|
|
// new String[]{ "trabalhadores_consultas_datas", "trabalhadores_consultas", "trabalhadores" },
|
|
|
|
|
// new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
// new Expression[]{
|
|
|
|
|
// new Field( "trabalhadores_consultas_datas.trabalhadores_consultas_id" ).isEqual( new Field( "trabalhadores_consultas.id" ) ),
|
|
|
|
|
// new Field( "trabalhadores_consultas.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
// new String[]{ "DISTINCT trabalhadores_consultas_datas.prestador_id" },
|
|
|
|
|
// new Field( "trabalhadores_consultas_datas.data" ).isEqual( data ).and(
|
|
|
|
|
// new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
// new Field( "trabalhadores_consultas_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
// null,
|
|
|
|
|
// null,
|
|
|
|
|
// null,
|
|
|
|
|
// null );
|
|
|
|
|
//
|
|
|
|
|
// Select selectExterno =
|
|
|
|
|
// new Select2(
|
|
|
|
|
// new String[]{ "trabalhadores_consultas_datas", "trabalhadores_consultas", "trabalhadores" },
|
|
|
|
|
// new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
// new Expression[]{
|
|
|
|
|
// new Field( "trabalhadores_consultas_datas.trabalhadores_consultas_id" ).isEqual( new Field( "trabalhadores_consultas.id" ) ),
|
|
|
|
|
// new Field( "trabalhadores_consultas.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
// new String[]{ "DISTINCT trabalhadores_consultas_datas.prestador_id" },
|
|
|
|
|
// new Field( "trabalhadores_consultas_datas.data" ).isEqual( data ).and(
|
|
|
|
|
// new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
// new Field( "trabalhadores_consultas_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
// null,
|
|
|
|
|
// null,
|
|
|
|
|
// null,
|
|
|
|
|
// null );
|
|
|
|
|
// Virtual2DArray arrayExterno = EXECUTER.executeQuery( selectExterno );
|
|
|
|
|
// Integer ids[] = new Integer[ arrayExterno.columnLength() ];
|
|
|
|
|
// for( int n = 0; n < arrayExterno.columnLength(); n++ )
|
|
|
|
|
// {
|
|
|
|
|
// ids[ n ] = ( Integer ) arrayExterno.get( n, 0 );
|
|
|
|
|
// }
|
|
|
|
|
// return ids;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public void setPrestadorIDForEstabelecimentoAndTipo( Integer estabelecimentoID, int tipo, Date data, Integer prestadorID )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
@ -194,12 +300,181 @@ public class LocaisRealizacaoDataProvider
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Object[][] getGruposEcdsEPrestadoresPorEstabelecimento( Integer estabelecimentoId )
|
|
|
|
|
protected IDObject[] getGruposEcdsByEstabelecimentoAndDate( Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "prt_grupos_protocolo", "prt_tipos_elementos_protocolo", "trabalhadores_ecd",
|
|
|
|
|
"trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "prt_grupos_protocolo.id" ).isEqual( new Field( "prt_tipos_elementos_protocolo.grupo_protocolo_id" ) ),
|
|
|
|
|
new Field( "prt_tipos_elementos_protocolo.id" ).isEqual( new Field( "trabalhadores_ecd.ecd_id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecd.trabalhadores_ecds_datas_id" ).isEqual( new Field( "trabalhadores_ecds_datas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT prt_grupos_protocolo.id", "prt_grupos_protocolo.descricao", "prt_grupos_protocolo.ordem",
|
|
|
|
|
"prt_grupos_protocolo.descricao_plain" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
new String[]{ "prt_grupos_protocolo.ordem", "prt_grupos_protocolo.descricao_plain" },
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
IDObject grupos[] = new IDObject[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < grupos.length; n++ )
|
|
|
|
|
{
|
|
|
|
|
Integer id = ( Integer ) array.get( n, 0 );
|
|
|
|
|
String descricao = ( String ) array.get( n, 1 );
|
|
|
|
|
grupos[ n ] = new MappableObject( id, descricao );
|
|
|
|
|
}
|
|
|
|
|
return grupos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer[] getPrestadoresByGrupoEcdEstabelecimentoAndDate( Integer grupoId, Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
return new Object[][]{ { new Integer( 1 ), "Sangue", new Integer( 1 ) },
|
|
|
|
|
{ new Integer( 2 ), "Sangue", new Integer( 1 ) },
|
|
|
|
|
{ new Integer( 3 ), "RX Torax", null },
|
|
|
|
|
{ new Integer( 4 ), "ECG", new Integer( 1 ) } };
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "prt_tipos_elementos_protocolo", "trabalhadores_ecd",
|
|
|
|
|
"trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "prt_tipos_elementos_protocolo.id" ).isEqual( new Field( "trabalhadores_ecd.ecd_id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecd.trabalhadores_ecds_datas_id" ).isEqual( new Field( "trabalhadores_ecds_datas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT trabalhadores_ecds_datas.prestador_id" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "prt_tipos_elementos_protocolo.grupo_protocolo_id" ).isEqual( grupoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
Integer prestadores[] = new Integer[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < prestadores.length; n++ )
|
|
|
|
|
{
|
|
|
|
|
prestadores[ n ] = ( Integer ) array.get( n, 0 );
|
|
|
|
|
}
|
|
|
|
|
return prestadores;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumeroMarcacoesByGrupoEcdEstabelecimentoAndDate( Integer grupoId, Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "prt_tipos_elementos_protocolo", "trabalhadores_ecd",
|
|
|
|
|
"trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "prt_tipos_elementos_protocolo.id" ).isEqual( new Field( "trabalhadores_ecd.ecd_id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecd.trabalhadores_ecds_datas_id" ).isEqual( new Field( "trabalhadores_ecds_datas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "COUNT( DISTINCT trabalhadores.id)" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "prt_tipos_elementos_protocolo.grupo_protocolo_id" ).isEqual( grupoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
return ( ( Number ) array.get( 0, 0 ) ).intValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected IDObject[] getExamesOficiaisByEstabelecimentoAndDate( Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "ecd_oficial", "trabalhadores_ecd",
|
|
|
|
|
"trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "ecd_oficial.id" ).isEqual( new Field( "trabalhadores_ecd.ecd_oficial_id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecd.trabalhadores_ecds_datas_id" ).isEqual( new Field( "trabalhadores_ecds_datas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT ecd_oficial.id", "ecd_oficial.descricao", "ecd_oficial.ordem",
|
|
|
|
|
"ecd_oficial.descricao_plain" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
new String[]{ "ecd_oficial.ordem", "ecd_oficial.descricao_plain" },
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
IDObject ecds[] = new IDObject[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < ecds.length; n++ )
|
|
|
|
|
{
|
|
|
|
|
Integer id = ( Integer ) array.get( n, 0 );
|
|
|
|
|
String descricao = ( String ) array.get( n, 1 );
|
|
|
|
|
ecds[ n ] = new MappableObject( id, descricao );
|
|
|
|
|
}
|
|
|
|
|
return ecds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer[] getPrestadoresByEcdOficialEstabelecimentoAndDate( Integer ecdOficialId, Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_ecd", "trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_ecd.trabalhadores_ecds_datas_id" ).isEqual( new Field( "trabalhadores_ecds_datas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "DISTINCT trabalhadores_ecds_datas.prestador_id" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecd.ecd_oficial_id" ).isEqual( ecdOficialId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
Integer prestadores[] = new Integer[ array.columnLength() ];
|
|
|
|
|
for( int n = 0; n < prestadores.length; n++ )
|
|
|
|
|
{
|
|
|
|
|
prestadores[ n ] = ( Integer ) array.get( n, 0 );
|
|
|
|
|
}
|
|
|
|
|
return prestadores;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumeroMarcacaoesByEcdOficialEstabelecimentoAndDate( Integer ecdOficialId, Integer estabelecimentoId, Date data )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
Select select =
|
|
|
|
|
new Select2(
|
|
|
|
|
new String[]{ "trabalhadores_ecd", "trabalhadores_ecds_datas", "trabalhadores_ecds", "trabalhadores" },
|
|
|
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
|
|
|
new Expression[]{
|
|
|
|
|
new Field( "trabalhadores_ecd.trabalhadores_ecds_datas_id" ).isEqual( new Field( "trabalhadores_ecds_datas.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.trabalhadores_ecds_id" ).isEqual( new Field( "trabalhadores_ecds.id" ) ),
|
|
|
|
|
new Field( "trabalhadores_ecds.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ) },
|
|
|
|
|
new String[]{ "COUNT( DISTINCT trabalhadores.id)" },
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.data" ).isEqual( data ).and(
|
|
|
|
|
new Field( "trabalhadores.estabelecimento_id" ).isEqual( estabelecimentoId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecd.ecd_oficial_id" ).isEqual( ecdOficialId ) ).and(
|
|
|
|
|
new Field( "trabalhadores_ecds_datas.estado" ).isEqual( new Integer( MedicinaConstants.ESTADO_POR_REALIZAR ) ) ),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null );
|
|
|
|
|
Virtual2DArray array = EXECUTER.executeQuery( select );
|
|
|
|
|
return ( ( Number ) array.get( 0, 0 ) ).intValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|