 				[4] AS resulted_on
 			FROM
 			(
+				-- Grab resulted on date
 				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], CONVERT(VARCHAR, res_dt.value_date_time, 101) AS [value_short_text],
 					4 AS RowNum
 				FROM  [mhgr_eav].[dbo].[result_entities] features
 				INNER JOIN  [mhgr_eav].[dbo].[result_entities] vcf ON vcf.id = features.parent_id
 					AND vcf.attribute_id = 103		-- VCF result
 				INNER JOIN  [mhgr_eav].[dbo].[result_entities] res_dt ON res_dt.parent_id = vcf.id 
-					AND res_dt.attribute_id = 72 -- Reference bases
-				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
-				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
-					AND ar.relationship_id = 5			-- Variant of gene
+					AND res_dt.attribute_id = 72	-- Reference bases
+				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
+				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
+					AND ar.relationship_id = 5		-- Variant of gene
 					AND ar.attribute2_id IN (34, 35)    -- F2, F5
 				INNER JOIN [mhgr_eav].[dbo].[patients] p ON p.id = features.patient_id
 
 				UNION ALL
 
+				-- Grab reference bases
 				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], refs.value_short_text,
 					3 AS RowNum
 				FROM  [mhgr_eav].[dbo].[result_entities] features
 				INNER JOIN  [mhgr_eav].[dbo].[result_entities] refs ON refs.parent_id = features.id 
-					AND refs.attribute_id = 115 -- Reference bases
-				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
-				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
-					AND ar.relationship_id = 5     -- Variant of gene
+					AND refs.attribute_id = 115		-- Reference bases
+				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
+				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
+					AND ar.relationship_id = 5		-- Variant of gene
 					AND ar.attribute2_id IN (34, 35)    -- F2, F5
 				WHERE features.attribute_id = 114   -- VCF Feature
 
 				UNION ALL
 
 				-- Grab vcf features, features have children specific SNPs, which have children SNP allele attributes
-				-- Limit this to just SNPs that are under CYP2C19
+				-- Limit this to just SNPs that are under F2 or F5 genes
 				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], alleles.value_short_text,
 					ROW_NUMBER() OVER (PARTITION BY snps.id, snps.attribute_id ORDER BY features.patient_id, snps.attribute_id) AS RowNum
 				FROM  [mhgr_eav].[dbo].[result_entities] features
 				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id 
 				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON ar.attribute1_id = snps.attribute_id
-					AND ar.relationship_id = 5     -- Variant of gene
+					AND ar.relationship_id = 5		-- Variant of gene
 					AND ar.attribute2_id IN (34, 35)    -- F2, F5
 				INNER JOIN  [mhgr_eav].[dbo].[result_entities] alleles ON alleles.parent_id = snps.id
-					AND alleles.attribute_id = 128 -- SNP allele
-				WHERE features.attribute_id = 114   -- VCF Feature
+					AND alleles.attribute_id = 128	-- SNP allele
+				WHERE features.attribute_id = 114	-- VCF Feature
 			) a
 			PIVOT ( MAX(value_short_text) FOR RowNum IN ([1], [2], [3], [4]) ) AS pvt
 		) v

			[resulted_on]
		FROM
			(
				SELECT id,
				patient_id,
				snp_id,
				[1] AS value1,

				[4] AS resulted_on
			FROM
			(
				-- Grab the resulted on date
				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], CONVERT(VARCHAR, res_dt.value_date_time, 101) AS [value_short_text],
					4 AS RowNum
				FROM  [mhgr_eav].[dbo].[result_entities] features
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] gvf ON gvf.id = features.parent_id
					AND gvf.attribute_id = 74		-- GVF result
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] res_dt ON res_dt.parent_id = gvf.id 
					AND res_dt.attribute_id = 72	-- Reference bases
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5		-- Variant of gene
					AND ar.attribute2_id IN (36, 37, 38, 39)	-- MYH7, TNNT2, TPM1, MYBPC3
				INNER JOIN [mhgr_eav].[dbo].[patients] p ON p.id = features.patient_id

				UNION ALL

				-- Grab the reference bases
				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], refs.value_short_text,
					3 AS RowNum
				FROM  [mhgr_eav].[dbo].[result_entities] features
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] refs ON refs.parent_id = features.id 
					AND refs.attribute_id = 100		-- Reference bases
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id
				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON snps.attribute_id = ar.attribute1_id
					AND ar.relationship_id = 5		-- Variant of gene
					AND ar.attribute2_id IN (36, 37, 38, 39)	-- MYH7, TNNT2, TPM1, MYBPC3
				WHERE features.attribute_id = 96	-- GVF Feature

				UNION ALL

				-- Grab GVF features, features have children specific SNPs, which have children SNP allele attributes
				-- Limit this to just SNPs that are under MYH7, TNNT2, TPM1, MYBPC3
				SELECT features.patient_id, features.id, snps.attribute_id AS [snp_id], alleles.value_short_text,
					ROW_NUMBER() OVER (PARTITION BY snps.id, snps.attribute_id ORDER BY features.patient_id, snps.attribute_id) AS RowNum
				FROM  [mhgr_eav].[dbo].[result_entities] features
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] snps ON snps.parent_id = features.id 
				INNER JOIN  [mhgr_eav].[dbo].[attribute_relationships] ar ON ar.attribute1_id = snps.attribute_id
					AND ar.relationship_id = 5		-- Variant of gene
					AND ar.attribute2_id IN (36, 37, 38, 39)	-- MYH7, TNNT2, TPM1, MYBPC3
				INNER JOIN  [mhgr_eav].[dbo].[result_entities] alleles ON alleles.parent_id = snps.id
					AND alleles.attribute_id = 128	-- SNP allele
				WHERE features.attribute_id = 96	-- GVF Feature
			) a
			PIVOT ( MAX(value_short_text) FOR RowNum IN ([1], [2], [3], [4]) ) AS pvt
		) v
