|  |  | @ -11,6 +11,8 @@ package siprp.medicina.processo; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.Singleton; |  |  |  | import com.evolute.utils.Singleton; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.arrays.Virtual2DArray; |  |  |  | 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.DBManager; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.db.Executer; |  |  |  | import com.evolute.utils.db.Executer; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.jdo.JDOProvider; |  |  |  | import com.evolute.utils.jdo.JDOProvider; | 
			
		
	
	
		
		
			
				
					|  |  | @ -18,7 +20,12 @@ import com.evolute.utils.sql.Expression; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.sql.Field; |  |  |  | import com.evolute.utils.sql.Field; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.sql.Select; |  |  |  | import com.evolute.utils.sql.Select; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.evolute.utils.sql.Select2; |  |  |  | import com.evolute.utils.sql.Select2; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.Arrays; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.Comparator; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.Date; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.HashMap; |  |  |  | import java.util.HashMap; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.Vector; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import siprp.medicina.MedicinaConstants; | 
			
		
	
		
		
			
				
					
					|  |  |  | import siprp.medicina.processo.data.TrabalhadoresProcessoData; |  |  |  | import siprp.medicina.processo.data.TrabalhadoresProcessoData; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | /** |  |  |  | /** | 
			
		
	
	
		
		
			
				
					|  |  | @ -26,6 +33,7 @@ import siprp.medicina.processo.data.TrabalhadoresProcessoData; | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @author fpalma |  |  |  |  * @author fpalma | 
			
		
	
		
		
			
				
					
					|  |  |  |  */ |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | public class ProcessoDataProvider |  |  |  | public class ProcessoDataProvider | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	implements MedicinaConstants | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public static final String PROCESSO_ABERTO_CODE = "a"; |  |  |  | 	public static final String PROCESSO_ABERTO_CODE = "a"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	public static final String PROCESSO_FECHADO_CODE = "f"; |  |  |  | 	public static final String PROCESSO_FECHADO_CODE = "f"; | 
			
		
	
	
		
		
			
				
					|  |  | @ -82,7 +90,7 @@ public class ProcessoDataProvider | 
			
		
	
		
		
			
				
					
					|  |  |  | 								new Expression[ 0 ], |  |  |  | 								new Expression[ 0 ], | 
			
		
	
		
		
			
				
					
					|  |  |  | 								new String[]{ "id", "data_inicio" }, |  |  |  | 								new String[]{ "id", "data_inicio" }, | 
			
		
	
		
		
			
				
					
					|  |  |  | 								new Field( "marcacoes_processo.trabalhador_id" ).isEqual( trabalhadorID ), |  |  |  | 								new Field( "marcacoes_processo.trabalhador_id" ).isEqual( trabalhadorID ), | 
			
		
	
		
		
			
				
					
					|  |  |  | 								new String[]{ "data_inicio" }, |  |  |  | 								new String[]{ "data_inicio DESC" }, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 								null, |  |  |  | 								null, | 
			
		
	
		
		
			
				
					
					|  |  |  | 								null, |  |  |  | 								null, | 
			
		
	
		
		
			
				
					
					|  |  |  | 								null ); |  |  |  | 								null ); | 
			
		
	
	
		
		
			
				
					|  |  | @ -112,4 +120,141 @@ public class ProcessoDataProvider | 
			
		
	
		
		
			
				
					
					|  |  |  | 	{ |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 		return ESTADO_PROCESSO_BY_CODE.get( codigo ); |  |  |  | 		return ESTADO_PROCESSO_BY_CODE.get( codigo ); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	public Object[][] getElementosProcesso( Integer processoID ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		throws Exception | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Vector<Object[]> elementosVector = new Vector<Object[]>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Select select = | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "trabalhadores_ecds" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "id", "data", "estado", "" + TIPO_ECDS }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "processo_id" ).isEqual( processoID ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "data", "id" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Virtual2DArray array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		elementosVector.addAll( Arrays.asList( array.getObjects() ) ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		select = | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "trabalhadores_consultas" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "id", "data", "estado", "" + TIPO_CONSULTA }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "processo_id" ).isEqual( processoID ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "data", "id" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		elementosVector.addAll( Arrays.asList( array.getObjects() ) ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		select = | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "trabalhadores_fichas_aptidao", "exames" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{ Select2.JOIN_INNER }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{ new Field( "trabalhadores_fichas_aptidao.exame_id" ).isEqual( new Field( "exames.id" ) ) }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "exames.id", "exames.data", "resultado", "" + TIPO_FICHA_APTIDAO }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "trabalhadores_fichas_aptidao.processo_id" ).isEqual( processoID ).and( | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "exames.inactivo" ).isDifferent( "y" ) ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "exames.data", "exames.id" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		elementosVector.addAll( Arrays.asList( array.getObjects() ) ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Object elementos[][] = elementosVector.toArray( new Object[ elementosVector.size() ][] ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Arrays.sort( elementos, new Comparator(){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			public int compare( Object o1, Object o2 ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 				return ( (Date)( ( Object[] ) o1 )[ 1 ] ).compareTo( ( (Date)( ( Object[] ) o2 )[ 1 ] ) ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		return elementos; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	public Object[][] getDatasConsulta( Integer consultaID ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		throws Exception | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Select select =  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "trabalhadores_consultas_datas" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "id", "data", "estado" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "consulta_id" ).isEqual( consultaID ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "data DESC" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Virtual2DArray array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		return array.getObjects(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	public Object[][] getDatasECDs( Integer consultaID ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		throws Exception | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Select select =  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "trabalhadores_ecds_datas" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "id", "data", "estado" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "consulta_id" ).isEqual( consultaID ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "data DESC" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Virtual2DArray array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		return array.getObjects(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	public IDObject getObservacoesConsultaData( Integer consultaDataID ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		throws Exception | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Select select =  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "consultas_datas_observacoes" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "id", "observacao" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "trabalhadores_consultas_datas_id" ).isEqual( consultaDataID ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Virtual2DArray array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			return null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		else | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			return new MappableObject( ( Integer ) array.get( 0, 0 ), ( String ) array.get( 0, 1 ) ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	public IDObject getObservacoesECDsData( Integer ecdsDataID ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		throws Exception | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Select select =  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			new Select2( new String[]{ "consultas_datas_observacoes" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Integer[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Expression[]{}, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new String[]{ "id", "observacao" }, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							new Field( "trabalhadores_ecds_datas_id" ).isEqual( ecdsDataID ), | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 							null ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		Virtual2DArray array = EXECUTER.executeQuery( select ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		if( array.columnLength() == 0 || array.get( 0, 0 ) == null ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			return null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		else | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 			return new MappableObject( ( Integer ) array.get( 0, 0 ), ( String ) array.get( 0, 1 ) ); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |