5	0	insert into stav (id, iduzi, idprac, mods, time_stamp, compname, cversion) values (7846, 6, 2, '//////////////////8=', '20.03.2026 07:01:45.915'/* time_stamp */, 'NTBVBHP470G10', '3.61.0.371')

17	0	execute procedure SET_USECASHDESKBYCCARDPAYMENT('F'/* USECASHDESKBYCCARDPAYMENT */)

67	0	update tellinky set idpracuziv = NULL where idpracuziv = (select id from pracuziv where idprac = 2 and iduziv = 6)

120	0	insert into statistika (datum, iduzi, idprac, textid, params, typ)
values ('20.03.2026'/* datum */, 6/* iduzi */, 2/* idprac */, 0/* textid */, 'acVybPacOrd'/* params */, '1'/* typ */)

123	0	update options set Obsah=31/* Obsah */ where ID=223/* ID */

143	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from KAR
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (vyrazen = 'N') and exists (select id from registr r join icp i on r.idicp = i.idicp where r.idpac = kar.idpac and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20') and (r.priznak in ('V','D','A')) and (i.icp = '09305001') and (i.odb = '001'))
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

299	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 3234/* ID */

319	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=3234/* IDPAC */ and AV.PLATIOD <= '01.11.2022'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

320	0	select heslotelkom from KAR where idpac = 3234

321	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

322	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

323	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

324	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

325	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

326	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

327	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

328	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

329	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 3234/* IDPAC */

330	0	select GV.DATUM from GENVYS GV where GV.IDPRE = (select first 1 IDPRE from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 0/* TYP */ order by DATUM desc)

331	0	select first 1 RPRUKAZ from KAR where IDPAC = 3234

332	0	select first 1 ZPRUKAZ from KAR where IDPAC = 3234

333	0	execute procedure sp_log(3234/* idpac */, 10000/* tblid */, 3234/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

334	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

335	0	select first 1 * from KAR

336	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

337	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from KAR
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (VYRAZEN = 'N')
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

338	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

339	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

340	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

341	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

342	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

343	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

344	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

345	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

346	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

347	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

348	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

349	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

350	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

351	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

352	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

353	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

354	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

355	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

356	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

357	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

358	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

359	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

360	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

361	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

362	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

363	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

364	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

365	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

366	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

367	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

368	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

369	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

370	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

371	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

372	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

373	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

374	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

375	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

376	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

377	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

378	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

379	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

380	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

381	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

382	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

383	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

384	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

385	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

386	0	select idicz from ICZ where poj = '111' and icz = '09305000'

387	0	select icp from ICP where idicz = '12' and odb = '001'

388	0	select idicz from ICZ where poj = '111' and icz = '09305000'

389	0	select icp from ICP where idicz = '12' and odb = '001'

390	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 3234 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 3234) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 3234  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '111' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '111' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 3234 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 3234 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 3234 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '486122443' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 3234  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 3234 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 3234 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 3234  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '486122443' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 3234 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(3234, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=3234 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 3234 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 3234) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 3234 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 3234 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '111' and P.ODB = '001'

391	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 3234/* ID */

392	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

393	0	select KOD from STALDGN where (IDPAC = 3234) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 3234 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

394	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 3234) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

395	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '486122443'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

396	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

397	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 3234) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 3234 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

398	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 3234
ORDER BY TP.DATUM DESC

399	0	select first 1 DATUM from GENVYS where IDPAC = 3234 and TYP = 110
ORDER BY DATUM DESC

400	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 3234 and ICP='09305001'

401	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 3234/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

402	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 3234/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

403	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 3234 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

404	0	select first 1 DATZAL from KAR where IDPAC = 3234

405	0	select first 1 BMI from SP_GETBMI(3234)

406	0	select first 1 puls from preh where (idpac = 3234) and not(puls is null)
ORDER BY datum DESC

407	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

408	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

409	0	select * from GETPACPOJ(3234/* IDPAC */, '20.03.2026'/* ODE_DNE */)

410	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=3234/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

411	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=3234/* IDPAC */ and AV.PLATIOD <= '01.11.2022'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

412	0	select heslotelkom from KAR where idpac = 3234

413	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

414	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

415	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

416	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

417	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

418	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

419	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

420	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

421	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 3234/* IDPAC */

422	0	select GV.DATUM from GENVYS GV where GV.IDPRE = (select first 1 IDPRE from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 0/* TYP */ order by DATUM desc)

423	0	select first 1 RPRUKAZ from KAR where IDPAC = 3234

424	0	select first 1 ZPRUKAZ from KAR where IDPAC = 3234

425	0	execute procedure sp_log(3234/* idpac */, 10000/* tblid */, 3234/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

426	0	select first 1 * from KAR

427	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

428	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from KAR
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (vyrazen = 'N') and exists (select id from registr r join icp i on r.idicp = i.idicp where r.idpac = kar.idpac and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20') and (r.priznak in ('V','D','A')) and (i.icp = '09305001') and (i.odb = '001'))
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

429	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

430	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

431	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

432	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

433	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

434	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

435	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

436	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

437	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

438	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

439	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

440	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

441	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

442	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

443	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

444	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

445	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

446	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

447	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

448	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

449	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

450	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

451	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

452	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

453	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

454	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

455	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

456	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

457	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

458	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

459	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

460	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

461	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

462	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

463	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

464	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

465	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

466	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

467	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

468	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

469	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

470	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

471	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

472	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

473	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

474	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

475	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

476	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

477	0	select idicz from ICZ where poj = '111' and icz = '09305000'

478	0	select icp from ICP where idicz = '12' and odb = '001'

479	0	select idicz from ICZ where poj = '111' and icz = '09305000'

480	0	select icp from ICP where idicz = '12' and odb = '001'

481	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 3234 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 3234) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 3234  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '111' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '111' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 3234 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 3234 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 3234 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '486122443' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 3234  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 3234 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 3234 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 3234  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '486122443' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 3234 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(3234, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=3234 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 3234 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 3234) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 3234 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 3234 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '111' and P.ODB = '001'

482	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 3234/* ID */

483	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

484	0	select KOD from STALDGN where (IDPAC = 3234) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 3234 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

485	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 3234) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

486	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '486122443'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

487	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

488	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 3234) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 3234 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

489	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 3234
ORDER BY TP.DATUM DESC

490	0	select first 1 DATUM from GENVYS where IDPAC = 3234 and TYP = 110
ORDER BY DATUM DESC

491	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 3234 and ICP='09305001'

492	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 3234/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

493	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 3234/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

494	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 3234 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

495	0	select first 1 DATZAL from KAR where IDPAC = 3234

496	0	select first 1 BMI from SP_GETBMI(3234)

497	0	select first 1 puls from preh where (idpac = 3234) and not(puls is null)
ORDER BY datum DESC

498	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

499	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

500	0	select * from GETPACPOJ(3234/* IDPAC */, '20.03.2026'/* ODE_DNE */)

501	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=3234/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

502	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=3234/* IDPAC */ and AV.PLATIOD <= '01.11.2022'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

503	0	select heslotelkom from KAR where idpac = 3234

504	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

505	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

506	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

507	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

508	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

509	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

510	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

511	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

512	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 3234/* IDPAC */

513	0	select GV.DATUM from GENVYS GV where GV.IDPRE = (select first 1 IDPRE from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 0/* TYP */ order by DATUM desc)

514	0	select first 1 RPRUKAZ from KAR where IDPAC = 3234

515	0	select first 1 ZPRUKAZ from KAR where IDPAC = 3234

516	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

517	0	execute procedure sp_log(3234/* idpac */, 10000/* tblid */, 3234/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

518	0	select first 1 * from KAR

519	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

520	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from kar join kar_sortby_idlist('4757') on idfromlist = idpac
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (VYRAZEN = 'N')
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

521	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 4757/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

522	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 4757 and ICP='09305001'

523	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 4757

524	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '7553221918'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '7553221918'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '207'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

525	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

526	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from kar join kar_sortby_idlist('4757') on idfromlist = idpac
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (VYRAZEN = 'N')
ORDER BY IDX ASC

527	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

528	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 4757/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

529	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 4757 and ICP='09305001'

530	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 4757

531	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '7553221918'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '7553221918'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '207'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

532	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

533	0	select idicz from ICZ where poj = '207' and icz = '09305000'

534	0	select icp from ICP where idicz = '15' and odb = '001'

535	0	select idicz from ICZ where poj = '207' and icz = '09305000'

536	0	select icp from ICP where idicz = '15' and odb = '001'

537	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 4757 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 4757) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 4757  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '7553221918' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '207' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '7553221918' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '207' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 4757  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(4757, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 4757 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 4757 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 4757 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '7553221918' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 4757  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 4757 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(4757, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 4757  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 4757 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 4757 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 4757  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 4757 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 4757  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '7553221918' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 4757 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 4757  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(4757, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=4757 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 4757 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 4757) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 4757 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 4757 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '207' and P.ODB = '001'

538	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 4757/* ID */

539	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

540	0	select KOD from STALDGN where (IDPAC = 4757) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 4757 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

541	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 4757) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

542	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '7553221918'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 50/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 50/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

543	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 50/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 50/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

544	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 4757) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 4757 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

545	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 4757
ORDER BY TP.DATUM DESC

546	0	select first 1 DATUM from GENVYS where IDPAC = 4757 and TYP = 110
ORDER BY DATUM DESC

547	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 4757 and ICP='09305001'

548	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 4757/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

549	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 4757/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

550	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 4757 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

551	0	select first 1 DATZAL from KAR where IDPAC = 4757

552	0	select first 1 BMI from SP_GETBMI(4757)

553	0	select first 1 puls from preh where (idpac = 4757) and not(puls is null)
ORDER BY datum DESC

554	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 4757) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 4757) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 4757) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

555	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 4757) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

556	0	select * from GETPACPOJ(4757/* IDPAC */, '20.03.2026'/* ODE_DNE */)

557	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=4757/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

558	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=4757/* IDPAC */ and AV.PLATIOD <= '11.12.2014'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

559	0	 execute block(IDPAC integer=4757/* IDPAC */, DATUM DATE='21.09.2025'/* DATUM */)
  returns (VALUE_BF varchar(8), VALUE_AF varchar(8), LEK_KOD varchar (8), LEK_NAZ varchar(30))
 as
  declare variable TMPATC varchar(7) = '';
  declare variable TMPSILA varchar(24) = '';
  declare variable RDATUM date;
  declare variable LEKKOD varchar(8)  = '';
  declare variable LEKNAZ varchar(30) = '';
  declare variable HODN_BE varchar(8) = '-1';
  declare variable HODN_AF varchar(8) = '-1';
  begin
  VALUE_BF = '-1';
  VALUE_AF = '-1';
  LEK_KOD = '';
  LEK_NAZ = '';
  select first 1 DATUM, KOD, LEK, ATC
    from RECEPT
  where
    IDPAC = :IDPAC and
    DATUM >= :DATUM and
   (ATC starting with 'C10AA01' or
    ATC starting with 'C10AA05' or
    ATC starting with 'C10AA07')
   order by datum desc
    into :RDATUM, :LEKKOD, :LEKNAZ, :TMPATC;
  if (RDATUM is null) then
    begin
      select first 1 m.DATUM, m.KOD, m.NAZ , l.ATC
        from MEDIKACE m
       join LEKY l on m.kod = l.kod
      where
       m.IDPAC = :IDPAC and
      (m.PLATI_DO >= :DATUM or m.PLATI_DO is null) and
        (l.ATC starting with 'C10AA01' or
         l.ATC starting with 'C10AA05' or
         l.ATC starting with 'C10AA07')
      order by m.DATUM desc
      into :RDATUM, :LEKKOD, :LEKNAZ, :TMPATC;
    end
  if (RDATUM is null) then
    begin
      VALUE_BF = -1;
      VALUE_AF = -1;
      LEK_KOD  = '';
      LEK_NAZ  = '';
      suspend;
      exit;
    end
  if (RDATUM is not null) then
    begin
      begin
      select first 1 VYSL
        from LABVD D
       join LABMETOD M on M.IDMETOD = D.IDMETOD and (M.KLICMZ in ('02322', '02323', '02324', '02325', '03379', '03380'))
       join LABVH H on H.IDVH = D.IDVH
      where D.IDPACIENT = :IDPAC and
            H.DATUM <= :RDATUM
      order by H.DATUM desc, D.ID desc
      into :HODN_BE;
      select STRING_OUT from sp_replace_char(:HODN_BE, ',', '.') into HODN_BE;
      select first 1 VYSL
        from LABVD D
       join LABMETOD M on M.IDMETOD = D.IDMETOD and (M.KLICMZ in ('02322', '02323', '02324', '02325', '03379', '03380'))
       join LABVH H on H.IDVH = D.IDVH
      where D.IDPACIENT = :IDPAC and
            H.DATUM >= :RDATUM
      order by H.DATUM desc, D.ID desc
      into :HODN_AF;
      select STRING_OUT from sp_replace_char(:HODN_AF, ',', '.') into HODN_AF;
     end
     if (((HODN_AF > '-1') and (HODN_AF > '0')) and ((HODN_BE = '-1') or (HODN_BE is null))) then
            begin
                HODN_BE = HODN_AF;
                select first 1 SILA from LEKY where KOD = :LEKKOD and (PLATIDO is null or PLATIDO <= 'TODAY')
                into :TMPSILA;
                if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.28 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.37 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.46 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.35 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.43 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.52 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.39 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.48 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.55 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '80') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.46 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '80') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.51 from 1 for 5);
            end
      end

      begin
        VALUE_BF = :hodn_be;
        VALUE_AF = :hodn_af;
        LEK_KOD  = :lekkod;
        LEK_NAZ  = :leknaz;
        suspend;
      end
end

560	0	select heslotelkom from KAR where idpac = 4757

561	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

562	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 4757/* IDPAC */
ORDER BY DATUM DESC

563	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 4757/* IDPAC */

564	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

565	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 4757/* IDPAC */
ORDER BY DATUM DESC

566	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 4757/* IDPAC */

567	0	select D.DATOSE from DOKLADD D where D.ID = (select first 1 DD.ID from DOKLADD DD where DD.RODCIS = '7553221918'/* RODCIS */ and DD.KOD in ('15120') order by DD.DATOSE desc)

568	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

569	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 4757/* IDPAC */
ORDER BY DATUM DESC

570	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 4757/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 4757/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 4757/* IDPAC */

571	0	select D.DATOSE from DOKLADD D where D.ID = (select first 1 DD.ID from DOKLADD DD where DD.RODCIS = '7553221918'/* RODCIS */ and DD.KOD in ('11320', '11321') order by DD.DATOSE desc)

572	0	select first 1 RPRUKAZ from KAR where IDPAC = 4757

573	0	select first 1 ZPRUKAZ from KAR where IDPAC = 4757

574	0	execute procedure sp_log(4757/* idpac */, 10000/* tblid */, 4757/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

575	0	SELECT ID,IDUZIV,IDPRAC,SECRET_TYPE,SECRET FROM KEYSTORE WHERE coalesce(IDUZIV,0)=6/* IDUZIV */ AND coalesce(IDPRAC,0)=2/* IDPRAC */ AND SECRET_TYPE='SUKLPASS'/* SECRET_TYPE */

576	0	select ID,Obsah from Options where
  (Category='Global'/* Category */) and
  (Name='CheckVersion'/* Name */) and
  (Login='2|6'/* Login */)

577	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

578	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

579	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

580	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

581	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

582	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

583	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

584	0	select FSDATS from STAV where ID = 7846/* ID */

585	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

586	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

587	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

588	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

589	0	select servertimestamp from sp_servertimestamp

590	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

591	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

592	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

593	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

594	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

595	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

596	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

597	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

598	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

599	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

600	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

601	0	select FSDATS from STAV where ID = 7846/* ID */

602	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

603	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

604	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

605	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

606	0	select servertimestamp from sp_servertimestamp

607	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

608	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

609	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

610	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

611	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

612	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

613	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

614	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

615	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

616	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

617	0	select FSDATS from STAV where ID = 7846/* ID */

618	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

619	0	select distinct(ID_ESINSTITUCE) as ID_ESINSTITUCE,
               (select first 1 MI.ID
                from MEDINETRECIP MI
                where MI.CGMNUMBER = ESI.NUMBER) as ID_MEDICALNET, coalesce((select first 1 MI.DISPLAYNAME
                                                                             from MEDINETRECIP MI
                                                                             where MI.CGMNUMBER = ESI.NUMBER), ESI.NAZEV || ', ' || ESI.ZARIZENI) as ZARIZENI,
               ESI.VXKEY, ESI.UID, ESI.NUMBER as CGMNUMBER, ESI.EMAIL
from (select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) as ID_ESINSTITUCE
      from ZARIZENI Z
      join ODDEL O on O.IDZAR = Z.ID
      join PRACOVISTE P on P.IDODDEL = O.ID
      join PRACUZIV PU on PU.IDPRAC = P.ID
      join UZIVATEL U on U.IDUZI = PU.IDUZIV
      where PU.ID = 6/* PUID */ and
            U.AKTIVNI = 'T'
      union all
      select distinct(ID_ESINSTITUCE) as ID_ESINSTITUCE
      from ES_GROUP_INT
      left join ES_GROUP on (ES_GROUP_INT.IDGROUP = ES_GROUP.ID)
      where (ES_GROUP.IDPRAC = 2/* IDPRAC */) or (ES_GROUP.IDODD = 2/* IDODD */) or (ES_GROUP.IDZAR = 2/* IDZAR */) or (ES_GROUP.IDPRACUZI = 6/* IDPRACUZIV */))
join ES_INSTITUCE ESI on ESI.ID = ID_ESINSTITUCE
where
   ESI.CLICKBOX = 'A'
ORDER BY ZARIZENI ASC

620	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

621	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

622	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

623	0	select servertimestamp from sp_servertimestamp

624	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

625	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

626	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

627	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

628	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

629	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

630	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

631	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

632	0	select first 1 * from KAR

633	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

634	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from KAR
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (vyrazen = 'N') and exists (select id from registr r join icp i on r.idicp = i.idicp where r.idpac = kar.idpac and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20') and (r.priznak in ('V','D','A')) and (i.icp = '09305001') and (i.odb = '001'))
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

635	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

636	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

637	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

638	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

639	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

640	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

641	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

642	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

643	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

644	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

645	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

646	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

647	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

648	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

649	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

650	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

651	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

652	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

653	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

654	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

655	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

656	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

657	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

658	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

659	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

660	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

661	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

662	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

663	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

664	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

665	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

666	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

667	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

668	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

669	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

670	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

671	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

672	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

673	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

674	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

675	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

676	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

677	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

678	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

679	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

680	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

681	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

682	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

683	0	select idicz from ICZ where poj = '111' and icz = '09305000'

684	0	select icp from ICP where idicz = '12' and odb = '001'

685	0	select idicz from ICZ where poj = '111' and icz = '09305000'

686	0	select icp from ICP where idicz = '12' and odb = '001'

687	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 3234 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 3234) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 3234  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '111' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '111' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 3234 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 3234 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 3234 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '486122443' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 3234  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 3234 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 3234 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 3234  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '486122443' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 3234 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(3234, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=3234 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 3234 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 3234) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 3234 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 3234 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '111' and P.ODB = '001'

688	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 3234/* ID */

689	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

690	0	select KOD from STALDGN where (IDPAC = 3234) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 3234 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

691	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 3234) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

692	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '486122443'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

693	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

694	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 3234) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 3234 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

695	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 3234
ORDER BY TP.DATUM DESC

696	0	select first 1 DATUM from GENVYS where IDPAC = 3234 and TYP = 110
ORDER BY DATUM DESC

697	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 3234 and ICP='09305001'

698	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 3234/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

699	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 3234/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

700	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 3234 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

701	0	select first 1 DATZAL from KAR where IDPAC = 3234

702	0	select first 1 BMI from SP_GETBMI(3234)

703	0	select first 1 puls from preh where (idpac = 3234) and not(puls is null)
ORDER BY datum DESC

704	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

705	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

706	0	select * from GETPACPOJ(3234/* IDPAC */, '20.03.2026'/* ODE_DNE */)

707	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=3234/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

708	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=3234/* IDPAC */ and AV.PLATIOD <= '01.11.2022'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

709	0	 execute block(IDPAC integer=3234/* IDPAC */, DATUM DATE='21.09.2025'/* DATUM */)
  returns (VALUE_BF varchar(8), VALUE_AF varchar(8), LEK_KOD varchar (8), LEK_NAZ varchar(30))
 as
  declare variable TMPATC varchar(7) = '';
  declare variable TMPSILA varchar(24) = '';
  declare variable RDATUM date;
  declare variable LEKKOD varchar(8)  = '';
  declare variable LEKNAZ varchar(30) = '';
  declare variable HODN_BE varchar(8) = '-1';
  declare variable HODN_AF varchar(8) = '-1';
  begin
  VALUE_BF = '-1';
  VALUE_AF = '-1';
  LEK_KOD = '';
  LEK_NAZ = '';
  select first 1 DATUM, KOD, LEK, ATC
    from RECEPT
  where
    IDPAC = :IDPAC and
    DATUM >= :DATUM and
   (ATC starting with 'C10AA01' or
    ATC starting with 'C10AA05' or
    ATC starting with 'C10AA07')
   order by datum desc
    into :RDATUM, :LEKKOD, :LEKNAZ, :TMPATC;
  if (RDATUM is null) then
    begin
      select first 1 m.DATUM, m.KOD, m.NAZ , l.ATC
        from MEDIKACE m
       join LEKY l on m.kod = l.kod
      where
       m.IDPAC = :IDPAC and
      (m.PLATI_DO >= :DATUM or m.PLATI_DO is null) and
        (l.ATC starting with 'C10AA01' or
         l.ATC starting with 'C10AA05' or
         l.ATC starting with 'C10AA07')
      order by m.DATUM desc
      into :RDATUM, :LEKKOD, :LEKNAZ, :TMPATC;
    end
  if (RDATUM is null) then
    begin
      VALUE_BF = -1;
      VALUE_AF = -1;
      LEK_KOD  = '';
      LEK_NAZ  = '';
      suspend;
      exit;
    end
  if (RDATUM is not null) then
    begin
      begin
      select first 1 VYSL
        from LABVD D
       join LABMETOD M on M.IDMETOD = D.IDMETOD and (M.KLICMZ in ('02322', '02323', '02324', '02325', '03379', '03380'))
       join LABVH H on H.IDVH = D.IDVH
      where D.IDPACIENT = :IDPAC and
            H.DATUM <= :RDATUM
      order by H.DATUM desc, D.ID desc
      into :HODN_BE;
      select STRING_OUT from sp_replace_char(:HODN_BE, ',', '.') into HODN_BE;
      select first 1 VYSL
        from LABVD D
       join LABMETOD M on M.IDMETOD = D.IDMETOD and (M.KLICMZ in ('02322', '02323', '02324', '02325', '03379', '03380'))
       join LABVH H on H.IDVH = D.IDVH
      where D.IDPACIENT = :IDPAC and
            H.DATUM >= :RDATUM
      order by H.DATUM desc, D.ID desc
      into :HODN_AF;
      select STRING_OUT from sp_replace_char(:HODN_AF, ',', '.') into HODN_AF;
     end
     if (((HODN_AF > '-1') and (HODN_AF > '0')) and ((HODN_BE = '-1') or (HODN_BE is null))) then
            begin
                HODN_BE = HODN_AF;
                select first 1 SILA from LEKY where KOD = :LEKKOD and (PLATIDO is null or PLATIDO <= 'TODAY')
                into :TMPSILA;
                if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.28 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.37 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.46 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.35 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.43 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.52 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.39 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.48 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.55 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '80') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.46 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '80') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.51 from 1 for 5);
            end
      end

      begin
        VALUE_BF = :hodn_be;
        VALUE_AF = :hodn_af;
        LEK_KOD  = :lekkod;
        LEK_NAZ  = :leknaz;
        suspend;
      end
end

710	0	select heslotelkom from KAR where idpac = 3234

711	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

712	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

713	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

714	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

715	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

716	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

717	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

718	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

719	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 3234/* IDPAC */

720	0	select GV.DATUM from GENVYS GV where GV.IDPRE = (select first 1 IDPRE from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 0/* TYP */ order by DATUM desc)

721	0	select first 1 RPRUKAZ from KAR where IDPAC = 3234

722	0	select first 1 ZPRUKAZ from KAR where IDPAC = 3234

723	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

724	0	execute procedure sp_log(3234/* idpac */, 10000/* tblid */, 3234/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

725	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

726	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

727	0	select FSDATS from STAV where ID = 7846/* ID */

728	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

729	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

730	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

731	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

732	0	select servertimestamp from sp_servertimestamp

733	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

734	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

735	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

736	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

737	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

738	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

739	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

740	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

741	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

742	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

743	0	select FSDATS from STAV where ID = 7846/* ID */

744	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

745	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

746	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

747	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

748	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

749	0	select servertimestamp from sp_servertimestamp

750	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

751	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

752	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

753	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

754	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

755	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

756	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

757	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

758	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

759	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

760	0	select FSDATS from STAV where ID = 7846/* ID */

761	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

762	0	select distinct(ID_ESINSTITUCE) as ID_ESINSTITUCE,
               (select first 1 MI.ID
                from MEDINETRECIP MI
                where MI.CGMNUMBER = ESI.NUMBER) as ID_MEDICALNET, coalesce((select first 1 MI.DISPLAYNAME
                                                                             from MEDINETRECIP MI
                                                                             where MI.CGMNUMBER = ESI.NUMBER), ESI.NAZEV || ', ' || ESI.ZARIZENI) as ZARIZENI,
               ESI.VXKEY, ESI.UID, ESI.NUMBER as CGMNUMBER, ESI.EMAIL
from (select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) as ID_ESINSTITUCE
      from ZARIZENI Z
      join ODDEL O on O.IDZAR = Z.ID
      join PRACOVISTE P on P.IDODDEL = O.ID
      join PRACUZIV PU on PU.IDPRAC = P.ID
      join UZIVATEL U on U.IDUZI = PU.IDUZIV
      where PU.ID = 6/* PUID */ and
            U.AKTIVNI = 'T'
      union all
      select distinct(ID_ESINSTITUCE) as ID_ESINSTITUCE
      from ES_GROUP_INT
      left join ES_GROUP on (ES_GROUP_INT.IDGROUP = ES_GROUP.ID)
      where (ES_GROUP.IDPRAC = 2/* IDPRAC */) or (ES_GROUP.IDODD = 2/* IDODD */) or (ES_GROUP.IDZAR = 2/* IDZAR */) or (ES_GROUP.IDPRACUZI = 6/* IDPRACUZIV */))
join ES_INSTITUCE ESI on ESI.ID = ID_ESINSTITUCE
where
   ESI.CLICKBOX = 'A'
ORDER BY ZARIZENI ASC

763	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

764	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

765	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

766	0	select servertimestamp from sp_servertimestamp

767	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

768	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

769	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

770	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

771	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

772	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

773	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

774	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

775	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

776	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

777	0	select FSDATS from STAV where ID = 7846/* ID */

778	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

779	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

780	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

781	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

782	0	select servertimestamp from sp_servertimestamp

783	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

784	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

785	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

786	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

787	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

788	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

789	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

790	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

791	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

792	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

793	0	select FSDATS from STAV where ID = 7846/* ID */

794	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

795	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

796	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

797	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

798	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

799	0	select servertimestamp from sp_servertimestamp

800	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

801	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

802	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

803	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

804	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

805	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

806	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

807	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

808	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

809	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

810	0	select FSDATS from STAV where ID = 7846/* ID */

811	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

812	0	select distinct(ID_ESINSTITUCE) as ID_ESINSTITUCE,
               (select first 1 MI.ID
                from MEDINETRECIP MI
                where MI.CGMNUMBER = ESI.NUMBER) as ID_MEDICALNET, coalesce((select first 1 MI.DISPLAYNAME
                                                                             from MEDINETRECIP MI
                                                                             where MI.CGMNUMBER = ESI.NUMBER), ESI.NAZEV || ', ' || ESI.ZARIZENI) as ZARIZENI,
               ESI.VXKEY, ESI.UID, ESI.NUMBER as CGMNUMBER, ESI.EMAIL
from (select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) as ID_ESINSTITUCE
      from ZARIZENI Z
      join ODDEL O on O.IDZAR = Z.ID
      join PRACOVISTE P on P.IDODDEL = O.ID
      join PRACUZIV PU on PU.IDPRAC = P.ID
      join UZIVATEL U on U.IDUZI = PU.IDUZIV
      where PU.ID = 6/* PUID */ and
            U.AKTIVNI = 'T'
      union all
      select distinct(ID_ESINSTITUCE) as ID_ESINSTITUCE
      from ES_GROUP_INT
      left join ES_GROUP on (ES_GROUP_INT.IDGROUP = ES_GROUP.ID)
      where (ES_GROUP.IDPRAC = 2/* IDPRAC */) or (ES_GROUP.IDODD = 2/* IDODD */) or (ES_GROUP.IDZAR = 2/* IDZAR */) or (ES_GROUP.IDPRACUZI = 6/* IDPRACUZIV */))
join ES_INSTITUCE ESI on ESI.ID = ID_ESINSTITUCE
where
   ESI.CLICKBOX = 'A'
ORDER BY ZARIZENI ASC

813	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

814	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

815	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

816	0	select servertimestamp from sp_servertimestamp

817	0	select first 1 LOGIN from OPTIONS where CATEGORY = 'MediWorker' and ID = 924578946

818	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

819	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

820	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

821	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

822	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

823	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

824	0	select first 1 * from KAR

825	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

826	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from KAR
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (VYRAZEN = 'N')
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

827	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

828	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

829	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

830	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

831	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

832	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

833	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

834	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

835	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

836	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

837	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

838	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

839	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

840	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

841	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

842	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

843	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

844	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

845	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

846	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

847	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

848	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

849	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

850	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

851	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

852	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

853	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

854	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

855	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

856	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

857	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

858	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

859	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

860	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

861	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

862	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

863	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

864	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

865	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

866	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

867	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

868	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

869	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

870	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

871	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

872	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

873	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

874	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

875	0	select idicz from ICZ where poj = '111' and icz = '09305000'

876	0	select icp from ICP where idicz = '12' and odb = '001'

877	0	select idicz from ICZ where poj = '111' and icz = '09305000'

878	0	select icp from ICP where idicz = '12' and odb = '001'

879	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 3234 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 3234) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 3234  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '111' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '111' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 3234 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 3234 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 3234 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '486122443' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 3234  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 3234 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 3234 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 3234  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '486122443' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 3234 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(3234, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=3234 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 3234 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 3234) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 3234 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 3234 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '111' and P.ODB = '001'

880	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 3234/* ID */

881	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

882	0	select KOD from STALDGN where (IDPAC = 3234) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 3234 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

883	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 3234) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

884	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '486122443'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

885	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

886	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 3234) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 3234 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

887	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 3234
ORDER BY TP.DATUM DESC

888	0	select first 1 DATUM from GENVYS where IDPAC = 3234 and TYP = 110
ORDER BY DATUM DESC

889	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 3234 and ICP='09305001'

890	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 3234/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

891	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 3234/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

892	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 3234 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

893	0	select first 1 DATZAL from KAR where IDPAC = 3234

894	0	select first 1 BMI from SP_GETBMI(3234)

895	0	select first 1 puls from preh where (idpac = 3234) and not(puls is null)
ORDER BY datum DESC

896	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

897	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

898	0	select * from GETPACPOJ(3234/* IDPAC */, '20.03.2026'/* ODE_DNE */)

899	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=3234/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

900	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=3234/* IDPAC */ and AV.PLATIOD <= '01.11.2022'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

901	0	select heslotelkom from KAR where idpac = 3234

902	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

903	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

904	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

905	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

906	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

907	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

908	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

909	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

910	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 3234/* IDPAC */

911	0	select GV.DATUM from GENVYS GV where GV.IDPRE = (select first 1 IDPRE from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 0/* TYP */ order by DATUM desc)

912	0	select first 1 RPRUKAZ from KAR where IDPAC = 3234

913	0	select first 1 ZPRUKAZ from KAR where IDPAC = 3234

914	0	execute procedure sp_log(3234/* idpac */, 10000/* tblid */, 3234/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

915	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

916	0	select first 1 * from KAR

917	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

918	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from KAR
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (vyrazen = 'N') and exists (select id from registr r join icp i on r.idicp = i.idicp where r.idpac = kar.idpac and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20') and (r.priznak in ('V','D','A')) and (i.icp = '09305001') and (i.odb = '001'))
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

919	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

920	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

921	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

922	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

923	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

924	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

925	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

926	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

927	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

928	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

929	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

930	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

931	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

932	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

933	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

934	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

935	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

936	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

937	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

938	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

939	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

940	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

941	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

942	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

943	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

944	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

945	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

946	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

947	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

948	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

949	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

950	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

951	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

952	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

953	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

954	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

955	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

956	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

957	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

958	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

959	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

960	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

961	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

962	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 3234/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

963	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 3234 and ICP='09305001'

964	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 3234

965	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '486122443'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '486122443'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '111'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

966	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '486122443'/* RODCIS */) and (IDA is NULL) and (POJ = '111'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

967	0	select idicz from ICZ where poj = '111' and icz = '09305000'

968	0	select icp from ICP where idicz = '12' and odb = '001'

969	0	select idicz from ICZ where poj = '111' and icz = '09305000'

970	0	select icp from ICP where idicz = '12' and odb = '001'

971	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 3234 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 3234) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 3234  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '111' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '486122443' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '111' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 3234 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 3234 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 3234 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '486122443' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 3234  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 3234 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(3234, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 3234 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 3234  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 3234 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 3234  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '486122443' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 3234 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 3234  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(3234, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=3234 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 3234 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 3234) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 3234 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 3234 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '111' and P.ODB = '001'

972	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 3234/* ID */

973	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

974	0	select KOD from STALDGN where (IDPAC = 3234) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 3234 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

975	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 3234) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

976	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '486122443'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

977	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 77/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 77/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

978	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 3234) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 3234 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

979	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 3234
ORDER BY TP.DATUM DESC

980	0	select first 1 DATUM from GENVYS where IDPAC = 3234 and TYP = 110
ORDER BY DATUM DESC

981	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 3234 and ICP='09305001'

982	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 3234/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

983	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 3234/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

984	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 3234 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

985	0	select first 1 DATZAL from KAR where IDPAC = 3234

986	0	select first 1 BMI from SP_GETBMI(3234)

987	0	select first 1 puls from preh where (idpac = 3234) and not(puls is null)
ORDER BY datum DESC

988	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 3234) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

989	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 3234) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

990	0	select * from GETPACPOJ(3234/* IDPAC */, '20.03.2026'/* ODE_DNE */)

991	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=3234/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

992	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=3234/* IDPAC */ and AV.PLATIOD <= '01.11.2022'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

993	0	select heslotelkom from KAR where idpac = 3234

994	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

995	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

996	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

997	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

998	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

999	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 3234/* IDPAC */

1000	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 3234) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

1001	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 3234/* IDPAC */
ORDER BY DATUM DESC

1002	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 3234/* IDPAC */

1003	0	select GV.DATUM from GENVYS GV where GV.IDPRE = (select first 1 IDPRE from GENVYS where IDPAC = 3234/* IDPAC */ and TYP = 0/* TYP */ order by DATUM desc)

1004	0	select first 1 RPRUKAZ from KAR where IDPAC = 3234

1005	0	select first 1 ZPRUKAZ from KAR where IDPAC = 3234

1006	0	execute procedure sp_log(3234/* idpac */, 10000/* tblid */, 3234/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

1007	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

1008	0	select first 1 * from KAR

1009	0	select ID_ESINSTITUCE from ( select coalesce(PU.ID_ESINSTITUCE, P.ID_ESINSTITUCE, O.ID_ESINSTITUCE, Z.ID_ESINSTITUCE) ID_ESINSTITUCE from PRACUZIV PU left join PRACOVISTE P on (P.ID=PU.IDPRAC) left join ODDEL O on (P.IDODDEL=O.ID) left join ZARIZENI Z on (O.IDZAR=Z.ID) where PU.IDPRAC = 2 and PU.IDUZIV = 6 ) ORGS where exists (select ID from ES_INSTITUCE where ID = ORGS.ID_ESINSTITUCE and ESERVICES = 'T')

1010	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from kar join kar_sortby_idlist('4757') on idfromlist = idpac
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (VYRAZEN = 'N')
ORDER BY KAR.PRIJMENI_UP ASC
       , KAR.RODCIS ASC

1011	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 4757/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

1012	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 4757 and ICP='09305001'

1013	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 4757

1014	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '7553221918'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '7553221918'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '207'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

1015	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

1016	0	select KAR.DATNAR,(select first 1 STAV from ES_PACIDENT join ES_PAC on (ES_PAC.ID=ES_PACIDENT.PAC_ID) left join ES_BROKER on (ES_BROKER.id_es_pac = ES_PAC.ID) where ((ES_PAC.idpac = kar.idpac) or (ES_BROKER.idpac = kar.idpac)) and ES_PACIDENT.INST_ID = 0) as ES_STAV,KAR.IDPAC,KAR.INFORMACE,KAR.INFORMACE_COL,KAR.JMENO,(select first 1 KZ.IDZAR from KARZARAZENI KZ where (KZ.IDPAC=KAR.IDPAC) and (KZ.DATUM is null or (KZ.DATUM<=CURRENT_DATE)) and (KZ.DATUMDO is null or (KZ.DATUMDO>=CURRENT_DATE)) order by KZ.ID) as K_ZARZAR,KAR.POHLAVI,GPP.POJ,KAR.POZNAMKA,KAR.PRIJMENI,KAR.PRIJMENI_UP,(select DATUM_REGISTRACE from SP_GETREGDAT(kar.IDPAC)) as REGDATUM,KAR.REGISTROVAL,(select PRIZNAK from SP_GETREGDAT(kar.IDPAC)) as REGPRIZNAK,KAR.RODCIS,KAR.ROZENA,(select first 1 OUTCOLS from GETKARZARAZENICOLORS(kar.idpac, '2026-03-20')) as SKUPINY,KAR.TITUL,KAR.TITULZA,KAR.TRVOBEC,KAR.TRVPSC,KAR.TRVULICE,KAR.VYRAZEN
from kar join kar_sortby_idlist('4757') on idfromlist = idpac
left join GETPACPOJ(KAR.IDPAC, '2026-03-20') GPP on GPP.IDPAC = KAR.IDPAC
where (VYRAZEN = 'N')
ORDER BY IDX ASC

1017	0	select IDZAR, BARVA from ZARAZENI_SPEC_S where BARVA is NOT NULL

1018	0	select first 1 ALERGIE from ANAMNEZA where IDPAC = 4757/* IDPAC */   and DATUM <= '20.03.2026'/* DATUM */
ORDER BY DATUM DESC
       , ID DESC

1019	0	select first 1 KAP_CHECK, KAP_STAV from KARB2B where IDPAC = 4757 and ICP='09305001'

1020	0	select first 1 VAKCINACE_CHECK, VAKCINACE_STAV, VAKCINACE_DATUM from KARISIN where IDPAC = 4757

1021	0	select distinct H.TYP from DOKLADH H join DOKLADD D on H.IDHLAV = D.IDHLAV where ((H.RODCIS = '7553221918'/* RODCIS */) or (H.RODCIS is null)) and (D.RODCIS = '7553221918'/* RODCIS */) and (H.IDA is NULL) and (H.POJ = '207'/* POJ */ ) and (H.ICZ = '09305001'/* ICZ */) and (H.HODB = '001'/* ODB */)

1022	0	select 'acDokladHCes', 'DOC%C' || case count(*) when 0 then '' else 'X' end from CESH    join CESD on  CESD.IDHLAV = CESH.IDHLAV
where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHLaz', 'DOC%L' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                   (DSK_TYP_DOK='L') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHOzdrav', 'DOC%V' || case count(*) when 0 then '' else 'X' end from LZN_DOKLADH where                (DSK_TYP_DOK='O') AND (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from LZN_DOKLADD where IDHLAV = LZN_DOKLADH.IDHLAV)
union
select 'acDokladHDrg', 'DOC%D' || case count(*) when 0 then '' else 'X' end from DRG         where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHOrtop', 'DOC%O' || case count(*) when 0 then '' else 'X' end from POU       where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */)
union
select 'acDokladHFoni', 'DOC%F' || case count(*) when 0 then '' else 'X' end from POUFONIH   where                   (RODCIS = '7553221918'/* RODCIS */) and (IDA is NULL) and (POJ = '207'/* POJ */) and exists(select ID from POUFONID where IDHLAV = POUFONIH.IDHLAV)

1023	0	select idicz from ICZ where poj = '207' and icz = '09305000'

1024	0	select icp from ICP where idicz = '15' and odb = '001'

1025	0	select idicz from ICZ where poj = '207' and icz = '09305000'

1026	0	select icp from ICP where idicz = '15' and odb = '001'

1027	0	select  cast('BalickyPac' as varchar(11)) as ID, substring(cast(BPAC.KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(BPAC.CENPASMO as VARCHAR(70)) from 1 for 30) as VAR2, cast(BPAC.DATUMOD as DATE) as DATE1, cast(BPAC.DATUMDO as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from BALICKYPAC BPAC left join SP_BALICKYPAC_PRIZNAK(BPAC.ID, '20.03.2026') PRI on 1 = 1 where BPAC.IDPAC = 4757 and PRI.PRIZNAK in ('A', 'B')  union select  cast('Dluh' as varchar(11)) as ID, substring(cast(P.MENA as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast((SUM(P.CENA - P.SLEVAC) - (SUM(P.PLATBA) + SUM((COALESCE((select SUM(case ZD.TYP when 'R' then ZD.CELKEM else -ZD.CELKEM end) from PLADET ZD where ZD.IDPLA = P.IDPLA and (ZD.TYP <> P.DOKLADTYP) and (ZD.TYP <> '|') and ((ZD.CENA < 0) or (ZD.TYP = 'R'))), 0))))) as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM PLA P WHERE (P.IDPAC = 4757) AND       (P.DOKLADTYP = 'F') AND       (P.STORNO IS NULL) AND       (P.NENISALDO = 'F') AND       ((P.SPLATNOST IS NULL) OR (P.SPLATNOST < '2026-03-20')) AND       (P.VALID = 'F') GROUP BY P.MENA  union select  cast('SouhlasPac' as varchar(11)) as ID, substring(cast(case     when S.NAZEV is null then       case         when H.TYP = 'ZSOUPOS' then 'Souhlas/Nesouhlas s poskytnutím zdravotních služeb nezletilému'         when H.TYP = 'ZSOUPOZ' then 'Souhlas zákonného zástupce nezletilého pacienta staršího 15ti let'         when H.TYP = 'ZSOUPO2' then 'Nesouhlas s poskytnutím zdravotních služeb - povinné oèkování'         when H.TYP = 'ZPOSIN2' then 'Urèení osoby oprávnìné dle zákona o zdravotních službách'         when H.TYP = 'OdmPece' then 'Prohlášení o odmítnutí zdravotní péèe pacientem - Negativní revers'       end     else S.NAZEV   end as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(H.DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC H left join SOUHLASPACSABL S on H.IDSOUHLASPACSABL = S.ID where H.TYP in ('IndSou', 'ZSOUPOS', 'ZSOUPOZ', 'ZSOUPO2', 'ZPOSIN2', 'OdmPece') and       H.IDPACI = 4757  union select  cast('sCenaVykZUM' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(coalesce(sum(cenabod),0) + coalesce(sum(cenamat),0) as NUMERIC(15,2)) as NUM1, cast((select coalesce(sum(cena),0) from LECD d where d.RODCIS = '7553221918' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N')) and exists (select h.IDLEC from LECH h where h.IDLEC = d.IDLEC and h.POJ = '207' and h.ICZ in ('09305001'))) as NUMERIC(15,2)) as NUM2 from DOKLADD d where d.RODCIS = '7553221918' and extract(year from d.DATOSE) = '2026' and ((d.KAT is null) or (d.KAT <> 'N' and d.KAT <> 'K' and d.KAT <> 'A')) and exists (select h.IDHLAV from DOKLADH h where h.IDHLAV = d.IDHLAV and h.POJ = '207' and h.ICZ in ('09305001'))  union select  cast('Registrl' as varchar(11)) as ID, substring(cast(REGISTROVAL as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 4757  union select  cast('OseLekPrak' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(CAST(ODBORN as INTEGER) as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(4757, 'T') WHERE ODBORN in ('001', '002')  union select  cast('SledLek' as varchar(11)) as ID, substring(cast(KOD as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(LEK as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SLEDLEK where IDPAC = 4757 and DATUM <= '2026-03-20'  union select  first 10  cast('HistDoc' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from HISTDOC where IDPACI = 4757 and STAV is NULL and IDZARPR = 2 and IDODDPR = 2 and IDPRACPR = 2  union select  first 1  cast('LastSms' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(SENDTIME) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from SMS where PACID = 4757 and SENDTIME is not NULL and not(STATUS in (100,1000))  union select  first 1  cast('PozadLekar' as varchar(11)) as ID, substring(cast(H.EICZ as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(H.EODZ as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADH H where H.IDHLAV = (select first 1 I.IDHLAV from DOKLADH I where I.RODCIS = '7553221918' and I.EICZ is not NULL order by I.IDHLAV desc)  union select  first 10  cast('Prilohy' as varchar(11)) as ID, substring(cast(FILENAME as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from FILES where IDPAC = 4757  union select  first 10  cast('Objednavky' as varchar(11)) as ID, substring(cast(F_CONCAT(U.PRIJMENI, F_CONCAT(U.JMENO, U.TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(PRAC as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(CAS as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OBJOBJ O join PRACOVISTE P on (P.ID = O.IDPRAC) join UZIVATEL U on (U.IDUZI = O.IDUZI) where IDPAC = 4757 and DATUM >= '20.03.2026'  union select  cast('OseLek' as varchar(11)) as ID, substring(cast(F_CONCAT(PRIJMENI, F_CONCAT(JMENO, TITUL, ', '), ' ') as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(TITUL2 as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 FROM KARUZIV_SEL(4757, 'T')  union select  cast('PeProhlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(TERMIN as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREH join PREINIH on (PREH.IDPREINI = PREINIH.IDPREINI) where IDPAC = 4757  union select  cast('Medikace' as varchar(11)) as ID, substring(cast(NAZ as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(PLATI_OD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from MEDIKACE where IDPAC = 4757 and PLATI_OD <= '20.03.2026' and (PLATI_DO >= '20.03.2026' or PLATI_DO is NULL)  union select  cast('NextDispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(PRISTI as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 4757 and PRISTI is not NULL  union select  cast('Dispenz' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(SKUPINA as VARCHAR(70)) from 1 for 30) as VAR2, cast(DATZAR as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DISPAC join DISSKU on (DISSKU.IDDIS = DISPAC.IDDIS) where IDPAC = 4757  union select  cast('Prohlidky' as varchar(11)) as ID, substring(cast(NAZEV as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUM as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PREPRI join PREINIH on (PREPRI.IDPREINI = PREINIH.IDPREINI) where IDPAC = 4757 and datum is not null  union select  cast('NextOck' as varchar(11)) as ID, substring(cast(coalesce(NAZ,ZKRATKA) as VARCHAR(254)) from 1 for 250) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(DATUMD as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from OCKPRI o left join KLK k on o.ZKRATKA = k.KOD where IDPAC = 4757  union select  first 1  cast('LastVykon' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(D.KOD as VARCHAR(70)) from 1 for 30) as VAR2, cast(D.DATOSE as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DOKLADD D where D.ID = (select first 1 dd.id from dokladd dd join dokladh dh on (dh.idhlav = dd.idhlav) where dd.rodcis = '7553221918' and (dh.hodb = '001' or dh.hodb is null) order by dd.datose desc)  union select  first 1  cast('LastDekurs' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from DEKURS where IDPAC = 4757 and (IDPRAC = 2 or IDPRAC = -1)  union select  first 1  cast('Karta' as varchar(11)) as ID, substring(cast(INFORMACE as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(CIZINEC as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(INFORMACE_COL as INTEGER) as INT1, POZNAMKA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from KAR where IDPAC = 4757  union select  first 1  cast('Saldo' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(SALDO as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from PACIENT_SALDO(4757, 1, 0, 0)  union select  first 1  cast('Anamneza' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, substring(cast(KREVSKUP as VARCHAR(70)) from 1 for 30) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ANAMNEZA as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where ID = (select first 1 ID from ANAMNEZA where IDPAC=4757 order by DATUM DESC, ID desc)  union select  first 20  cast('Ockovani' as varchar(11)) as ID, substring(cast(ockzaz.LATKA as VARCHAR(254)) from 1 for 250) as VAR1, substring(cast(ockzaz.ZKRATKA as VARCHAR(70)) from 1 for 30) as VAR2, cast(max(ockzaz.DATUM) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ockzaz where ockzaz.idpac = 4757 group by ockzaz.ZKRATKA, ockzaz.LATKA  union select  first 1  cast('NeschopenOd' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(MAX(ZACNES) as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from NES where (IDPAC = 4757) and (ZACNES <= '20.03.2026') and ((KONNES is NULL) or (KONNES > '20.03.2026')) and (STORNO = 'F')  union select  first 1  cast('Alergie' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(NULL as INTEGER) as INT1, ALERGIE as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ANAMNEZA where IDPAC = 4757 and ID = (select first 1 ID from ANAMNEZA where IDPAC = 4757 and DATUM <= '20.03.2026' order by DATUM desc, ID desc)  union select  first 1  cast('Pojistovna' as varchar(11)) as ID, cast(NULL as VARCHAR(254)) as VAR1, cast(NULL as VARCHAR(70)) as VAR2, cast(NULL as DATE) as DATE1, cast(NULL as DATE) as DATE2, cast(NULL as TIMESTAMP) as TIME1, cast(P.IDICP as INTEGER) as INT1, NULL as TEXT1, cast(NULL as NUMERIC(15,2)) as NUM1, cast(NULL as NUMERIC(15,2)) as NUM2 from ICP P join ICZ Z on (Z.IDICZ = P.IDICZ) where Z.POJ = '207' and P.ODB = '001'

1028	0	select POHLAVI,PRIJMENI,JMENO,TITUL,(select first 1 POJ from GETPACPOJ(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as POJ,DATNAR,RODCIS,IDSTAV,DRUHPOJ,TRVOBEC,TRVULICE,TRVPSC,PREOBEC,PREULICE,PREPSC,AKTIVBYDL,ZAMEST,ZAMADRESA,IDZAMEST,PROFES,OSCISLO,GEONOMU,(select KOD from GETPACCENPAS(IDPAC, '20.03.2026 00:00:00.000'/* ODE_DNE */)) as CENPAS,ROZENA,IZIPOD,STPRIS,ZUJEDN,PRUKAZ,TYPPECE,CIZINEC,TITULZA,DATREG,ZASTUPOVANY_ICP,IDISIN,UPRCHLIK from KAR where IDPAC = 4757/* ID */

1029	0	select first 1 R.ID, R.DATUM from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

1030	0	select KOD from STALDGN where (IDPAC = 4757) and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = 4757 order by DATUM desc)
ORDER BY PORADI ASC
       , KOD ASC

1031	0	select first 1 N.ZACNES, D.DATUM, D.KAM, D.KAMODKUD, D.ICZ
from NES N left join NESD D on D.IDNES = N.ID
where (N.IDPAC = 4757) and (N.ZACNES <= '20.03.2026') and ((N.KONNES is NULL) or (N.KONNES > '20.03.2026')) and (N.STORNO = 'F')
ORDER BY N.ZACNES DESC
       , D.DATUM DESC
       , D.ID DESC

1032	0	select PV.KOD,
(select first 1 D.DATOSE from DOKLADD D where D.RODCIS = '7553221918'/* RODCIS */ and D.KOD = PV.KOD order by DATOSE desc),
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.ICP is NULL or PV.ICP = '09305001'/* ICP */)
and (PV.VEKOD is NULL or PV.VEKOD <= 50/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 50/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

1033	0	select PV.KOD,
PV.JENREG,
PV.ODVYKAZANI
from PROHVYK PV
where (PV.ODBORN is NULL or PV.ODBORN = '001'/* ODB */)
and (PV.VEKOD is NULL or PV.VEKOD <= 50/* VEKOD */)
and (PV.VEKDO is NULL or PV.VEKDO > 50/* VEKDO */)
and (PV.POHLAVI is NULL or PV.POHLAVI = 'Z'/* POHLAVI */)
ORDER BY PV.KOD ASC

1034	0	select S.NAZEV, M.NAZ, S.KOD from STALDGN S join MKN10 M on (M.KOD = S.KOD and (M.PLATIOD is NULL or M.PLATIOD <= 'NOW') and (M.PLATIDO is NULL or M.PLATIDO >= 'NOW')) where (S.IDPAC = 4757) and S.IDANAM = (select first 1 A.ID from ANAMNEZA A where A.IDPAC = 4757 order by A.DATUM desc)
ORDER BY S.PORADI ASC
       , S.KOD ASC

1035	0	select first 1 TP.DATUM from TEHPRO TP join TEH T on T.IDTEH = TP.IDTEH where T.IDPAC = 4757
ORDER BY TP.DATUM DESC

1036	0	select first 1 DATUM from GENVYS where IDPAC = 4757 and TYP = 110
ORDER BY DATUM DESC

1037	0	select first 1 KAP_CHECK, KAP_STAV, DALSI_KONTROLA from KARB2B where IDPAC = 4757 and ICP='09305001'

1038	0	select first 1 T.WARN, T.POZN, T.DATUM from TEHKAL T where (T.IDPAC = 4757/* IDPAC */) and (T.DATUM >= '20.03.2026'/* DATUM */)
ORDER BY DATUM ASC

1039	0	select first 1 (case T.VYPOCETDLE when 1 then (T.PM) else (T.UZ1POROD - 280) end) as POCATEKTEH
from Teh T
  left join kar K on (K.idpac = T.IdPac)
where
  (T.IDPAC = 4757/* IDPAC */) and
  ((ENDTEH>='20.03.2026 00:00:00.000'/* Dnes */) or (ENDTEH is null)) and /* pouze vysetreni pred datem ukonceni*/
  (((PM is NULL) and (UZ1POROD is NULL) and (ENDTEH is null)) or /* nelze zjistit konec tehotenstvi*/
   (T.PM >= ('20.03.2026 00:00:00.000'/* Dnes */ - (42*7))) or /* max. delka tehotenstvi dle PM 42 tyd. */
   ((PM is null) and (UZ1POROD+14 >= '20.03.2026 00:00:00.000'/* Dnes */)) /* max. termin dle UZ + 14 dni */
  )
ORDER BY PM DESC NULLS LAST
       , UZ1POROD DESC NULLS LAST

1040	0	select first 1 ZAMEST, ZAMADRESA, PROFES, ICO from KAR left join FIRMY on FIRMY.FIRMA = KAR.ZAMEST where IDPAC = 4757 and (ZAMEST is not NULL or ZAMADRESA is not NULL or PROFES is not NULL)

1041	0	select first 1 DATZAL from KAR where IDPAC = 4757

1042	0	select first 1 BMI from SP_GETBMI(4757)

1043	0	select first 1 puls from preh where (idpac = 4757) and not(puls is null)
ORDER BY datum DESC

1044	0	select first 1 ZACNES, CISNES, ID, (select first 1 DATA from HISTDOC where TYP = 'POTDPN' and (IDPACI = 4757) and (DATA like '%CisNes=' || NES.CISNES || '%') order by DATUM desc) from NES where (IDPAC = 4757) and ('2026-03-20' >= ZACNES + 10) and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and ((select count(*) from HISTDOC where TYP = 'POTDPN' and (IDPACI = 4757) and (extract(month from DATUM) || extract(year from DATUM) = extract(month from cast('2026-03-20' as date) + 4) || extract(year from cast('2026-03-20' as date) + 4)) and DATA like '%CisNes=' || NES.CISNES || '%') = 0) and (not exists(select Id from nesd where nesd.idnes = nes.id) or ((select first 1 Kam from nesd where nesd.idnes = nes.id order by nesd.datum desc, nesd.id desc) = 'N'))
ORDER BY ZACNES ASC

1045	0	select first 1 ZACNES, CISNES, ID, POTVRZENI_VYDANO from NES where (IDPAC = 4757) and ('2026-03-20' >= ZACNES + 10)  and ((KONNES is NULL) or (KONNES > '2026-03-20')) and (STORNO = 'F') and (extract(month from POTVRZENI_VYDANO) || extract(year from POTVRZENI_VYDANO) = extract(month from cast('2026-03-20' as date)) || extract(year from cast('2026-03-20' as date)))
ORDER BY ZACNES ASC

1046	0	select * from GETPACPOJ(4757/* IDPAC */, '20.03.2026'/* ODE_DNE */)

1047	0	select ID, IDPAC, ANAMNEZA, DATUM, ALERGIE, KREVSKUP,
HBSAG, DUCHOD, BEZMOCNOST, HIV, MESOD, MESDO,
MESTYP, BWR, ISOIMUN, PANEV, coalesce(POCPOROD, -1) as POCPOROD, coalesce(POCPOTRAT, -1) as POCPOTRAT,
coalesce(POCINTER, -1) as POCINTER, coalesce(POCOPER, -1) as POCOPER, IDUZIV, SIGNATURE, SIGNATURE_INFO,
IDCERTIFICATE, RHDATUM, RHVYSL, TRIZOMIE, NTD, VVV,
IZIPSTAT, KURAK, TST, KARDIOSTIM, CIGARETDENNE, FREKKOURENI,
(select first 1 vyska from preh where (idpac = anamneza.idpac) and (vyska is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vyska,
(select first 1 vaha from preh where (idpac = anamneza.idpac) and (vaha is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) vaha,
(select first 1 puls from preh where (idpac = anamneza.idpac) and (puls is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) puls,
(select first 1 tlaksys from preh where (idpac = anamneza.idpac) and (tlaksys is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlaksys,
(select first 1 tlakdia from preh where (idpac = anamneza.idpac) and (tlakdia is not null) /*and (datum <= anamneza.datum)*/ order by datum desc, idpre desc) tlakdia,
memporod, mempotrat, meminter, memoper, pm, ID_EDOKUMENT, PRUKAZ from ANAMNEZA  where (IDPAC=4757/* IDPAC */)
ORDER BY DATUM DESC
       , ID DESC

1048	0	select AC.NAZEV,
AV.SVALUE,
AV.BDATA,
AV.NVALUE,
AV.DVALUE,
AF.USERMASK,
AV.TYP
from ANAMVALUES AV
left join ANAMVCFG AC on AC.IDTYPHODN = AV.IDTYPHODN
left join ANAMVFMT AF on AF.IDTYPHODN = AV.IDTYPHODN
where AV.IDPAC=4757/* IDPAC */ and AV.PLATIOD <= '11.12.2014'/* DATUM */ and AKTUAL = 'T'
ORDER BY AF.PORADI ASC
       , AV.DATZAPIS DESC
       , AV.PLATIOD DESC

1049	0	 execute block(IDPAC integer=4757/* IDPAC */, DATUM DATE='21.09.2025'/* DATUM */)
  returns (VALUE_BF varchar(8), VALUE_AF varchar(8), LEK_KOD varchar (8), LEK_NAZ varchar(30))
 as
  declare variable TMPATC varchar(7) = '';
  declare variable TMPSILA varchar(24) = '';
  declare variable RDATUM date;
  declare variable LEKKOD varchar(8)  = '';
  declare variable LEKNAZ varchar(30) = '';
  declare variable HODN_BE varchar(8) = '-1';
  declare variable HODN_AF varchar(8) = '-1';
  begin
  VALUE_BF = '-1';
  VALUE_AF = '-1';
  LEK_KOD = '';
  LEK_NAZ = '';
  select first 1 DATUM, KOD, LEK, ATC
    from RECEPT
  where
    IDPAC = :IDPAC and
    DATUM >= :DATUM and
   (ATC starting with 'C10AA01' or
    ATC starting with 'C10AA05' or
    ATC starting with 'C10AA07')
   order by datum desc
    into :RDATUM, :LEKKOD, :LEKNAZ, :TMPATC;
  if (RDATUM is null) then
    begin
      select first 1 m.DATUM, m.KOD, m.NAZ , l.ATC
        from MEDIKACE m
       join LEKY l on m.kod = l.kod
      where
       m.IDPAC = :IDPAC and
      (m.PLATI_DO >= :DATUM or m.PLATI_DO is null) and
        (l.ATC starting with 'C10AA01' or
         l.ATC starting with 'C10AA05' or
         l.ATC starting with 'C10AA07')
      order by m.DATUM desc
      into :RDATUM, :LEKKOD, :LEKNAZ, :TMPATC;
    end
  if (RDATUM is null) then
    begin
      VALUE_BF = -1;
      VALUE_AF = -1;
      LEK_KOD  = '';
      LEK_NAZ  = '';
      suspend;
      exit;
    end
  if (RDATUM is not null) then
    begin
      begin
      select first 1 VYSL
        from LABVD D
       join LABMETOD M on M.IDMETOD = D.IDMETOD and (M.KLICMZ in ('02322', '02323', '02324', '02325', '03379', '03380'))
       join LABVH H on H.IDVH = D.IDVH
      where D.IDPACIENT = :IDPAC and
            H.DATUM <= :RDATUM
      order by H.DATUM desc, D.ID desc
      into :HODN_BE;
      select STRING_OUT from sp_replace_char(:HODN_BE, ',', '.') into HODN_BE;
      select first 1 VYSL
        from LABVD D
       join LABMETOD M on M.IDMETOD = D.IDMETOD and (M.KLICMZ in ('02322', '02323', '02324', '02325', '03379', '03380'))
       join LABVH H on H.IDVH = D.IDVH
      where D.IDPACIENT = :IDPAC and
            H.DATUM >= :RDATUM
      order by H.DATUM desc, D.ID desc
      into :HODN_AF;
      select STRING_OUT from sp_replace_char(:HODN_AF, ',', '.') into HODN_AF;
     end
     if (((HODN_AF > '-1') and (HODN_AF > '0')) and ((HODN_BE = '-1') or (HODN_BE is null))) then
            begin
                HODN_BE = HODN_AF;
                select first 1 SILA from LEKY where KOD = :LEKKOD and (PLATIDO is null or PLATIDO <= 'TODAY')
                into :TMPSILA;
                if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.28 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.37 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '10') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.46 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.35 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.43 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '20') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.52 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.39 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.48 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '40') and (TMPATC = 'C10AA07')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.55 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '80') and (TMPATC = 'C10AA01')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.46 from 1 for 5);
                else if ((substring(TMPSILA from 1 for 2) = '80') and (TMPATC = 'C10AA05')) then
                  HODN_BE = substring(cast(HODN_BE as float) * 1.51 from 1 for 5);
            end
      end

      begin
        VALUE_BF = :hodn_be;
        VALUE_AF = :hodn_af;
        LEK_KOD  = :lekkod;
        LEK_NAZ  = :leknaz;
        suspend;
      end
end

1050	0	select heslotelkom from KAR where idpac = 4757

1051	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

1052	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'PSA'/* TYP */ and IDPAC = 4757/* IDPAC */
ORDER BY DATUM DESC

1053	0	select K.POHLAVI as POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 KOD from STALDGN where IDPAC = K.IDPAC and IDANAM = (select first 1 ID from ANAMNEZA where IDPAC = K.IDPAC order by DATUM desc, ID desc) and KOD like 'C61%') as DGN, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('01131', '01132', '01133', '01134') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 4757/* IDPAC */

1054	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

1055	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'TOKS'/* TYP */ and IDPAC = 4757/* IDPAC */
ORDER BY DATUM DESC

1056	0	select K.DATNAR as DATNAR, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('15120', '15121') order by DATOSE desc, ID desc) as VYKON from KAR K where K.IDPAC = 4757/* IDPAC */

1057	0	select D.DATOSE from DOKLADD D where D.ID = (select first 1 DD.ID from DOKLADD DD where DD.RODCIS = '7553221918'/* RODCIS */ and DD.KOD in ('15120') order by DD.DATOSE desc)

1058	0	select R.ID from REGISTR R join ICP i on (i.idicp = r.idicp) where (r.idpac = 4757) and not (r.priznak in ('Z','N')) and (i.ICP = '09305001') and (i.ODB = '001') and (r.datum <= '2026-03-20') and (r.datum_zruseni is null or r.datum_zruseni >= '2026-03-20')

1059	0	select DATUM, NEZOBRAZOVAT from ALERT where TYP = 'FRAX'/* TYP */ and IDPAC = 4757/* IDPAC */
ORDER BY DATUM DESC

1060	0	select K.DATNAR, K.POHLAVI, (select ROK from GET_VEK2(K.DATNAR, '20.03.2026'/* DATUM */)) as VEK, (select first 1 DATOSE from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as DATOSE, (select first 1 KOD    from DOKLADD where RODCIS = K.RODCIS and KOD in ('11320', '11321', '11327') order by DATOSE desc, ID desc) as VYKON, (select first 1 "DATA" from GENVYS where IDPAC = 4757/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATA, (select first 1 DATUM  from GENVYS where IDPAC = 4757/* IDPAC */ and TYP = 112/* TYP */ order by DATUM desc, IDPRE desc) as DXADATUM from KAR K where K.IDPAC = 4757/* IDPAC */

1061	0	select D.DATOSE from DOKLADD D where D.ID = (select first 1 DD.ID from DOKLADD DD where DD.RODCIS = '7553221918'/* RODCIS */ and DD.KOD in ('11320', '11321') order by DD.DATOSE desc)

1062	0	select first 1 RPRUKAZ from KAR where IDPAC = 4757

1063	0	select first 1 ZPRUKAZ from KAR where IDPAC = 4757

1064	0	execute procedure sp_log(4757/* idpac */, 10000/* tblid */, 4757/* recid */, 'V', NULL/* rodcis */, NULL/* id1 */, NULL/* detail */)

1065	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

1066	0	execute procedure SP_UPDATE_USER_TIMESTAMP(7846, 6, 2, '//////////////////8=', 'NTBVBHP470G10', '3.61.0.371')

1067	0	select FSDATS from STAV where ID = 7846/* ID */

1068	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */

1069	0	select first 1 * from MEDINETIN I where ((I.STAV <> 1) or (I.STAV is null)) and CGMNUMBER_PRIJEMCE in ('01300149556')

1070	0	select "VALUE" from CLICKDOC where "KEY" = 'system_id'/* "KEY" */
