class InterView{
constructor(args){
this.data = args.data;
this.render()
}
//入口
render(){
this.initTable()
}
/**
* table的重绘
*/
initTable(){
let trAttr = this.data.itemSort;
let showDays = this.data.showDays;
let len = showDays.length;
let content ='';
content +='';
content +=' | ';
for(let i =0 ;i | | | | | ';
}
content +='
';
content +='';
for(let j=0;j<=len;j++){
if(j===0){
content+='日 期 | '
}else{
content+=`${showDays[j-1]} | `
}
}
content +='
';
content +='';
content +='时间 | ';
for(let j=0;j37 | 11 | 15 | 19 | 23 | ';
}
content +='
';
content +=''
content+='
'
for(let i =0;i<1;i++){
content +="";
if(i == 0){
content +=`
呼吸脉搏体温 2510040 208039 156038 104037 52036 0035
|
| `;
}
content +="
";
}
for(let i=0;i';
for(let j=0;j<=len;j++){
if(j===0){
if(trAttr[i].id=="advice"){
content += ' | '
}else{
content += ''+trAttr[i].name+' | '
}
}else{
content+=` | `
if(trAttr[i].isColSpan){
break
}
}
}
content +=''
}
content+=''
document.getElementById('table').innerHTML=content;
this.initData(len)
}
/**
* 获取当前时间
* @returns {string}
*/
getDate(){
let now = new Date()
let year = now.getFullYear()
let month = (now.getMonth()+1)<10?('0'+(now.getMonth()+1).toString()):(now.getMonth()+1)
let day = now.getDate()<10?'0'+now.getDate().toString():now.getDate()
return year+'-'+month+'-'+day
}
/**
* 计算时间
* @param day
* @param date
* @returns {string}
* @constructor
*/
InitDateTime(day,date) {
let agoDate = new Date(Date.parse(date.replace(/-/g, "/")));
let agoTime = agoDate.getDate();
let dayAgo = -day + agoTime;
agoDate.setDate(dayAgo);
let agoDay = agoDate.getDate()<10?'0'+agoDate.getDate().toString():agoDate.getDate();
let agoMonth = agoDate.getMonth()+1<10?'0'+(agoDate.getMonth()+1).toString():(agoDate.getMonth()+1);
let agoYear = agoDate.getFullYear();
let dateFrom = (agoYear.toString() + '-' + agoMonth.toString() + '-' + agoDay.toString());
return dateFrom
}
initLabelData(type,data){
data.forEach((element,index) => {
if(element){
let keys = Object.keys(element);
let len = keys.length
if(len>0){
for(let i =0 ;i {
if(element){
document.getElementById(type)
.querySelectorAll('td')[0].appendChild(
new InViewLabel({'type':type,'info':element.name,'id':element.id}));
let svgLeft = (element.dose.begin)*126;
let svgTop = index * 20;
let svgInfo = element.dose.info;
let svgId = element.dose.id
let begin = element.dose.begin;
let end = element.dose.end;
let len = 0;
let arrow = true;
if(end ==-1){
len = (days-begin)*126;
}else{
len = (end-begin>0?end-begin:0.2)*126;
arrow = false;
}
let color = Utils.color16();
document.getElementById('advice').querySelectorAll('td')[1].appendChild(new InterViewSvg({'top':svgTop,'left':svgLeft,'info':svgInfo,'id':svgId,'length':len,'arrow':arrow,'color':color}));
}
});
}
initData(showDays){
let check = this.data.check;
if(check){
this.initLabelData('check',check);
}
let test = this.data.test;
if(test){
this.initLabelData('test',test);
}
let emr = this.data.emr;
if(emr){
this.initLabelData('emr',emr);
}
let prescription = this.data.prescription;
if(prescription){
this.initLabelData('prescription',prescription);
}
let handle = this.data.handle;
if(handle){
this.initLabelData('handle',handle);
}
let advice = this.data.advice;
if(advice){
this.initAdviceData('advice',advice,showDays);
}
this.initSvg(showDays,126,201);
let temperatureArr = this.data.T;
this.makeTempCrossLine(temperatureArr,3);
let rArr = this.data.R;
this.makeRLine(rArr,3);
let pArr = this.data.P;
this.makePulseLine(pArr);
}
/**
* 初始化svg 坐标系,tips
* @param {*} showDays
* @param {*} svgUnitWidth
* @param {*} svgHeight
*/
initSvg(showDays,svgUnitWidth,svgHeight){
let svg = d3.select("#svg");
svg.attr("width",svgUnitWidth*showDays).attr("height",svgHeight);
let damainX = showDays*6;
let xSc = d3.scaleLinear()
.domain([0, damainX])
.range([0, svgUnitWidth*showDays]);
this.xSc = xSc;
//公用X坐标轴
let xAxis = d3.axisTop(xSc).ticks(damainX).tickSize(svgHeight-1);
this.xAxis = xAxis;
svg.append("g").call(xAxis).attr("transform","translate(0,"+(svgHeight-1)+")");
//体温Y坐标轴
let ytemSc = d3.scaleLinear().domain([42,35]).range([0,svgHeight-1]);
let ytemAxis = d3.axisRight(ytemSc).ticks(8).tickSize(svgUnitWidth*showDays);
this.ytemSc = ytemSc;
this.ytemAxis = ytemAxis;
svg.append("g").call(ytemAxis)
.classed('axis_y', true);
d3.selectAll(".axis_y .tick:nth-of-type(6) line").attr('stroke','red')
//呼吸Y坐标系
let yRSc = d3.scaleLinear().domain([35,0]).range([0,svgHeight-1]);
let yRAxis = d3.axisRight(yRSc).ticks(8).tickSize(0).tickValues("");
this.yRSc = yRSc ;
this.yRAxis = yRAxis;
//脉搏Y坐标系
let yPSc = d3.scaleLinear().domain([140,0]).range([0,svgHeight-1]);
let yPAxis = d3.axisRight(yPSc).ticks(8).tickSize(0).tickValues("");
this.yPSc = yPSc;
this.yPAxis = yPAxis;
svg.append("g").call(yRAxis);
this.svg = svg;
//创建tips
let tips = svg.append ('g')
.attr('id','tips')
.attr ('class', 'tips')
.style('display','none')
this.tips = tips;
let tipsRect = tips.append ('path')
.attr('id','tipsRect')
.attr ('class' , 'tips-border' )
.attr ('d' , 'm5.99786,9.79993l0,0c0,-2.65063 2.97544,-4.79938 6.64583,-4.79938l3.02083,0l0,0l14.49999,0l27.18748,0c1.76259,0 3.45298,0.50565 4.69932,1.40571c1.24633,0.90006 1.94652,2.1208 1.94652,3.39368l0,11.99845l0,0l0,7.19907l0,0c0,2.65063 -2.97544,4.79938 -6.64583,4.79938l-27.18748,0l-18.94245,12.20371l4.44246,-12.20371l-3.02083,0c-3.67039,0 -6.64583,-2.14875 -6.64583,-4.79938l0,0l0,-7.19907l0,0l0,-11.99845z' )
.attr('fill','red')
.attr("opacity","0.3")
this.tipsRect= tipsRect;
let tipsText = tips.append ('text')
.attr('id','tipsText')
.attr('class' ,'tips-text')
.attr( 'x' , 6 )
.attr( 'y' , 25 )
.attr( 'fill',"black")
.attr('font-size','14px')
.text ( '' ) ;
this.tipsText = tipsText;
}
/**
* 呼吸
* @param {*} ds
* @param {*} offset
*/
makeRLine(ds,offset){
let svg = this.svg;
let xSc = this.xSc;
let ySc = this.yRSc;
let len = ds.length;
var resDs = [];
for(let i =0;i [ xSc(d[0]+0.5), ySc(d[1]) ,d[1]] );
let tipsText = this.tipsText;
let tips = this.tips;
let tipsRect = this.tipsRect;
let tems = svg.append("g")
.selectAll("R").data(resDs).enter()
.append("use")
.attr("href","#R")
.attr("data-y",d =>d[2])
.attr("transform",d=>"translate("+(d[0]-offset)+","+(d[1]-offset)+") ")
.attr("opacity",d =>d[1]==undefined ? 0 : 1)
.classed("outerData",true)
.on("mousemove",function(e){
var pt = d3.pointer( e ,tems.node());
console.log(pt,e.target.dataset.y);
tipsText.text ("R:"+e.target.dataset.y) ;
tips.attr ('transform', 'translate(' + (e.pageX-126) + ',' + (e.pageY-90) + ')' )
tipsRect.attr("fill","rgb(255,140,0)")
tips.style('display', 'block');
})
.on ('mouseout' , function () {
tips.style('display', 'none');
})
var lnMaker = d3.line().defined((d,i) => d[1]==undefined ? false : true);
svg.append("g").append("path")
.attr("d",lnMaker(resDs))
.attr("fill","none")
.attr("stroke","#7631a1")
.classed("outerData",true);
}
/**
*
* @param {传入数据,42个 {"y":100,type:"P"}的数组} ds
*/
makePulseLine(ds){
let svg = this.svg;
let xSc = this.xSc;
let ySc = this.yPSc;
let len = ds.length;
var resDs = []
for(let i =0;i [ xSc(d[0]+0.5), ySc(d[1]), d[2] ,d[1]] );
let tips = this.tips
let tipsText = this.tipsText;
let tipsRect = this.tipsRect;
let tems = svg.append("g")
.selectAll("bcuse").data(resDs).enter()
.append("use")
.attr("href",d =>d[2])
.attr("data-y",d =>("#P"==d[2]?"P:":"HR:")+d[3])
.attr("transform",d=>"translate("+(d[0])+","+(d[1])+") ")
.attr("opacity",d =>d[1]==undefined ? 0 : 1)
.classed("outerData",true)
.on("mousemove",function(e){
// var pt = d3.pointer( e,tems.node() );
// console.log(pt,e.target.dataset.y);
tipsText.text (e.target.dataset.y) ;
tips.attr ('transform', 'translate(' + (e.pageX-126) + ',' + (e.pageY-90) + ')' )
tipsRect.attr("fill","rgb(255,140,0)")
tips.style('display', 'block');
})
.on ('mouseout' , function () {
tips.style('display', 'none');
})
var lnMaker = d3.line().defined((d,i) => d[1]==undefined ? false : true);;
svg.append("g").append("path")
.attr("d",lnMaker(resDs))
.attr("fill","none")
.attr("stroke","red")
.classed("outerData",true)
}
/**
* 体温记录
* @param {*} ds
* @param {*} showDays
* @param {*} svgUnitWidth
* @param {*} svgHeight
* @param {*} offset
*/
makeTempCrossLine(ds,offset){
let svg = this.svg;
let xSc = this.xSc;
let ySc = this.ytemSc;
let len = ds.length;
var resDs = [];
var physicalCool = [];
for(let i =0;i [ xSc(d[0]+0.5), ySc(d[1]) ,d[1]] );
let tipsText = this.tipsText;
let tips = this.tips;
let tipsRect = this.tipsRect;
let tems = svg.append("g")
.selectAll("bcuse").data(resDs).enter()
.append("use")
.attr("href","#T")
.attr("data-y",d =>d[2])
.attr("transform",d=>"translate("+(d[0]-offset)+","+(d[1]-offset)+") ")
.attr("opacity",d =>d[1]==undefined ? 0 : 1)
.classed("outerData",true)
.on("mousemove",function(e){
var pt = d3.pointer( e ,tems.node());
console.log(pt,e.target.dataset.y);
tipsText.text ("T:"+e.target.dataset.y) ;
tips.attr ('transform', 'translate(' + (e.pageX-126) + ',' + (e.pageY-90) + ')' )
tipsRect.attr("fill","rgb(255,140,0)")
tips.style('display', 'block');
})
.on ('mouseout' , function () {
tips.style('display', 'none');
})
var lnMaker = d3.line().defined((d,i) => d[1]==undefined ? false : true);
svg.append("g").append("path")
.attr("d",lnMaker(resDs))
.attr("fill","none")
.attr("stroke","blue")
.classed("outerData",true);
//绘制物理降温
if(physicalCool.length>0){
physicalCool.forEach((d)=>{
//绘制虚线
let pcResDs = [[xSc(d[0]+0.5),ySc(d[1])],[xSc(d[0]+0.5),ySc(d[2])]];
svg.append("g").append("path")
.attr("d",lnMaker(pcResDs))
.attr("fill","none")
.attr("stroke-dasharray","5,5")
.attr("stroke","red")
.classed("outerData",true);
//绘制红色圆圈
let rhcDs = [xSc(d[0]+0.5),ySc(d[2])];
svg.append("g")
// .selectAll("bcuse").data(rhcDs).enter()
.append("circle").attr("r",4)
.attr("cx",rhcDs[0]).attr("cy",rhcDs[1])
.style("fill","none")
.attr("stroke","red")
.classed("outerData",true)
});
}
}
}
class InViewLabel{
constructor(args){
this.title=args.title
this.type = args.type||"emr";
this.id = args.id;
this.info = args.info;
this.event = () =>{
Utils.sendDataToWat(JSON.stringify({
event : "click",
id: this.id,
type: this.type
}));
}
return this.render();
}
render(){
let div = document.createElement("div");
div.innerHTML= Utils.createDiv(this.title,this.info,this.type);
div.onclick = this.event;
return div;
}
}
class InterViewSvg{
constructor(args){
this.top = args.top;
this.left = args.left;
this.info = args.info;
this.id = args.id;
this.length = args.length;
this.arrow = args.arrow;
this.color = args.color;
this.event = () =>{
Utils.sendDataToWat(JSON.stringify({
event : "click",
id: this.id,
type: "advice"
}));
}
return this.render();
}
render(){
let div = document.createElement("div");
div.innerHTML = Utils.createSvg(this.top+'px',this.left+'px',this.info,this.id,this.length,this.arrow);
div.onclick = this.event;
return div;
}
}
/**
* 带图标标签
export class ImgLabel extends InViewLabel{
constructor(args){
super(args);
this.type=args.type||'emr';
return this.render();
}
render(){
let div = document.createElement("div");
div.innerHTML= Utils.createDiv(this.title,this.info,this.type);
div.onclick = this.event;
return div;
}
}
*/
class Utils{
constructor(){
}
static getRealPath(){
let curWwwPath = window.document.location.href;
let pathName = window.document.location.pathname;
let pos = curWwwPath.indexOf(pathName);
let localhostPaht = curWwwPath.substring(0, pos);
let projectName = pathName.substring(0, pathName.substr(1).indexOf('/')+1);
return localhostPaht+projectName;
}
static sendDataToWat(data){
return window.parent.top.DxURLPage.action(this.GetQueryString('strwinid'),this.GetQueryString('strctrid'),data);
}
static GetQueryString(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null){
return unescape(r[2]);
}
return null;
}
static createDiv(title,info,type,color) {
let divTemplate = "";
switch(type) {
case "emr":
divTemplate = ``;
break;
case "test":
divTemplate = ``;
break;
case "check":
divTemplate = ``
break;
case "advice":
divTemplate = `${info}
`
break;
default:
divTemplate = `${info}
`;
}
return divTemplate;
}
static createSvg(top,left,info,id,length,arrow){
let color = this.color16();
if(arrow){
return ``;
}else{
return ``;
}
}
static color16(){
let colors = Array.of('#78debe','#4395e2','#8bcf31','#cbc874','#7631a1',
'#b488f0','#217c62','#fddc49','#70323e','#f509f3','#a1baee','#ed7a30',
'#fa53fd','#73e50f','#254911','#c86e70','#db2dac','#395599');
let index = Math.floor((Math.random()*colors.length));
return colors[index];
}
}