- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
select distinct cast(null as integer) NZAP,d_ext_uslug_napr_zag.id_doc_public NNAPR,d_ext_uslug_napr_zag.date_doc DNAPR,
d_ext_uslug_napr_zag.form_med_pom FOMP, tab_lpu.lpu_ext_code MONAPR, tab_struct_obos_unit.code_ffoms PMONAPR, cast (:lpu_ext_code as varchar(20)) MO, TSOU1.code_ffoms PMO,
tab_other_strings.code_external VPOLIS,patients.polis_s SPOLIS,patients.polis_n NPOLIS,
tab_msk.smocod SMO, tab_msk.TF_OKATO TER,
d_ext_uslug_napr_zag.fam FAM, d_ext_uslug_napr_zag.nam IM, d_ext_uslug_napr_zag.otch OT, d_ext_uslug_napr_zag.male P, d_ext_uslug_napr_zag.born DR,
patients.TELEFON TEL,
d_ext_uslug_napr_zag.ds_osn_mkb DSNAPR, TAB_PLACE_PARAM.profil_koek_for_foms PROFK,tab_profile.CODE_PROFILE_EGISZ_PRFO PROFO,
TAB_PLACE_PARAM.profil_koek_for_foms PROFKNAPR,
tab_profile.CODE_PROFILE_EGISZ_PRFO PROFONAPR,
users.snils MEDRAB,
med_kart.id_kart_public NKART, med_kart.ds_priem_mkb DS,
d_ext_uslug_napr_zag.date_plan_gosp DPGOSP,
MED_KART.date_vipis_planed DPOGOSP
from d_ext_uslug_napr_zag
left outer join patients on patients.id_pac=d_ext_uslug_napr_zag.pac_id and patients.dae>='31.12.9999'
left outer join tab_other_strings on tab_other_strings.id_string=patients.polis_type
left outer join tab_profile on tab_profile.id_profile=d_ext_uslug_napr_zag.TARGET_PODR_PROFILE
left outer join R_USERS_DOLGN on R_USERS_DOLGN.ID_KD=d_ext_uslug_napr_zag.NAPR_DOCTOR_KD_ID
left outer join users on users.id_user=d_ext_uslug_napr_zag.napr_doctor_user_id
left outer join tab_msk on tab_msk.id_msk=patients.msk
left outer join tab_place on tab_place.id_place=d_ext_uslug_napr_zag.napr_place_id
left outer join tab_struct_obos_unit on tab_struct_obos_unit.lpu_id=d_ext_uslug_napr_zag.from_lpu_id
left outer join tab_struct_obos_unit TSOU1 on TSOU1.id_obos_unit=tab_place.obos_unit_id
left outer join d_diagn on d_diagn.id_doc = d_ext_uslug_napr_zag.id_doc
left outer join med_kart on med_kart.pac_id = patients.id_pac
and med_kart.dt_coming>=:O_BEG and med_kart.dt_coming<=:O_END
left outer join d_dvig on d_dvig.med_kart=med_kart.id_kart and d_dvig.type_dvig=31
left outer join tab_place_param on tab_place_param.id_place=d_dvig.target_place
and tab_place_param.dab<=:O_BEG and tab_place_param.dae>:O_BEG
left outer join tab_struct_place_har on tab_struct_place_har.place_id=tab_place.id_place
left outer join tab_lpu on tab_lpu.lpu_code= med_kart.napr_lpu
where d_ext_uslug_napr_zag.IS_INCOMING=0 and d_ext_uslug_napr_zag.pay_id=1 --IS_INCOMING=0 только исходящие,
and d_ext_uslug_napr_zag.date_doc>=:O_BEG and d_ext_uslug_napr_zag.date_doc<=:O_END