//打印工作站脚本
var printStationList = [];
var currentprintStation = null;

function getPrintStationListFromServer() {
    var result = window.external.GetPrintStationResult();
    printStationList = JSON.parse(result);

    var yearMonthTpl = '<div class="monthInfo">{0}</div>';
    var pacsScpTpl = '<div id="printStationItemTemplate" class="caseItem" onclick="showPrintStationItem(\'{0}\',this)"><div class="caseItemPatientInfo">{0}</div><div class="caseItemZhuSu">图像格式：.jpg<br/>接收时间：{1}<br/>影像大小：{2}</div></div>';
    var html = [];
    var existedYear = [];

    $.each(printStationList, function (i, n) {
        if ($.inArray(n.year_month, existedYear) == -1) {
            existedYear.push(n.year_month);
            html.push(yearMonthTpl.format(n.year_month));
        } else {
            html.push(pacsScpTpl.format(n.name, n.received_time, n.size));
        }
    });

    $('#printStationListContent').html(html.join(''));
    if (currentpacsScp == null) {
        $('#printStationListContent .caseItem:eq(0)').click();
    }

}

function getPrintStationByPath(name) {
    var printStation = {};
    $.each(printStationList, function (i, n) {
        if (n.name == name) {
            printStation = n;
            return false;
        }
    });
    return printStation;
}

function showPrintStationItem(name, obj) {
    $('#printStationListContent .caseItem').removeClass("selected");
    $(obj).addClass("selected");

    var printStation = getPrintStationByPath(name);

    $('#details_printStation_title').html('{0} {1}'.format(printStation.name, printStation.size));

    $('#details_printStationImg').html('<img style="max-width:550px;" src="../../dicomdata/printscp/images/{0}" />'.format(name));

    currentprintStation = name;
}