Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Margaret
Creator II
Creator II

Opioids prescribed per Emergency Department visit

I need to calculate the rate at which various providers prescribe controlled substances:

For each provider: Count(Rx)  /  Count(Visits)  

Sometimes a provider prescribes a medication to a patient they aren't assigned to.

Sometimes more than one provider is assigned to a single patient.

Here are the two tables I have:   

Account NumberRx ProviderMedicationRx ID
12667Brown, PAHYDROmorphone HCL15213627357
12667Brown, PAHYDROmorphone HCL15233728439
12667Dr. McDonaldfentaNYL15182933689-2
12667Dr. McDonaldHYDROCO37|Hydrocodone15194001371
12667Dr. McDonaldHYDROCOD/APAP 5/325 15193742325
12667Dr. McDonaldHYDROmorphone HCL15182933689
27025Dr. RodriguezchlordiazePOXIDE 25MG 29011739391
27025Dr. WongLORazepam28222549500-2
27025Dr. WilsonLORazepam28232607599

Account NumberVisit Provider
12667Brown, PA
27025Dr. Rodriguez
27025Dr Wong
27025Dr Wilson

I would like to create an object for the end user that looks like this:    

ProviderRx'sVisitsRx's/Visit
Brown, PA212/1
Dr. McDonald4           04/0
Dr. Rodriguez111/1
Dr. Wong111/1
Dr. Wilson111/1

(I also need to make a line graph showing Providers Rx/Visit rate over time with MonthYear as the X axis--so if I end up having to count providers visits in the script, somehow I would have to relate it back to my Calendar table.)

1 Solution

Accepted Solutions
Digvijay_Singh

11 Replies
Digvijay_Singh

May be this -

Capture.PNG

Margaret
Creator II
Creator II
Author

Right but HOW? 🙂

What expression do I use? Did you use??

Digvijay_Singh

I created island provider table to have all names at one place and can be used as dimension, here the script - (I found one other problem, you need to clean your names, Somewhere it has 'Dr.' and somewhere without dot after 'Dr'

Rx:

LOAD [Account Number],

     replace(trim([Rx Provider]),'.','') as [Rx Provider],

     Medication,

     [Rx ID]

FROM

[https://community.qlik.com/thread/294627]

(html, codepage is 1252, embedded labels, table is @1);


visit:

LOAD [Account Number],

     replace(trim([Visit Provider]),'.','') as [Visit Provider]

FROM

[https://community.qlik.com/thread/294627]

(html, codepage is 1252, embedded labels, table is @2);


Provider:

Load

distinct [Rx Provider] as Provider

Resident Rx;

Concatenate

Load distinct

[Visit Provider] as Provider

Resident visit

Where Not Exists(Provider,[Visit Provider])


The expression used are -

For Rx - Count( If(Provider=[Rx Provider],[Rx Provider]))

For visits - Count( If(Provider=[Visit Provider],[Visit Provider]))

For Rx/Visit - Column(1)/Column(2)


I attached qvw as well in the last post. Thanks



Margaret
Creator II
Creator II
Author

Thank you. I definitely didn't see a .qvw on the first post, but I see it now.

Shouldn't I be counting ID's like this, or is it the same thing since you didn't use DISTINCT?


Count( If(Provider=[Rx Provider],[Rx ID]))

Count( If(Provider=[Visit Provider],[Account Number]))



Digvijay_Singh

I think you can count IDs, I just tried to match numbers

Margaret
Creator II
Creator II
Author

I think it's working, thank you!!

I also changed it to Set Analysis and then I don't have to wait for the chart to load:

count({<Provider={"=$([Visit Provider])"}>}DISTINCT VisitID)

Digvijay_Singh

Great!

Margaret
Creator II
Creator II
Author

Except using Set Analysis totals the count for everyone and assigns it to each provider instead of separate for each provider.

count({<Provider={"=$([Visit Provider])"}>}DISTINCT [Account Number])

Is there a way to use set analysis without it doing that?

Digvijay_Singh

I think set analysis won't work here because Provider is an island field and not associated to rest of the data model. Do you see too much slowness with the if?