delete from pharm.T_BARCODE_TEMPLATE_ATTRIBUTE where BarcodeTemplate = 'A53669FC-635C-4443-AF18-7581DBB86954'
DELETE FROM PHARM.T_BARCODE_TEMPLATE WHERE BarcodeTemplateID = 'A53669FC-635C-4443-AF18-7581DBB86954'

DECLARE @type int, @id uniqueidentifier
SELECT @type = e.EntityId from VCLib.T_ENTITIES e 
WHERE e.EntName = 'RECIPE_GENERAL'
set @id = NEWID()

update [PHARM].[T_BARCODE_TEMPLATE] set [Entity] = @type

ALTER TABLE [PHARM].[T_BARCODE_TEMPLATE] ALTER COLUMN [Entity] int NOT NULL

INSERT INTO PHARM.T_BARCODE_TEMPLATE(BarcodeTemplateID, Entity, TemplateName, BeginDate, [Version]) 
VALUES (@id, @type, 'Спецификация штрих-кода по ЛЛО рецептам 102', '20230101', 102)

INSERT INTO PHARM.T_BARCODE_TEMPLATE_ATTRIBUTE (BarcodeTemplateAttributeID, BarcodeTemplate, [Order], [Size], Description, LexemPathLink, ValueType) 
VALUES (NEWID(), @id, 0, 160, 'Код врача', '<lx:SubString xmlns:lx="lexem"><lx:PadRight><lx:Path OwnerQueryLevel="0"><lx:StepString name="Post" /><lx:StepString name="Code" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">7</lx:ConstOperand></lx:PadRight><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">7</lx:ConstOperand></lx:SubString>', 2),
	   (NEWID(), @id, 1, 56, 'Код МО', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Post" /><lx:StepString name="Division" /><lx:StepString name="Branch" /><lx:StepString name="LpuSettings" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.LPU_SETTINGS" isNull="1" /></lx:Criterion></When><Then><lx:PadRight><lx:Path OwnerQueryLevel="0"><lx:StepString name="Post" /><lx:StepString name="Division" /><lx:StepString name="Branch" /><lx:StepString name="BranchCode" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">4</lx:ConstOperand></lx:PadRight></Then><Else><lx:PadRight><lx:Path OwnerQueryLevel="0"><lx:StepString name="Post" /><lx:StepString name="Division" /><lx:StepString name="Branch" /><lx:StepString name="LpuMain" /><lx:StepString name="Code" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">4</lx:ConstOperand></lx:PadRight></Else></lx:Case>', 2),
	   (NEWID(), @id, 2, 88, 'Серия рецепта', '<lx:PadRight xmlns:lx="lexem"><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="Serial" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">11</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">11</lx:ConstOperand></lx:PadRight>', 2),
	   (NEWID(), @id, 3, 64, 'Номер рецепта', '<lx:Path OwnerQueryLevel="0" xmlns:lx="lexem"><lx:StepString name="Number" /></lx:Path>', 1),
	   (NEWID(), @id, 4, 64, 'Код заболевания (по МКБ-10)', '<lx:PadRight xmlns:lx="lexem"><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="MKBCode" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">8</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">8</lx:ConstOperand></lx:PadRight>', 2),
	   (NEWID(), @id, 5, 5, 'Тип льготы', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Benefits" /><lx:StepString name="BenefitViews" /><lx:StepString name="Code" /></lx:Path><lx:ConstOperand isNull="1" /></lx:Criterion></When><Then><lx:Path OwnerQueryLevel="0"><lx:StepString name="Benefits" /><lx:StepString name="BenefitViews" /><lx:StepString name="Code" /></lx:Path></Then><Else><lx:ConstOperand isNull="1" /></Else></lx:Case>', 0),
	   (NEWID(), @id, 6, 24, 'Код льготы', '<lx:PadRight xmlns:lx="lexem"><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="Benefits" /><lx:StepString name="BenefitCode" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">3</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">3</lx:ConstOperand></lx:PadRight>', 2),
	   (NEWID(), @id, 7, 1, 'Признак МНН(0)/ТоргНаим(1)', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="CMnn" /></lx:Path><lx:BaseObjectOperand Entity="PHARM.C_MNN" isNull="1" /></lx:Criterion></When><Then><lx:ConstOperand type="Int32">0</lx:ConstOperand></Then><Else><lx:ConstOperand type="Int32">1</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 8, 44, 'Код МНН/ТоргНаим', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="CTrn" /></lx:Path><lx:BaseObjectOperand Entity="PHARM.C_TRN" isNull="1" /></lx:Criterion></When><Then><lx:Path OwnerQueryLevel="0"><lx:StepString name="CTrn" /><lx:StepString name="OtherID" /></lx:Path></Then><Else><lx:Path OwnerQueryLevel="0"><lx:StepString name="CMnn" /><lx:StepString name="OtherID" /></lx:Path></Else></lx:Case>', 1),
	   (NEWID(), @id, 9, 37, 'СНИЛС', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="SNILS" /></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:ConstOperand type="Int32">0</lx:ConstOperand></Then><Else><lx:Replace><lx:Replace><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="SNILS" /><lx:StepString name="SnilsID" /></lx:Path><lx:ConstOperand type="String"><![CDATA[-]]></lx:ConstOperand><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></lx:Replace><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></lx:Replace></Else></lx:Case>', 1),
	   (NEWID(), @id, 10, 160, 'Дозировка', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="DoseView" /></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:Case><When><lx:Criterion type="&lt;"><lx:StringLen><lx:Path OwnerQueryLevel="0"><lx:StepString name="DoseView" /></lx:Path></lx:StringLen><lx:ConstOperand type="Int32">20</lx:ConstOperand></lx:Criterion></When><Then><lx:PadRight><lx:Path OwnerQueryLevel="0"><lx:StepString name="DoseView" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">20</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 11, 16, 'Лекарственная форма', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="MedicationForms" /></lx:Path><lx:BaseObjectOperand Entity="PHARM.MEDICATION_FORMS" isNull="1" /></lx:Criterion></When><Then><lx:Path OwnerQueryLevel="0"><lx:StepString name="MedicationForms" /><lx:StepString name="Code" /></lx:Path></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 12, 24, 'Количество единиц', '<lx:MathOperator sign="*" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0"><lx:StepString name="UnitsCount" /></lx:Path><lx:ConstOperand type="Int32">1000</lx:ConstOperand></lx:MathOperator>', 0),
	   (NEWID(), @id, 13, 10, 'Код категории гражданина', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Benefits" /><lx:StepString name="BenefitCode" /></lx:Path><lx:ConstOperand isNull="1" /></lx:Criterion></When><Then><lx:Path OwnerQueryLevel="0"><lx:StepString name="Benefits" /><lx:StepString name="BenefitCode" /></lx:Path></Then><Else><lx:ConstOperand isNull="1" /></Else></lx:Case>', 0),
	   (NEWID(), @id, 14, 1, 'Пол (0-женский, 1-мужской)', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="Sex" /></lx:Path><lx:EnumOperand EnumType="Sex" type="Int32" PrimaryKey="10301"><Name><![CDATA[мужской]]></Name></lx:EnumOperand></lx:Criterion></When><Then><lx:ConstOperand type="Int32">1</lx:ConstOperand></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 15, 7, 'Дата выписки рецепта: год', '<lx:SubString xmlns:lx="lexem"><lx:Cast type="String"><lx:DatePart datepart="Year"><lx:Path OwnerQueryLevel="0"><lx:StepString name="RecipeDate" /></lx:Path></lx:DatePart></lx:Cast><lx:ConstOperand type="Int32">2</lx:ConstOperand><lx:ConstOperand type="Int32">2</lx:ConstOperand></lx:SubString>', 0),
	   (NEWID(), @id, 16, 4, 'Дата выписки рецепта: месяц', '<lx:DatePart datepart="Month" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0"><lx:StepString name="RecipeDate" /></lx:Path></lx:DatePart>', 0),
	   (NEWID(), @id, 17, 5, 'Дата выписки рецепта: день', '<lx:DatePart datepart="Day" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0"><lx:StepString name="RecipeDate" /></lx:Path></lx:DatePart>', 0),
	   (NEWID(), @id, 18, 1, 'Признак наличия протокола ВК', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="ProtokolKek" /></lx:Path><lx:ConstOperand type="Boolean">True</lx:ConstOperand></lx:Criterion></When><Then><lx:ConstOperand type="Int32">1</lx:ConstOperand></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 19, 136, 'Код КЛАДР', '<lx:Case xmlns:lx="lexem"><When><lx:Criteria type="And"><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Street" /></lx:Path><lx:Null /></lx:Criterion><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Street" /><lx:StepString name="Code" /></lx:Path><lx:Null /></lx:Criterion></lx:Criteria></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Street" /><lx:StepString name="Code" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">17</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">17</lx:ConstOperand></lx:PadRight></Then><When><lx:Criteria type="And"><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="District" /></lx:Path><lx:Null /></lx:Criterion><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="District" /><lx:StepString name="Code" /></lx:Path><lx:Null /></lx:Criterion></lx:Criteria></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Street" /><lx:StepString name="District" /><lx:StepString name="Code" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">17</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">17</lx:ConstOperand></lx:PadRight></Then><When><lx:Criteria type="And"><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="City" /></lx:Path><lx:Null /></lx:Criterion><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="City" /><lx:StepString name="Code" /></lx:Path><lx:Null /></lx:Criterion></lx:Criteria></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="City" /><lx:StepString name="Code" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">17</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">17</lx:ConstOperand></lx:PadRight></Then><Else><lx:Null /></Else></lx:Case>', 2),
	   (NEWID(), @id, 20, 64, 'Дом', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="House" /></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="House" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">8</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">8</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 21, 32, 'Корпус', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Block" /></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Block" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">4</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">4</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 22, 32, 'Квартира', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Flat" /></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="AddressReal" /><lx:StepString name="Flat" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">4</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">4</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 23, 320, 'Фамилия', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:StringLen><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="LastName" /></lx:Path></lx:StringLen><lx:ConstOperand isNull="1" /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="LastName" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">40</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">40</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 24, 320, 'Имя', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:StringLen><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="FirstName" /></lx:Path></lx:StringLen><lx:Null /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="FirstName" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">40</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">40</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 25, 320, 'Отчество', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:StringLen><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="FatherName" /></lx:Path></lx:StringLen><lx:Null /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="FatherName" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">40</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">40</lx:ConstOperand></lx:PadRight></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 26, 7, 'Дата рождения: год', '<lx:SubString xmlns:lx="lexem"><lx:Cast type="String"><lx:DatePart datepart="Year"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="Birthday" /></lx:Path></lx:DatePart></lx:Cast><lx:ConstOperand type="Int32">2</lx:ConstOperand><lx:ConstOperand type="Int32">2</lx:ConstOperand></lx:SubString>', 0),
	   (NEWID(), @id, 27, 4, 'Дата рождения: месяц', '<lx:DatePart datepart="Month" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="Birthday" /></lx:Path></lx:DatePart>', 0),
	   (NEWID(), @id, 28, 5, 'Дата рождения: день', '<lx:DatePart datepart="Day" xmlns:lx="lexem"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="Birthday" /></lx:Path></lx:DatePart>', 0),
	   (NEWID(), @id, 29, 3, 'Срок действия рецепта: ‘1’- 1 месяц,   ‘2’- 10 дней, ‘3’- 3 месяца, ‘4’- 5 дней', '<lx:Case xmlns:lx="lexem"><When><lx:Criteria type="Or"><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Period" /></lx:Path><lx:ChoiceOperand Entity="AKUZ.RECIPE_GENERAL" AttributeName="Period" type="Int32" PrimaryKey="0" /></lx:Criterion><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Period" /></lx:Path><lx:ChoiceOperand Entity="AKUZ.RECIPE_GENERAL" AttributeName="Period" type="Int32" PrimaryKey="1" /></lx:Criterion></lx:Criteria></When><Then><lx:ConstOperand type="Int32">1</lx:ConstOperand></Then><When><lx:Criteria type="Or"><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Period" /></lx:Path><lx:ChoiceOperand Entity="AKUZ.RECIPE_GENERAL" AttributeName="Period" type="Int32" PrimaryKey="4" /></lx:Criterion><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Period" /></lx:Path><lx:ChoiceOperand Entity="AKUZ.RECIPE_GENERAL" AttributeName="Period" type="Int32" PrimaryKey="5" /></lx:Criterion></lx:Criteria></When><Then><lx:ConstOperand type="Int32">2</lx:ConstOperand></Then><When><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Period" /></lx:Path><lx:ChoiceOperand Entity="AKUZ.RECIPE_GENERAL" AttributeName="Period" type="Int32" PrimaryKey="2" /></lx:Criterion></When><Then><lx:ConstOperand type="Int32">3</lx:ConstOperand></Then><When><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="Period" /></lx:Path><lx:ChoiceOperand Entity="AKUZ.RECIPE_GENERAL" AttributeName="Period" type="Int32" PrimaryKey="3" /></lx:Criterion></When><Then><lx:ConstOperand type="Int32">4</lx:ConstOperand></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 30, 128, 'Полис ОМС', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:Case><When><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="PolicyForm" /></lx:Path><lx:ConstOperand type="Int32">1</lx:ConstOperand></lx:Criterion></When><Then><lx:Case><When><lx:Criterion type="&gt;"><lx:StringLen><lx:MathOperator sign="+"><lx:MathOperator sign="+"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Serial" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand></lx:MathOperator><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Number" /></lx:Path></lx:MathOperator></lx:StringLen><lx:ConstOperand type="Int32">16</lx:ConstOperand></lx:Criterion></When><Then><lx:SubString><lx:MathOperator sign="+"><lx:MathOperator sign="+"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Serial" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand></lx:MathOperator><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Number" /></lx:Path></lx:MathOperator><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">16</lx:ConstOperand></lx:SubString></Then><Else><lx:PadRight><lx:MathOperator sign="+"><lx:MathOperator sign="+"><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Serial" /></lx:Path><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand></lx:MathOperator><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Number" /></lx:Path></lx:MathOperator><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">16</lx:ConstOperand></lx:PadRight></Else></lx:Case></Then><Else><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="OmsPolicy"><lx:ParamHolder><lx:StepString name="CURRENT_DATE" /></lx:ParamHolder></lx:StepString><lx:StepString name="Number" /></lx:Path></Else></lx:Case></Then><Else><lx:ConstOperand type="String"><![CDATA[]]></lx:ConstOperand></Else></lx:Case>', 2),
	   (NEWID(), @id, 31, 80, 'Номер справки', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:Null /></lx:Criterion></When><Then><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="Number" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">10</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">10</lx:ConstOperand></lx:PadRight></Then><Else><lx:Null /></Else></lx:Case>', 2),
	   (NEWID(), @id, 32, 7, 'Дата с: год', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.PATIENT_REFERENCE" isNull="1" /></lx:Criterion></When><Then><lx:SubString><lx:Cast type="String"><lx:DatePart datepart="Year"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateBegin" /></lx:Path></lx:DatePart></lx:Cast><lx:ConstOperand type="Int32">2</lx:ConstOperand><lx:ConstOperand type="Int32">2</lx:ConstOperand></lx:SubString></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 33, 4, 'Дата с: месяц', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.PATIENT_REFERENCE" isNull="1" /></lx:Criterion></When><Then><lx:DatePart datepart="Month"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateBegin" /></lx:Path></lx:DatePart></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 34, 5, 'Дата с: день', '<lx:Case xmlns:lx="lexem"><When><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.PATIENT_REFERENCE" isNull="1" /></lx:Criterion></When><Then><lx:DatePart datepart="Day"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateBegin" /></lx:Path></lx:DatePart></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 35, 7, 'Дата по: год', '<lx:Case xmlns:lx="lexem"><When><lx:Criteria type="And"><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.PATIENT_REFERENCE" isNull="1" /></lx:Criterion><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateEnd" /></lx:Path><lx:ConstOperand isNull="1" /></lx:Criterion></lx:Criteria></When><Then><lx:SubString><lx:Cast type="String"><lx:DatePart datepart="Year"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateEnd" /></lx:Path></lx:DatePart></lx:Cast><lx:ConstOperand type="Int32">2</lx:ConstOperand><lx:ConstOperand type="Int32">2</lx:ConstOperand></lx:SubString></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 36, 4, 'Дата по: месяц', '<lx:Case xmlns:lx="lexem"><When><lx:Criteria type="And"><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.PATIENT_REFERENCE" isNull="1" /></lx:Criterion><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateEnd" /></lx:Path><lx:ConstOperand isNull="1" /></lx:Criterion></lx:Criteria></When><Then><lx:DatePart datepart="Month"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateEnd" /></lx:Path></lx:DatePart></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 37, 5, 'Дата по: день', '<lx:Case xmlns:lx="lexem"><When><lx:Criteria type="And"><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /></lx:Path><lx:BaseObjectOperand Entity="AKUZ.PATIENT_REFERENCE" isNull="1" /></lx:Criterion><lx:Criterion not="1" type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateEnd" /></lx:Path><lx:ConstOperand isNull="1" /></lx:Criterion></lx:Criteria></When><Then><lx:DatePart datepart="Day"><lx:Path OwnerQueryLevel="0"><lx:StepString name="PatientReference" /><lx:StepString name="DateEnd" /></lx:Path></lx:DatePart></Then><Else><lx:ConstOperand type="Int32">0</lx:ConstOperand></Else></lx:Case>', 0),
	   (NEWID(), @id, 38, 128, 'Телефон', '<lx:ChildCount xmlns:lx="lexem"><condition><lx:Criteria type="And"><lx:Criterion type="="><lx:Path OwnerQueryLevel="0"><lx:StepString name="PhoneType" /></lx:Path><lx:ConstOperand type="Int32">3</lx:ConstOperand></lx:Criterion><lx:Criterion type="&lt;&gt;"><lx:Path OwnerQueryLevel="0"><lx:StepString name="Number" /></lx:Path><lx:Null /></lx:Criterion></lx:Criteria></condition><lx:Path OwnerQueryLevel="0"><lx:StepString name="AmbulanceCard" /><lx:StepString name="Patient" /><lx:StepString name="PhoneNumbers" /></lx:Path><lx:First><lx:PadRight><lx:SubString><lx:Path OwnerQueryLevel="0"><lx:StepString name="Number" /></lx:Path><lx:ConstOperand type="Int32">0</lx:ConstOperand><lx:ConstOperand type="Int32">16</lx:ConstOperand></lx:SubString><lx:ConstOperand type="String"><![CDATA[ ]]></lx:ConstOperand><lx:ConstOperand type="Int32">16</lx:ConstOperand></lx:PadRight></lx:First><lx:Path OwnerQueryLevel="0"><lx:StepString name="AddedDate" /></lx:Path><lx:ConstOperand type="String"><![CDATA[asc]]></lx:ConstOperand></lx:ChildCount>', 2),
	   (NEWID(), @id, 39, 2, 'Дополнение нулями объединенной последовательности бит до кратности 8', '<lx:ConstOperand type="Int32" xmlns:lx="lexem">0</lx:ConstOperand>', 0),
	   (NEWID(), @id, 40, 8, 'Версия = 102', '<lx:ConstOperand type="Int32" xmlns:lx="lexem">102</lx:ConstOperand>', 0)