 				'BioCondition'
 				)
 			THEN 'Condition'
+		WHEN h.concept_class_id IN (
+				'Regimen',
+				'Modality'
+				)
+			THEN 'Regimen' --https://github.com/OHDSI/OncologyWG/issues/69
 		ELSE 'Undefined'
 		END AS domain_id,
 	h.vocabulary_id,
+	h.concept_class_id,
 	CASE 
-		WHEN h.concept_class_id = 'Brand_Name'
-			THEN 'Brand Name'
-		ELSE h.concept_class_id
-		END AS concept_class_id,
-	CASE 
-		WHEN h.concept_class_id = 'Component Class'
-			THEN 'C'
+		WHEN h.concept_class_id = 'Condition Class'
+			THEN 'C' -- let's make them classification concepts (in previos version Component Class was assigned manually, Jeremy fixed it in the 30-Aug-2019 release)
+		WHEN concept_class_id = 'Modality'
+			THEN 'S' -- can be used as a generic Regimen when we don't know what exact Chemo or Hormonotherapy patient got
 		ELSE h.standard_concept
 		END AS standard_concept,
 	h.concept_code,
 	h.valid_start_date,
 	h.valid_end_date,
-	NULL AS invalid_reason --fix when new release comes up
+	h.invalid_reason
 FROM sources.hemonc_cs h
 WHERE h.concept_class_id IN (
 		'Regimen type', -- type

		'Component', -- ingredient, Standard if there's no equivalent in Rx, RxE
		'Context', -- therapy intent or line or other Context, STANDARD
		'Regimen', -- Standard
		'Brand_Name', -- need to map to RxNorm, RxNorm Extension if possible, if not - leave it as is
		'Route',
		'Procedure'
		)
	AND h.concept_name IS NOT NULL;

--4. Create concept_relationship_stage
INSERT INTO concept_relationship_stage
SELECT DISTINCT concept_id_1,
	concept_id_2,
	concept_code_1,
	concept_code_2,
	vocabulary_id_1,
	vocabulary_id_2,
	CASE 
		WHEN relationship_id = 'Has Route'
			THEN 'May have route'
		ELSE
			--relationship_ids have this structure "First word only is initcap"
			REPLACE(UPPER(SUBSTRING(LOWER(relationship_id) FROM 1 FOR 1)) || SUBSTRING(LOWER(relationship_id) FROM 2), ' rx', ' Rx')
		END AS relationship_id,
	r.valid_start_date,
	CASE 
		WHEN r.invalid_reason = 'NA'
			THEN TO_DATE('20991231', 'yyyymmdd')
		ELSE r.valid_end_date
		END AS valid_end_date,
	CASE 
		WHEN r.invalid_reason = 'NA'
			THEN NULL
		ELSE r.invalid_reason
		END AS invalid_reason
FROM sources.hemonc_crs r
LEFT JOIN concept c1 ON c1.concept_code = r.concept_code_1
	AND c1.vocabulary_id = r.vocabulary_id_1
LEFT JOIN concept_stage cs1 ON cs1.concept_code = r.concept_code_1
	AND cs1.vocabulary_id = r.vocabulary_id_1
LEFT JOIN concept c2 ON c2.concept_code = r.concept_code_2
	AND c2.vocabulary_id = r.vocabulary_id_2
LEFT JOIN concept_stage cs2 ON cs2.concept_code = r.concept_code_2
	AND cs2.vocabulary_id = r.vocabulary_id_2
WHERE r.relationship_id NOT IN (
		'Has Been Compared To',
		'Can Be Preceded By',
		'Can Be Followed By'
		)
	AND NOT (
		r.concept_code_1 = '37'
		AND r.concept_code_2 = '225741'
		AND r.relationship_id = 'Maps to'
		)
	AND NOT (
		c1.concept_code IS NULL
		AND cs1.concept_code IS NULL
		)
	AND NOT (
		c2.concept_code IS NULL
		AND cs2.concept_code IS NULL
		);


--10. To build hierarchy relationships from RxNorm (E) concepts
INSERT INTO concept_relationship_stage
SELECT DISTINCT --results in  Duplications, which should be fine as we can have different ways to go through
	NULL::int4 AS concept_id_1,
	NULL::int4 AS concept_id_2,
	rb.concept_code_2,
	ra.concept_code_2,
	rb.vocabulary_id_2,
	ra.vocabulary_id_2,
	'Subsumes' AS relationship_id,
	ra.valid_start_date,
	ra.valid_end_date,
	ra.invalid_reason
