 	RETURN z;
 END;
 $BODY$
-LANGUAGE 'plpgsql' SECURITY DEFINER;
+LANGUAGE 'plpgsql' IMMUTABLE PARALLEL SAFE;
 
 --get unique dose
 CREATE OR REPLACE FUNCTION GetDistinctDose (active_numerator_strength IN VARCHAR, active_ingred_unit IN VARCHAR, p IN INT) RETURNS VARCHAR

	AND crs.valid_end_date <> i.valid_end_date
	AND crs.invalid_reason IS NOT NULL;

--33. Clean up
DROP FUNCTION GetAggrDose (active_numerator_strength IN VARCHAR, active_ingred_unit IN VARCHAR);
DROP FUNCTION GetDistinctDose (active_numerator_strength IN VARCHAR, active_ingred_unit IN VARCHAR, p IN INT);
DROP FUNCTION CheckNDCDate (pDate IN VARCHAR, pDateDefault IN DATE);
DROP TABLE main_ndc;
DROP TABLE rxnorm2ndc_mappings_ext;

-- At the end, the three tables concept_stage, concept_relationship_stage and concept_synonym_stage should be ready to be fed into the generic_update.sql script

	'11-digit NDC' AS concept_class_id,
	NULL AS standard_concept,
	ndc_code AS concept_code,
	FIRST_VALUE(startDate) OVER (
		PARTITION BY ndc_code ORDER BY startDate ROWS BETWEEN UNBOUNDED PRECEDING
				AND UNBOUNDED FOLLOWING
		) AS valid_start_date,
	LAST_VALUE(endDate) OVER (
		PARTITION BY ndc_code ORDER BY endDate ROWS BETWEEN UNBOUNDED PRECEDING
				AND UNBOUNDED FOLLOWING
		) AS valid_end_date,
	LAST_VALUE(invalid_reason) OVER (
		PARTITION BY ndc_code ORDER BY endDate ROWS BETWEEN UNBOUNDED PRECEDING
				AND UNBOUNDED FOLLOWING
		) AS invalid_reason
FROM rxnorm2ndc_mappings_ext m
WHERE NOT EXISTS (
