Database type: Multiple ... I have it in CSV, MDB, ACCDB, and loaded into MySql. I can get to it anyway I need to.
I work for a Medical Facility and have been handed a database that has millions of 'line items' in it. Each line item contains the patients Chart Number, the Date of Service, the Charge Code, Payment Amount, and Total Charges for that charge code. I have a snippet of the data below:
+-----+-------------+---------+--------------+----------+ |Chart| ServiceDate | Code | Payment | Charges | +-----+-------------+---------+--------------+----------+ | 2241| 1/27/2014 | 12002 | 411.00 | 51.24 | | 2241| 1/27/2014 | 17311 | 1491.00 | 616.10 | | 2241| 1/27/2014 | 17312 | 2108.00 | 722.98 | | 2241| 1/7/2014 | 17311 | (1491.00) | 0.00 | | 2241| 1/7/2014 | 17312 | (1054.00) | 0.00 | | 2241| 2/17/2014 | 17311 | 1491.00 | 616.10 | | 2241| 2/17/2014 | 17312 | 1054.00 | 361.49 | | 2241| 3/20/2014 | 17311 | (1491.00) | 0.00 | +-----+-------------+---------+--------------+----------+
These are all for the same Patient, which I can tell due to the 'Chart' column being the same. In this example, the patient has 3 dates of service (1/27/2014, 1/7/2014, 2/17/2014, and 3/20/2014).
Now this is where things get complicated:
I need to run a query/script/program/anything that basically combines those line items and turns them into appointments.
This is how they would be grouped together (shown just for reference):
+-----+-------------+---------+--------------+----------+ |Chart| ServiceDate | Code | Payment | Charges | +-----+-------------+---------+--------------+----------+ | 2241| 1/27/2014 | 12002 | 411.00 | 51.24 | | | | 17311 | 1491.00 | 616.10 | | | | 17312 | 2108.00 | 722.98 | +-----+-------------+---------+--------------+----------+ +-----+-------------+---------+--------------+----------+ | 2241| 1/7/2014 | 17311 | (1,491.00) | 0.00 | | | | 17312 | (1054.00) | 0.00 | +-----+-------------+---------+--------------+----------+ +-----+-------------+---------+--------------+----------+ | 2241| 2/17/2014 | 17311 | 1491.00 | 616.10 | | | | 17312 | 1054.00 | 361.49 | +-----+-------------+---------+--------------+----------+ +-----+-------------+---------+--------------+----------+ | 2241| 3/20/2014 | 17311 | (1491.00) | 0.00 | +-----+-------------+---------+--------------+----------+
Now having blank cells in a database is just bad practice (IMHO), so I'd love to be able to go a step further and do it like this:
The final result would be more of a line-by-line setup, each line containing everything for the appointment.
Any column where the Chart and ServiceDate are the same, combine the Code,Payment, and Charges column (delim with a comma) as follows:
+-----+-------------+-------------------+------------------------+---------------------+ |Chart| ServiceDate | Codes | Charges | Payments | +-----+-------------+-------------------+------------------------+---------------------+ | 2241| 1/27/2014 | 12002,17311,17312 | 411.00,1491.00,2108.00 | 51.24,616.10,722.98 | +-----+-------------+-------------------+------------------------+---------------------+ | 2241| 1/7/2014 | 17311,17312 | (1491.00),(1054.00) | 0.00,0.00 | +-----+-------------+-------------------+------------------------+---------------------+ | 2241| 2/17/2014 | 17311,17312 | 1491.00,1054.00 | 616.10,361.49 | +-----+-------------+-------------------+------------------------+---------------------+ | 2241| 3/20/2014 | 17311 | 1491.00 | 0.00 | +-----+-------------+-------------------+------------------------+---------------------+
However, I can not think of any way to go about that in SQL or Excel, etc. The only thing that I can think of being able to do is to open up VS.Net and whip up an application that would loop through the entire DB and look for the columns where the Chart and ServiceDate are the same, and try to go from there. However, the logic behind how I would need to go about that is what is throwing me for a loop.
Spoken out in worded form ("Any column where the Chart and ServiceDate are the same, combine the Code,Payment, and Charges column") it seems so easy...but in practice I am at a loss as to where to start.
Does anyone have any ideas as to what direction I should take? Am I making this harder than it actually is?
I have an odd feeling this is going to be one of those: "OMG, I should have realized that" type moments when a response is posted, and I am going to apologize for that ahead of time :)