Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split FDA strengths into their own rows #64

Closed
jrlegrand opened this issue Jan 6, 2022 · 2 comments · Fixed by #65
Closed

Split FDA strengths into their own rows #64

jrlegrand opened this issue Jan 6, 2022 · 2 comments · Fixed by #65

Comments

@jrlegrand
Copy link
Member

Problem Statement

FDA has better human-understandable strengths than RxNorm at an NDC level.

example:
FDA infant's ibuprofen = 50 mg / 1.25 mL
RxNorm for same thing = 40 mg / 1 mL

Criteria for Success

Split the 3 columns below by semicolon and put them in their own table(s) that can link back to the original NDC product/package. Ideally, it would be one table with a column for product_id, substance_name, strength_numerator, strength_denominator - as opposed to like 3 separate tables for all that info. But not sure what is technically possible with unnest.

image

Additional Information

Should be similar to the fda_class work.

@jrlegrand
Copy link
Member Author

I think this works... putting here for @Bridg109 to review...

SELECT
	substance.productid
	, substance.rn AS line
	, substance.token AS substancename
	, strength.token AS active_numerator_strength
	, unit.token AS active_ingred_unit
FROM (
	SELECT DISTINCT
		prod.productid
		, ROW_NUMBER() OVER (PARTITION BY prod.productid) AS rn
		, arr.token
	FROM datasource.fda_ndc_product prod
	, UNNEST(string_to_array(prod.substancename, '; ')) arr(token)
) substance
LEFT JOIN (
	SELECT DISTINCT
		prod.productid
		, ROW_NUMBER() OVER (PARTITION BY prod.productid) AS rn
		, arr.token
	FROM datasource.fda_ndc_product prod
	, UNNEST(string_to_array(prod.active_numerator_strength, '; ')) arr(token)
) strength ON substance.productid = strength.productid AND substance.rn = strength.rn
LEFT JOIN (
	SELECT DISTINCT
		prod.productid
		, ROW_NUMBER() OVER (PARTITION BY prod.productid) AS rn
		, arr.token
	FROM datasource.fda_ndc_product prod
	, UNNEST(string_to_array(prod.active_ingred_unit, '; ')) arr(token)
) unit ON substance.productid = unit.productid AND substance.rn = unit.rn;

@Bridg109
Copy link
Collaborator

Bridg109 commented Jan 7, 2022

You can unnest() multiple arrays in parellel

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants