Of course! This is from a larger query, so excuse the noise. I listed all RxNorm drugs and any ATCs that had a relationship to them. As of now, Iâm getting about a 5% mapping rate. My goal in using ATCs is to form a hierarchy of sorts, for instance all drugs that serve the nervous system have a flag that indicates that.
WITH ATC_CODE AS
(
SELECT
atc_cr.SRC_CONCEPT_ID_1 AS SRC_ATC_CONCEPT_ID
, atc_con.SRC_CONCEPT_NAME AS SRC_ATC_CONCEPT_NAME
, atc_cr.SRC_RELATIONSHIP_ID AS SRC_RELATIONSHIP_ID
, atc_con.SRC_CONCEPT_CODE AS SRC_ATC_CODE
, atc_cr.SRC_CONCEPT_ID_2 AS SRC_MAPPED_CONCEPT_ID
, atc_con2.SRC_CONCEPT_NAME AS SRC_MAPPED_CONCEPT_NAME
, atc_con2.SRC_CONCEPT_CODE AS SRC_MAPPED_CONCEPT_CODE
, atc_con.SRC_CONCEPT_CLASS_ID
âAggregates all ATCs that map to an RxNorm concept
, LISTAGG(âSRC_ATC_CODEâ, ', ') WITHIN GROUP (ORDER BY âSRC_ATC_CODEâ)
OVER (PARTITION BY âSRC_MAPPED_CONCEPT_IDâ, âSRC_MAPPED_CONCEPT_NAMEâ) AS SRC_ALL_ATCs
âChecks for any cartesians
, ROW_NUMBER() OVER (PARTITION BY SRC_MAPPED_CONCEPT_ID
ORDER BY SRC_MAPPED_CONCEPT_ID, SRC_MAPPED_CONCEPT_ID) AS ROW_NUMBER_COUNTER_ATC
FROM
CONCEPT_RELATIONSHIP atc_cr
LEFT OUTER JOIN CONCEPT atc_con
ON atc_con.SRC_CONCEPT_ID = atc_cr.SRC_CONCEPT_ID_1
LEFT OUTER JOIN
CONCEPT atc_con2
ON atc_con2.SRC_CONCEPT_ID = atc_cr.SRC_CONCEPT_ID_2
WHERE atc_con.SRC_DOMAIN_ID = âDrugâ
AND atc_con.SRC_VOCABULARY_ID ILIKE â%ATC%â
QUALIFY ROW_NUMBER_COUNTER_ATC = 1
)
SELECT
rx_superset.SRC_concept_name_RxNorm
, rx_superset.SRC_CONCEPT_ID_RXNORM
, rx_superset.SRC_CONCEPT_CLASS_ID_RxNorm
, rx_superset.SRC_CONCEPT_CODE
, rx_superset.SRC_VALID_START_DATE
, rx_superset.SRC_VALID_END_DATE
, rx_superset.SRC_STANDARD_CONCEPT
âAdding ATC codes from ATC_CODE
, ATC_CODE.SRC_ALL_ATCs
FROM
(
SELECT
rx_co.SRC_CONCEPT_ID AS SRC_CONCEPT_ID_RxNorm
, rx_co.SRC_CONCEPT_NAME AS SRC_CONCEPT_NAME_RxNorm
, rx_co.SRC_CONCEPT_CLASS_ID AS SRC_CONCEPT_CLASS_ID_RxNorm
, rx_co.SRC_VOCABULARY_ID
, rx_co.SRC_CONCEPT_CODE
, rx_co.SRC_VALID_START_DATE
, rx_co.SRC_VALID_END_DATE
, rx_co.SRC_STANDARD_CONCEPT
FROM
SPARKSOFT_DATA_SHARE.PUBLISHED_WEB.CONCEPT rx_co
WHERE
rx_co.SRC_VOCABULARY_ID = âRxNormâ
UNION
SELECT
rxe_co.SRC_CONCEPT_ID AS SRC_CONCEPT_ID_RxNorm
, rxe_co.SRC_CONCEPT_NAME AS SRC_CONCEPT_NAME_RxNorm
, rxe_co.SRC_CONCEPT_CLASS_ID AS SRC_CONCEPT_CLASS_ID_RxNorm
, rxe_co.SRC_VOCABULARY_ID
, rxe_co.SRC_CONCEPT_CODE
, rxe_co.SRC_VALID_START_DATE
, rxe_co.SRC_VALID_END_DATE
, rxe_co.SRC_STANDARD_CONCEPT
FROM
SPARKSOFT_DATA_SHARE.PUBLISHED_WEB.CONCEPT rxe_co
WHERE
rxe_co.SRC_VOCABULARY_ID = âRxNorm Extensionâ
)rx_superset
LEFT OUTER JOIN
ATC_CODE
ON rx_superset.SRC_CONCEPT_ID_RXNORM = ATC_CODE.SRC_MAPPED_CONCEPT_ID