meditech data repository 102

Download Meditech Data Repository 102

Post on 13-Nov-2014

97 views

Category:

Documents

22 download

Embed Size (px)

DESCRIPTION

This is the second installment in the MEDITECH Data Repository training series. In this installment you will learn: Where to find data in the DR, Report Development Standards, writing efficient code, T-SQL tips, Report Development with SSRS and Report Builder. Learn how to master report development in MEDITECH Data Repository.

TRANSCRIPT

Soup to Nuts - Data Repository 1022012 MUSE International Tuesday Education Session #803 May 29th 1:30pm

Presenter: Jamie Gerardo www.acmeware.com

Todays AgendaFinding Data Report Development Standards Writing Efficient Code T-SQL Tips Report Development SSRS

Reports Report Models/Report Builder

Finding Data

If you know the NPR structure then finding data will be much easier In general you can think of a Detail Segment as a table Tools Meditech Website SysDrTables Shift F9 (C/S) and Shift F8 for Magic DR Application Menu

1. 2. 3.

4.

Meditech DR Home PageOverview of the data repository

* Table Structure

Viewing the Table Structure http://www.meditech.com/Useful Table information

Meditech - Table Structure

1. Shows the equivalent NPR Parent/Child relationships 2. Interactive Primary Keys that displays other tables with foreign keys

SysDr Tables in livedb---------------------------------------------------------------------------- A general search by DR Field Name -- '%Comment%' is a wildcard search for any field with Comment -- You can modify the name as needed for your search ---------------------------------------------------------------------------

SELECT T.Name, C.* FROM livedb.dbo.SysDrColumns C INNER JOIN livedb.dbo.SysDrTables T ON C.TableID = T.TableID WHERE C.Name like '%Comment%' order by 1-------------------------------------------- A search by specific NPR field -------------------------------------------

Examples of how to query Sys DR tables

-------------------------------------------------------- A search by Dpm and Detail Segment -------------------------------------------------------

SELECT T.Name, C.* FROM livedb.dbo.SysDrColumns C INNER JOIN livedb.dbo.SysDrTables T ON C.TableID = T.TableID WHERE C.NprElement = 'BAR.PAT.account' order by 1

SELECT T.Name, C.* FROM livedb.dbo.SysDrColumns C INNER JOIN livedb.dbo.SysDrTables T ON C.TableID = T.TableID WHERE C.NprDpm = 'BAR.PAT' AND C.NprSegment = 'main' order by 1

SysDr Result ExampleSELECT T.Name, C.* FROM livedb.dbo.SysDrColumns C INNER JOIN livedb.dbo.SysDrTables T ON C.TableID = T.TableID WHERE C.Name like '%Comment%' order by 1

Shows table name, column, data type along with the DPM, NprSegment and NprElement

Shift F9 (C/S) and Shift F8 for Magic

Table and Field Inquiry on the DR Application Menu

I rarely use these tools on the DR Menu They can be helpful but I find the previously covered options to be the best.

Magic 5.61 Screen

Report/SQL Development Standards Data

and Database Organization Stored procedures Documentation

Organization - Database

1. Dont save stored procedures and/or tables in livedb. 2. Create a database to keep your stored procedures, views and tables. Make sure Recovery Mode is set to simple You can set up the database files similar to livedb 3. You will want to include the database you create in your backup plan.

What is a stored procedure?A stored procedure is a saved set of code on the SQL Server that allows you to run:EXEC spBarAccountsByAccountTypeRather than SELECT BVFD.AccountType, BV.PostalCode, BV.AccountNumber FROM livedb.dbo.BarVisits BV INNER JOIN livedb.dbo.BarVisitFinancialData BVFD ON BV.SourceID = BVFD.SourceID AND BV.BillingID = BVFD.BillingID

Organize your Stored Procedures

Name your stored procedures so that you can easily locate them. Ex: spErDepartVolumesByHour Ex: spAdmRevisitsTable Re-name stored procs no longer in use. Ex: x_spErDepartVolumesByHour Use Header information to describe a stored procedures use. Only save useable code as a stored procedure. Save test code and research code as a text file or label appropriately.

Stored ProceduresTo save a stored procedure you CREATE PROC. This saves the stored procedure on the server/database youve selected

Once created you can Modify and View Dependencies

Saving code as a text fileItems to save as a text file 1. Research queries 2. Testing queries

Default Location this can be changed

Document in your code!

Documenting through out your code is a huge help with understanding laterjust what you were thinking at the time. Document on any bit of code that is the least bit out of the ordinary. Not only what by why. Notate in each step of your code what you are doing.

Stored Procedure Example Header

Example code documentation

Creating Efficiencies

Indexing

Estimated Execution Plan

Joining on Primary Keys Creating Datamarts (tables) Functions Using With (NoLock)

Table Indexing

Clustered

Every Meditech table has a clustered index, which is the physical order of the table by primary key(s). Never modify or delete There is only 1 per table A non-clustered index creates a separate 'internal' table that stores only the selected key values of the table in order. Each 'record' in this index contains the key value from one record in the table along with a pointer to either the data record itself or to a value in the clustered index. A max of 249 non-clustered indexes per table You will want to be selective with indexes you build

Non-Clustered

Typical Indexes used

BarChargeTransactions

BarCollectionTransactions

ixServiceDateTime ixTransactionProcedureID ixProcedureChargeDeptixVisitID ixAdmitDateTime ixServiceDateTime ixServiceDateTime ixStatus

ixReceiptDateTime ixInsuranceIDixAdmitDateTime ixVisitID ixAccountNumber (Field4) ixUnitNumber (Field3)

AdmittingData

BarVisits

AbstractData

AdmVisits

DMisUserStatisticsDetail

Example of Execution PlanDisplay Estimated Execution Plan

Creating an Index

Primary Keys

Joining on the primary keys will make your report run faster. Omitting the primary key will not only slow down your query but many times your output will not be correct. Each application has a unique identifier (primary key) that will allow you to join to other applications.

Primary Key ExampleSELECT AV.VisitID, AV.LocationID, AV.[Name], AD.AdmitDateTime FROM livedb.dbo.AdmVisits AV WITH (NOLOCK) Even if there is only one SourceID, you will want to use the Clustered Index for faster processing.

INNER JOIN livedb.dbo.AdmittingData AD WITH (NOLOCK) ON AV.SourceID = AD.SourceID AND AV.VisitID = AD.VisitID

WHERE Status='ADM IN

SQL Design Query Editor

You can use this tool but you still need to join on the primary keys. This tool will not automatically do that for you.

Primary Key Example 2SELECT AV.VisitID, AV.LocationID, AV.[Name], AD.AdmitDateTime, BV.PrimaryInsuranceID, BVFD.Balance FROM livedb.dbo.AdmVisits AV INNER JOIN livedb.dbo.AdmittingData AD ON AV.SourceID = AD.SourceID AND AV.VisitID = AD.VisitID LEFT JOIN livedb.dbo.BarVisits BV ON AV.SourceID = BV.SourceID AND AV.VisitID = BV.VisitID LEFT JOIN livedb.dbo.BarVisitFinancialData BVFD ON BV.SourceID = BVFD.SourceID AND BV.BillingID = BVFD.BillingID where Status='ADM IN'

VisitID is in a number of tables but youll only want to use it to join to a parent type table BarVisits, AbstractData, Lab Specimens, SchAppointments

Use the applications primary key (unique identifier) within the application tables. Adm - VisitID Bar BillingID Abs AbstractID Oe OrderID Sch - AppointmentID

Creating Datamarts / TablesWhen do you create a new table?

Processing time for a report may dictate the need for a table. Combining data from various applications for faster queries. Combining data and creating custom fields for reporting needs. Building Report Models

Datamart ExampleIssue: You have a very large query for nursing with lots of data from various assessments and with pharmacy data. This query takes over 10 minutes to run and will take longer if additional filters are added. Solution: 1. Create a table with all the data you need for your reports 2. Set up a SQL Server Agent Job to populate the data on a nightly basis 3. Create a set of store procedures to use for your report output.

Datamart Example - ContinuedNursingStoredProcedureThis table gets updated daily. A SQL Server Job is set up to populate on a nightly basis with new data.

Additional Stored procedures are written to use for reporting purposes NursingLocationSummary

Creating Tables

You can write sql code to insert data into a table by first creating the table then inserting the data.After the first table insert typically you will: TRUNCATE TABLE PatientBirthDates INSERT PatientBirthDates

1. CREATE TABLE PatientBirthDates ( Name varchar(35) not null, AccountNumber varchar(15) not null, DOB datetime null) 2. INSERT PatientBirthDates SELECT Name, AccountNumber, BirthDateTime FROM AdmVisits

You can insert directly into a table as below. The data types and fields will populate based on the data returned.The INTO only works the first time.

Select * INTO tbNewTable from DMisUsers

Either way of creating the table is fine. Just note that you may need alter data types and write code to add Primary keys. Typically modifications will need to be made when the table is created by an INTO. Youll also need to Truncate Table where necessary. ** Will demonstrate

User Defined FunctionWhat is a User Defined Function?Functions are subroutines used to encapsulate frequently performed logic. Any code that must perform the logic incorporated in a function can call the function rather than having to repeat all of the function logic.

Built-in functions operate as defined in the Transact-SQL Reference and cannot be modified. The functions can be referenced only in Transact-SQL statements using the syntax defined in the Tran