
                select
                    Drug.Drug_id as "Drug_id",
                    dcm.DrugComplexMnn_id as "DrugComplexMnn_id",
                    coalesce(Drug.Drug_Name, dcm.DrugComplexMnn_RusName, '') as "Drug_Name",
                    COALESCE(ln.NAME,ACT.LATNAME,dcm.DrugComplexMnn_LatName,'') as "LatName"
                    ,cmnn.ACTMATTERS_ID as "ActMatters_id"
                from v_EvnPrescr EP
                    inner join v_EvnPrescrTreat EPT on EPT.EvnPrescrTreat_id = EP.EvnPrescr_id
                    inner join v_EvnCourseTreat ECT on ECT.EvnCourseTreat_id = EPT.EvnCourse_id
                    left join v_EvnCourseTreatDrug ec_drug on ec_drug.EvnCourseTreat_id = EPT.EvnCourse_id
                    left join rls.v_Drug Drug on Drug.Drug_id = ec_drug.Drug_id
                    left join rls.v_DrugComplexMnn dcm on dcm.DrugComplexMnn_id = COALESCE(ec_drug.DrugComplexMnn_id,Drug.DrugComplexMnn_id)
                    left join rls.drugcomplexmnnname cmnn  on cmnn.DrugComplexMnnName_id= dcm.DrugComplexMnnName_id
                    left join rls.ACTMATTERS ACT on ACT.ACTMATTERS_ID = cmnn.ACTMATTERS_id
                    left join rls.PREP p on p.Prep_id = Drug.DrugPrep_id
                    left join rls.LATINNAMES ln on ln.LATINNAMES_ID = p.LATINNAMEID
                where EP.PrescriptionType_id = 5
                    and EP.PrescriptionStatusType_id != 3
                    and EP.Lpu_id = '500801000000012'
                    and EP.pmUser_insID = '348065627787'
                order by
                    EP.EvnPrescr_setDate DESC
                limit 50
            
