Thursday, July 7, 2016

Code first - Cannot insert the value NULL into column 'Id'


public Category(string name, string urlName, int index)
{
    CategoryId = Guid.NewGuid();
    Name = name;
    UrlName = urlName;
    CategoryIndex = index;
}








Solution
[Key]
[DatabaseGenerated(DatabaseGenerationOption.None)]
public Int64 PolicyID { get; set; }

Thursday, June 23, 2016

MERGE (Transact-SQL)

In SQL Server 2008, you can perform multiple data manipulation language (DML) operations in a single statement by using the MERGE statement. For example, you may need to synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table. Typically, this is done by executing a stored procedure or batch that contains individual INSERT, UPDATE, and DELETE statements. However, this means that the data in both the source and target tables are evaluated and processed multiple times; at least once for each statement.
By using the MERGE statement, you can replace the individual DML statements with a single statement. This can improve query performance because the operations are performed within a single statement, therefore, minimizing the number of times the data in the source and target tables are processed. However, performance gains depend on having correct indexes, joins, and other considerations in place

USE [MyDatabase]
GO
merge into mytable as Target
using mytable2 as Source
on Target.id=Source.id
when matched then 
update set Target.name=Source.name,
Target.Salary = Source.Salary
when not matched then
insert (id,name,salary) values (Source.id,Source.name,Source.Salary);

Bulk Load Best Practices

The MERGE statement can be used to efficiently bulk load data from a source data file into a target table by specifying the OPENROWSET(BULK…) clause as the table source. By doing so, the entire file is processed in a single batch.
To improve the performance of the bulk merge process, we recommend the following guidelines:
  • Create a clustered index on the join columns in the target table.
  • Use the ORDER and UNIQUE hints in the OPENROWSET(BULK…) clause to specify how the source data file is sorted.
    By default, the bulk operation assumes the data file is unordered. Therefore, it is important that the source data is sorted according to the clustered index on the target table and that the ORDER hint is used to indicate the order so that the query optimizer can generate a more efficient query plan. Hints are validated at runtime; if the data stream does not conform to the specified hints, an error is raised.
These guidelines ensure that the join keys are unique and the sort order of the data in the source file matches the target table. Query performance is improved because additional sort operations are not necessary and unnecessary data copies are not required. The following example uses the MERGE statement to bulk load data from StockData.txt, a flat file, into the target table dbo.Stock. By defining a primary key constraint onStockName in the target table, a clustered index is created on the column used to join with the source data. The ORDER and UNIQUE hints are applied to the Stock column in the data source, which maps to the clustered index key column in the target table.
Before running this example, create a text file named 'StockData.txt' in the folder C:\SQLFiles\. The file should have two columns of data separated by a comma
USE AdventureWorks2008R2;
GO
CREATE TABLE dbo.Stock (StockName nvarchar(50) PRIMARY KEY, Qty int CHECK (Qty > 0));
GO
MERGE dbo.Stock AS s
USING OPENROWSET (
    BULK 'C:\SQLFiles\StockData.txt',
    FORMATFILE = 'C:\SQLFiles\BulkloadFormatFile.xml',
    ROWS_PER_BATCH = 15000,
    ORDER (Stock) UNIQUE) AS b
ON s.StockName = b.Stock
WHEN MATCHED AND (Qty + Delta = 0) THEN DELETE
WHEN MATCHED THEN UPDATE SET Qty += Delta
WHEN NOT MATCHED THEN INSERT VALUES (Stock, Delta);
GO

reference:
 https://msdn.microsoft.com/en-us/library/cc879317.aspx
https://technet.microsoft.com/en-us/library/bb510625.aspx
http://stackoverflow.com/questions/17967374/sql-merge-statement-not-working-in-stored-procedure
http://www.databasejournal.com/features/mssql/article.php/3739131/UPSERT-Functionality-in-SQL-Server-2008.htm


Wednesday, March 30, 2016

IntelliSense IN SQL SERVER MANAGEMENT STUDIO

SQL Prompt : Write, format, and refactor SQL effortlessly
IN SQL SERVER MANAGEMENT STUDIO AND VISUAL STUDIO
  • IntelliSense-style code completion
  • Customizable code formatting
  • Code snippet library
  • Refactor SQL code
  • SSMS tab history
  • New: SSMS tab coloring
Writing SQL code by hand, even with IntelliSense, is frankly pretty dull
So we made SQL Prompt, which isn’t
An add-in for SQL Server Management Studio and Visual Studio, SQL Prompt strips away the repetition of coding.
As well as autocompleting your code, SQL Prompt takes care of formatting, object renaming, and other distractions, so you can concentrate on how the code actually works.
Whether you need to write, refactor, or explore database code, find out how SQL Prompt makes it effortless by trying it free for 28 days.
Reference :
http://www.red-gate.com/products/sql-development/sql-prompt/


Thursday, March 10, 2016

HL7 PID (Patient Identification) Segment

PID: Patient identification segment

The PID segment is used by all applications as the primary means of communicating patient identification information. This segment contains permanent patient identifying and demographic information that, for the most part, is not likely to change frequently.


The HL7 PID segment is found in every type of ADT message (i.e. ADT-A01, ADT-A08, etc.) and contains 30 different fields with values ranging from patient ID number, to patient sex, to address, to marital status, to citizenship. The PID segment provides important identification information about the patient and, in fact, is used as the primary means of communicating the identifying and demographic information about a patient between systems. Due to the nature of the information found in the PID segment, it is unlikely to change frequently. 

SEQLENGTHDataTypeOptional/RequiredRPT / #TBL #NAME
PID.14SIO1
Set ID - PID
PID.220CXB1
Patient ID
PID.320CXR*
Patient Identifier List
PID.420CXB*
Alternate Patient ID - PID
PID.548XPNR*
Patient Name
PID.648XPNO*
Mother s Maiden Name
PID.726TSO1
Date/Time Of Birth
PID.81ISO10001Sex
PID.948XPNO*
Patient Alias
PID.1080CEO*
Race
PID.11106XADO*
Patient Address
PID.124ISB10289County Code
PID.1340XTNO*
Phone Number - Home
PID.1440XTNO*
Phone Number - Business
PID.1560CEO1
Primary Language
PID.1680CEO1
Marital Status
PID.1780CEO1
Religion
PID.1820CXO1
Patient Account Number
PID.1916STB1
SSN Number - Patient
PID.2025DLNO1
Driver's License Number - Patient
PID.2120CXO*
Mother's Identifier
PID.2280CEO*
Ethnic Group
PID.2360STO1
Birth Place
PID.241IDO10136Multiple Birth Indicator
PID.252NMO1
Birth Order
PID.2680CEO*
Citizenship
PID.2760CEO1
Veterans Military Status
PID.2880CEO1
Nationality
PID.2926TSO1
Patient Death Date and Time
PID.301IDO10136Patient Death Indicator

Reference:
 http://www.hl7soup.com/Features.html

HL7 Soup Software help you to Edit and View HL7 PID Patient Identification Segment 


HL7 Editing Software



Wednesday, March 2, 2016

Design UML Diagram online without Installing the Tool

https://www.draw.io/

Health Language 7 (HL7) Convert HL7 Code to XML

HL7 (Health Language 7) is a "standard" utilized by the healthcare industry to enable messaging between applications i.e. EHR to PMS (practice management system) for example. It is managed and maintained by Health Level Seven International (HL7) which is a not-for-profit, ANSI-accredited standards developing organization. The HL7 standard is often jokingly referred to as the “non-standard standard.” This is not very fair but it does reflect the fact that almost every hospital, clinic, imaging center, lab, and care facility is “special” in terms of how it implements HL7 (really?, why?). The reason is primarily because there is no such thing as a standard business or clinical process for interacting with patients, clinical data, or related personnel.

The HL7 messaging protocol was designed to facilitate high volumes of pre-defined data to be shared across many applications reliably. The protocol selected to make this happen was a traditional file transfer or a TCP/IP socket in both a real-time and batched fashion. HL7 v2.x message structure is complex, flat, and delimited. HL7 has obviously evolved over time. The current version of HL7 is v3.0. However, older versions exist and make up the bulk of the standard used today primarily because of the large number customization that have been done to each HL7 message.

Reference:
https://catalyze.io/learn/hl7-101-a-primer ***

http://www.interfaceware.com/manual/xml.html

http://www.christian-sonek.de/hl7/hl7server_de

http://www.interfaceware.com/manual/full_tree.html **


Tuesday, February 23, 2016

Select All checkbox using Knockout JS


Normal SelectAll CheckBoxes using Knockout
  // Select All checkbox
    self.SelectedAllPermissions = ko.computed({
        read: function () {
            var item = ko.utils.arrayFirst(self.SecurityPagesListArray(), function (item) {
                return !item.SelectedPage();
            });
            return item == null;
        },
        write: function (value) {
            ko.utils.arrayForEach(self.SecurityPagesListArray(), function (permission) {
                permission.SelectedPage(value);
            });
        }
    });

--------------------------------------------------------------------------------


Select All Checkbox from One Array to Another


// Select All checkbox
    self.SelectedAllPermissions= ko.computed({
        read: function () {
            return self.selectedBooks().length === self.filterBooks().length;
        },
        write: function (value) {
            self.selectedBooks(value ? self.filterBooks().slice(0) : []);
        },
        owner: self
    });


   <input style="margin-left:10px;width:20px;height:20px;" class="pull-left" type="checkbox" data-bind="checked: SelectedAllPermissions" />