
            select
                 ut.UslugaTest_id as "UslugaTest_id",
                 ut.UslugaTest_ResultValue as "UslugaTest_ResultValue",
                 to_char(ut.UslugaTest_CheckDT, 'dd.mm.yyyy hh24:mi:ss') as "UslugaTest_setDT",
                 ut.Unit_id as "Unit_id",
                 ut.UslugaComplex_id as "UslugaComplex_id",
                 ut.LabTest_id as "LabTest_id",
                 lb.LabTest_Name as "LabTest_Name",
                 uth.MedStaffFact_id as "MedStaffFact_id",
                 at.AnalyzerTestType_id as "AnalyzerTestType_id"
            from v_EvnUslugaPar eup
                 join v_EvnLabSample els on els.EvnLabSample_id = eup.EvnLabSample_id
                 join dbo.v_UslugaTest ut on ut.UslugaTest_pid = eup.EvnUslugaPar_id
                 left join lis.Unit u on u.Unit_id = ut.Unit_id
                 left join nsi.v_LabTest lb on lb.LabTest_id = ut.LabTest_id
                 left join lateral (
                     select at.AnalyzerTestType_id
                       from v_UslugaComplexMedService ucms_par
                            join v_UslugaComplexMedService ucms_ut on
                                 ucms_par.UslugaComplexMedService_id = ucms_ut.UslugaComplexMedService_pid
                            join lis.v_AnalyzerTest at on
                                 at.UslugaComplexMedService_id = ucms_ut.UslugaComplexMedService_id
                      where ucms_ut.UslugaComplex_id = ut.UslugaComplex_id
                        and ucms_par.MedService_id = els.MedService_id
                        and ucms_par.UslugaComplex_id = eup.UslugaComplex_id
                      limit 1
                 ) at on true
                 left join lateral (
                     select Person_Fin
                       from v_MedPersonal
                      where MedPersonal_id = COALESCE(els.MedPersonal_did, els.MedPersonal_sdid)
                      limit 1
                 ) ms on true
                 left join lateral (
                     select MedStaffFact_id
                       from v_UslugaTestHistory
                      where UslugaTest_id = ut.UslugaTest_id
                      order by UslugaTestHistory_id desc
                      limit 1
                 ) as uth on true
           where eup.EvnUslugaPar_id = 550101081049194
        
