CREATE OR REPLACE FORCE EDITIONABLE VIEW "AD74A"."AD74A07V20" (
    "ID_EXPEDIENTE_00",
	"F_ALTA_18",
    "OIDDOKUSI_18",
    "NOMBRE_DOC_18",
    "F_INFORME_02",
    "SOLA_02",
    "ESTA_SOLA_MANANA_02",
    "ESTA_SOLA_TARDE_02",
    "ESTA_SOLA_NOCHE_02",
    "RELACION_ENTORNO_02",
    "FAMILIAR_FALLECIDO_02",
    "VINCULO_FALLECIDO_02",
    "VISITAS_FAMILIA_02",
    "VISITAS_AMIGOS_02",
    "FRECUENCIA_SALIDAS_02",
    "PERIODO_SIN_VISITAS_02",
    "TIEMPO_SIN_VISITAS_02",
    "OBSERVACIONES_02"
) AS
    SELECT
        "ID_EXPEDIENTE_00",
        "F_ALTA_18",
        "OIDDOKUSI_18",
        "NOMBRE_DOC_18",
        "F_INFORME_02",
        "SOLA_02",
        "ESTA_SOLA_MANANA_02",
        "ESTA_SOLA_TARDE_02",
        "ESTA_SOLA_NOCHE_02",
        "RELACION_ENTORNO_02",
        "FAMILIAR_FALLECIDO_02",
        "VINCULO_FALLECIDO_02",
        "VISITAS_FAMILIA_02",
        "VISITAS_AMIGOS_02",
        "FRECUENCIA_SALIDAS_02",
        "PERIODO_SIN_VISITAS_02",
        "TIEMPO_SIN_VISITAS_02",
        "OBSERVACIONES_02"
    FROM
        (
            SELECT
                docs.id_expediente_00,
                docs.f_alta_18,
                dt.oiddokusi_18,
                dt.nombre_doc_18,
                inf_soc.f_informe_02,
                inf_soc.sola_02,
                inf_soc.esta_sola_manana_02,
                inf_soc.esta_sola_tarde_02,
                inf_soc.esta_sola_noche_02,
                inf_soc.relacion_entorno_02,
                inf_soc.familiar_fallecido_02,
                inf_soc.vinculo_fallecido_02,
                inf_soc.visitas_familia_02,
                inf_soc.visitas_amigos_02,
                inf_soc.frecuencia_salidas_02,
                inf_soc.periodo_sin_visitas_02,
                inf_soc.tiempo_sin_visitas_02,
                inf_soc.observaciones_02
            FROM
                documentos_tarea dt,
                informes         inf,
                informe_social   inf_soc,
                (
                    SELECT
--EX
                        ex.id_expediente_00     id_expediente_00,
--DT
                        MAX(dt.id_doc_tarea_18) id_doc_tarea_18,
                        dt.id_tipo_doc_18       id_tipo_doc_18,
                        dt.f_alta_18            f_alta_18
                    FROM
                        documentos_tarea    dt,
                        tareas_tramite      tt,
                        tramites_expediente te,
                        expedientes         ex
                    WHERE
                            1 = 1
                        AND tt.id_tarea_tram_11 = dt.id_tarea_tram_18
                        AND te.id_tramite_exp_10 = tt.id_tramite_exp_11
                        AND ex.id_expediente_00 = te.id_expediente_10
                        AND te.id_estado_10 = 2--TAREA FINALIZADA
                        AND oiddokusi_18 IS NOT NULL
                        AND dt.id_tipo_doc_18 = 3--INFORME SOCIAL
                    GROUP BY
                        ex.id_expediente_00,
                        dt.id_tipo_doc_18,
                        dt.f_alta_18
                )                docs
            WHERE
                    dt.id_doc_tarea_18 = docs.id_doc_tarea_18
                AND inf.id_expediente_16 (+) = docs.id_expediente_00
                AND inf_soc.id_informe_02 (+) = inf.id_informe_16
            UNION
            SELECT
                de.id_expediente_13,
                de.f_alta_13,
                de.oid_documento_13,
                de.nombre_doc_13
                || '.'
                || de.extension_13,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL,
                NULL
            FROM
                     ad74a12t00 be
                INNER JOIN ad74a13t00 de ON ( de.id_entrada_13 = be.id_entrada_12 )
            WHERE
                de.id_tipo_doc_13 = 3
        )
		
		/
		
		
		
		
		