Archive January 2019

Get disease ICD code in C# using ICD10 API

public string GetICDCode(string ICDCode)
            DiagnosisModel model = new DiagnosisModel();
            String postURL = string.Format("{0}&desc=short&r=json", ICDCode);
            WebRequest request = WebRequest.Create(postURL);
            request.Method = "GET";
            request.ContentType = "application/json; charset=utf-8";

            var response = (HttpWebResponse)request.GetResponse();
            string jsonText;
            using (var sr = new StreamReader(response.GetResponseStream()))
                jsonText = sr.ReadToEnd();
            return jsonText;


We created a method for getting icd code.

Create Model for icd code vlaues and data

public class ICDCode
            public string Name { get; set; }
            public string[] Inclusions { get; set; }
            public string[] ExcludesOne { get; set; }
            public string[] ExcludesTwo { get; set; }
            public string Description { get; set; }
            public string Valid { get; set; }
            public string Type { get; set; }
            public string Response { get; set; }

Just pass icd code in above method and it will give you result as json,

deserilize it with you model class and store in your model properties.

ICDCode model = new ICDCode();

var jsonResultICDCode = GetICDCode(yourICDcode);

model.ICDResponse = new JavaScriptSerializer().Deserialize<ICDCode>(jsonResultICDCode);

If your ICD code is valid than, it will return
model.ICDResponse.Valid=1 and model.ICDResponse.Response == “True”

Now you can get all information about icd code in your model properties.

Select multiple count in one result set in sql and C#.

Here, you can select multiple counts from different – 2 tables in one result set. with multiple coulumn names.

i used insight databse ORM in C#.

First i created a Model in c# where result set will bind with Columns name and model property name.

public class AnalyticsModel
        public int totalAppointments { get; set; }
        public int totalPrescriptionRenewal { get; set; }
        public int totalNumberOfDropInsPerDay { get; set; }
        public int totalRequest { get; set; }

And Now My Store Procedure in SQL

CREATE PROC [dbo].[AnalyticsTotal]

	(SELECT COUNT(*) FROM Appointment WHERE MeetingType IN(1,3) AND Status=1) AS [totalAppointments],

	(SELECT COUNT(*) FROM Appointment WHERE MeetingType=2 AND Status=1) AS [totalPrescriptionRenewal],

	(SELECT COUNT(*) FROM Appointment WHERE IsDropIn=1 AND Status=1) AS [totalNumberOfDropInsPerDay],

	(SELECT COUNT(*) FROM Appointment WHERE MeetingType IN(1,2,3) AND Status=1) AS [totalRequest]


And in last i got my result set in my DataClass.

var Result = DB.QuerySql<AnalyticsModel>(@"Exec [dbo].[AnalyticsTotal]").FirstOrDefault();

Here QuerySql is the method of Insight Database ORM.

You can Install in your visual studio from nuget package manager.

Install-Package Insight.Database -Version 6.2.8

Get only time or only Date from a datetime string in SQL

If you have a datetime in string format or as varchar, than you can cast this string or varchar in datetime format.

And if you want to retrieve only date or only time from datetime than query is below.

CAST() method, you can use for conversation from any format to any other format in SQL


CAST(’01/14/2019′ AS DATETIME)

CAST(’01/14/2019′ AS TIME)

CAST(’01/14/2019′ AS DATE)

Ajax post method sample in jquery

How to send, get post data through ajax without refreshing whole page in jquery.

first you have to include jquery script files, you can download from jquery website.

                cache: false,
                type: "POST",
                url: _rootURL + obj.deleteUrl,
                data: { Token: removeId },
                success: function (result) {
      //result of function, get here or put here data in JSON format
                error: function (xhr, ajaxOptions, thrownError) {
                    showErrorNotification('Failed to processed successfully!');

Compare date and time in jquery

To compare date or dateandtime in jquery you have to pass date sring or date in Date() object.

if(new Date($('#txtsearchdatefrom').val()) <= newDate($('#txtsearchdateto').val())) {
//your code....


if(new Date('2018/12/02')<=new Date('2018/12/03'))
//your code

Get Enum Description in C#

To get Enum description in c# here is a method or code.

For this first you have to import a namespace of Refletion because it is a part of Reflection.

using System.Reflection;

After importing namespace you can use reflection and get enum description.

public static string GetEnumDescription(Enum value)
            FieldInfo fi = value.GetType().GetField(value.ToString());
            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (attributes.Length > 0)
                return attributes[0].Description;
                return value.ToString();

Now you can use this method to get enum description.

GetEnumDescription(Enum value)

Here value that we are passing will be string as same as in enum name.

Enum dropdown bind in MVC razor

How do you create dropdown list from enum in MVC

  1. Write Enum
public enum MeetingType
            FIRST= 1,
            SECOND= 2,
            THIRD= 3

public string Name{get;set;}

After Enum we will write get select list code from enum in controller section in those controller that will have the view of dropdown.

public ActionResult GetDropdown()
var enumData = from Demo e in Enum.GetValues(typeof(Demo))
                           select new
                               Value= (int)e,
                               Text= e
            ViewBag.EnumList = new SelectList(enumData,"Value","Text");
return View();

Here Demo is the Enum name and we created a list type of selectlist for dropdown.

Now we can use this ViewBag.EnumList in our dropdown list.

Razor Code:

@Html.DropDownList("Name", ViewBag.EnumList as SelectList, "Select Type", new { @class = "form-control" })

If you use @Html.DropDownListFor() Then for strongly bind code is below:

@Html.DropDownListFor(x => x.Name, (IEnumerable<SelectListItem>)ViewBag.EnumList, "Select Type", new { @class = "form-control" })

And now you can bind your dropdown with your Name model attribute.