/** 
 * <feature scope="SanteDB.Persistence.Data.ADO" id="20210628-01" name="Update:20210628-01" applyRange="1.1.0.0-1.2.0.0"  invariantName="npgsql">
 *	<summary>Update: Adds confidence codes for relationships</summary>
 *	<isInstalled>select ck_patch('20210628-01')</isInstalled>
 * </feature>
 */
 BEGIN TRANSACTION;
 INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('B52C7E95-88B8-4C4C-836A-934277AFDB92','d39073be-0f8f-440e-b8c8-7034cc138a95','fafec286-89d5-420b-9085-054aca9d1eef','ADMINISTERABLE MATERIAL') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('B52C7E95-88B8-4C4C-836A-934277AFDB92','d39073be-0f8f-440e-b8c8-7034cc138a95','d39073be-0f8f-440e-b8c8-7034cc138a95','ADMINISTERABLE MATERIAL') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('77B7A04B-C065-4FAF-8EC0-2CDAD4AE372B','9de2a846-ddf2-4ebc-902e-84508c5089ea','7c08bd55-4d42-49cd-92f8-6388d6c4183f','ASSIGNED ENTITY/EMPLOY') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('77B7A04B-C065-4FAF-8EC0-2CDAD4AE372B','6b04fed8-c164-469c-910b-f824c2bda4f0','7c08bd55-4d42-49cd-92f8-6388d6c4183f','ASSIGNED ENTITY/EMPLOY') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('31B0DFCB-D7BA-452A-98B9-45EBCCD30732','bacd9c6f-3fa9-481e-9636-37457962804d','9de2a846-ddf2-4ebc-902e-84508c5089ea','CAREGIVER') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('31B0DFCB-D7BA-452A-98B9-45EBCCD30732','bacd9c6f-3fa9-481e-9636-37457962804d','6b04fed8-c164-469c-910b-f824c2bda4f0','CAREGIVER') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('31B0DFCB-D7BA-452A-98B9-45EBCCD30732','bacd9c6f-3fa9-481e-9636-37457962804d','7c08bd55-4d42-49cd-92f8-6388d6c4183f','CAREGIVER') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('9D256279-F1AC-46B3-A974-DD13E2AD4F72','e29fcfad-ec1d-4c60-a055-039a494248ae','9de2a846-ddf2-4ebc-902e-84508c5089ea','CLAIMANT') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('8FF9D9A5-A206-4566-82CD-67B770D7CE8A','bacd9c6f-3fa9-481e-9636-37457962804d','7c08bd55-4d42-49cd-92f8-6388d6c4183f','COVERAGE SPONSOR') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('8FF9D9A5-A206-4566-82CD-67B770D7CE8A','e29fcfad-ec1d-4c60-a055-039a494248ae','bacd9c6f-3fa9-481e-9636-37457962804d','POLICY COVERED PARTY') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('6B04FED8-C164-469C-910B-F824C2BDA4F0','bacd9c6f-3fa9-481e-9636-37457962804d','7c08bd55-4d42-49cd-92f8-6388d6c4183f','HEALTHCARE PROVIDER') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('6B04FED8-C164-469C-910B-F824C2BDA4F0','bacd9c6f-3fa9-481e-9636-37457962804d','6b04fed8-c164-469c-910b-f824c2bda4f0','HEALTHCARE PROVIDER') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('b1d2148d-bb35-4337-8fe6-021f5a3ac8a3','bacd9c6f-3fa9-481e-9636-37457962804d','6b04fed8-c164-469c-910b-f824c2bda4f0','CONTACT->PROVIDER') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('b1d2148d-bb35-4337-8fe6-021f5a3ac8a3','bacd9c6f-3fa9-481e-9636-37457962804d','9de2a846-ddf2-4ebc-902e-84508c5089ea','CONTACT->PERSON') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('b1d2148d-bb35-4337-8fe6-021f5a3ac8a3','bacd9c6f-3fa9-481e-9636-37457962804d','bacd9c6f-3fa9-481e-9636-37457962804d','CONTACT->PATIENT') ON CONFLICT DO NOTHING;
INSERT INTO ENT_REL_VRFY_CDTBL (REL_TYP_CD_ID, SRC_CLS_CD_ID, TRG_CLS_CD_ID, ERR_DESC) VALUES ('b1d2148d-bb35-4337-8fe6-021f5a3ac8a3','bacd9c6f-3fa9-481e-9636-37457962804d','7c08bd55-4d42-49cd-92f8-6388d6c4183f','CARE GIVER->ORGANIZATION') ON CONFLICT DO NOTHING;

DROP INDEX IF EXISTS SEC_DEV_SCRT_IDX ;

DROP INDEX ENT_ID_ENT_VAL_UQ_IDX;
CREATE UNIQUE INDEX ENT_ID_ENT_VAL_UQ_IDX ON ENT_ID_TBL(ENT_ID, AUT_ID, ID_VAL) WHERE (OBSLT_VRSN_SEQ_ID IS NULL);
-- 
INSERT INTO ENT_REL_VRFY_CDTBL (rel_typ_cd_id , src_cls_cd_id , trg_cls_cd_id , err_desc )
SELECT CD_ID AS REL_TYP_CD_ID, 'BACD9C6F-3FA9-481E-9636-37457962804D','BACD9C6F-3FA9-481E-9636-37457962804D','FAMILY MEMBER PATIENT<>PATIENT'  FROM cd_set_mem_assoc_tbl WHERE SET_ID='D3692F40-1033-48EA-94CB-31FC0F352A4E'
ON CONFLICT DO NOTHING;

-- PORTION
INSERT INTO ent_rel_vrfy_cdtbl (rel_typ_cd_id, src_cls_cd_id, trg_cls_cd_id, err_desc) 
	SELECT 
		'CFF670E4-965E-4288-B966-47A44479D2AD', CD_ID, CD_ID, 'ALIQUOT'
	FROM CD_SET_MEM_ASSOC_TBL WHERE SET_ID = '4E6DA567-0094-4F23-8555-11DA499593AF'
  ON CONFLICT DO NOTHING;


  
CREATE OR REPLACE FUNCTION REG_PATCH(PATCH_ID_IN IN VARCHAR(24)) RETURNS BOOLEAN AS $$
BEGIN
	INSERT INTO PATCH_DB_SYSTBL (PATCH_ID) VALUES (PATCH_ID_IN) ON CONFLICT DO NOTHING;
	RETURN TRUE;
END
$$ LANGUAGE PLPGSQL;
COMMIT;
SELECT REG_PATCH('20210628-01');
