Parsing ICD Details from Ajax Call

by Nivaldo

HTML

<!--<a href="http://mlstage1.apa.org:8031/pimain/services/icd-10-cm/get-icd-detail.xqy?id=f02">hello</a>-->
<p style="background-color: yellow; width: 25%">click me to see icd details</p>
<div id="dataplace"></div>

JavaScript

var entries = ["codeAlso","codeFirst","excludes1","excludes2","includes","inclusionTerm","notes","useAdditionalCode"]
var entriesTitle = ["Also Codes","First Codes","Excludes Type 1","Excludes Type 2","Includes","Terms to Include","Notes","Addtional Codes to Use"]

$( "p" ).click(function() {
    $.post("http://mlstage1.apa.org:8031/pimain/services/icd-10-cm/get-icd-detail.xqy",{id:"f02"})
    .done(function( data ) {
        var html = "";
        
        html += "<h2>" + data.diag.id + "</h2>";
        html += "<h5>" + data.diag.sectionId + "</h5>";
        html += "<h4>" + data.diag.desc + "</h4>";
        
        for (var entryCt=0; entryCt<entries.length; entryCt++)
            if (data.diag[entries[entryCt]] != null) {   
                html += "<p><b>" + entriesTitle[entryCt] + "</b></p>";
                html += "<ul>";
                for (var ct=0; ct<data.diag[entries[entryCt]].note.length; ct++) 
                    html += "<li>" + data.diag[entries[entryCt]].note[ct] + "</li>";
                html += "</ul>";
            }

        $("#dataplace" ).html(html);
    });
});