class ParseDataType { constructor(data, deviceInfo) { if (!data) return [] this.extractData = data this.eyeType = { OS: '', OD: '' } this.brand = deviceInfo.brand this.model = deviceInfo.model this.eyeType.OS = data.match(/OS/) this.eyeType.OD = data.match(/OD/) console.log('OS',this.eyeType.OS ? this.eyeType.OS[0] : '') console.log('OD',this.eyeType.OD ? this.eyeType.OD[0] : '') if (data.match(/Axial length values/) || data.match(/轴长值/)) { // 人工晶体生物测量 1 this.keyWords = 'IOL-Master500-1' } else if (data.match(/公式:/)) { // 人工晶体生物测量 2 this.keyWords = 'IOL-Master500-2' } else if (data.match(/Corneal Wavefront Analyzer/) && data.match(/Keratron™ Scout/)) { // 角膜地形图(阿玛仕) OCULUS Keratograph this.keyWords = 'OPTIKON' } else if (data.match(/IOL 计算/)) { // IOL-Master700 this.keyWords = 'IOL-Master700' } else if (data.match(/超声生物显微镜检查报告单/)) { // UBM // this.keyWords = 'UBM' } } analysis() { console.log('keyWords',this.keyWords); switch (this.keyWords) { case 'IOL-Master500-1': return this.master5001() case 'IOL-Master500-2': return this.master5002() case 'OPTIKON': return this.corneal() case 'IOL-Master700': return this.master700() case 'UBM': return this.ubmData() } } regexKey(start, end) { const regex =new RegExp(`${start}(.*?)${end}`, "g"); return [...this.extractData.matchAll(regex)].map(m => m[1]); } // 取start和mideele之间的值 regexKeyB(start, middle, end) { const regex =new RegExp(`${start}.*?${middle}(.*?)${end}\\s*`, "g"); return [...this.extractData.matchAll(regex)].map(m => m[1]); } regexKeyC(start) { const regex =new RegExp(`${start}\\s*(.*?)(?=\\s|$)`); return [...this.extractData.match(regex)].map(m => m[1]); } // 取middle和end之间的值 regexKeyD() { const regex = /(OD)-(Steep|Flat):.*?@(\d*)°/g; return [...this.extractData.matchAll(regex)].map(m => m[3] || ''); } regexKeyE() { const regex = /(OS)-(Steep|Flat):.*?@(\d*)°/g; return [...this.extractData.matchAll(regex)].map(m => m[3] || ''); } regexKeyF() { const regex = /Off:[^@]*@(\d+)°/g; return [...this.extractData.matchAll(regex)].map(m => m[1] || ''); } /** * master500 */ master5001() { let data = {} const examTime = this.regexKey('Examination date:', 'n:').length ? this.regexKey('Examination date:', 'n:') : this.regexKey('检查日期:', 'n:') const AL = this.regexKey('Comp. AL:', 'mm').length ? this.regexKey('Comp. AL:', 'mm') : this.regexKey('复合AL:', 'mm') const K1_D = this.regexKey('MV: ', '/').length ? this.regexKey('MV: ', '/') : this.regexKey('平均值: ', '/') const regex1 = /平均值:\s*\d+\.\d+\/(\d+\.\d+)\s*D/g; const regex2 = /MV:\s*\d+\.\d+\/(\d+\.\d+)\s*D/g; const K2_D = [...this.extractData.matchAll(regex1)].map(match => match[1].trim()).length ? [...this.extractData.matchAll(regex1)].map(match => match[1].trim()) : [...this.extractData.matchAll(regex2)].map(match => match[1].trim()); console.log('examTime',examTime); data = [{ AL: AL.length === 2 ? AL[0] : '', K1_D: K1_D.length === 2 ? K1_D[0] : '', K2_D: K1_D.length === 2 ? K2_D[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: 'OD' },{ AL: AL.length === 2 ? AL[1] : '', K1_D: K1_D.length === 2 ? K1_D[1] : '', K2_D: K1_D.length === 2 ? K2_D[1] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: 'OS' }, { AL: AL.length === 1 ? AL[0] : '', K1_D: K1_D.length === 1 ? K1_D[0] : '', K2_D: K1_D.length === 1 ? K2_D[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: '' }] console.log(data) return data; } /** * master500 */ master5002() { let data = {} const examTime = this.regexKey('检查日期:', 'n:') const AL = this.regexKey('AL:', 'mm') const K1_D = this.regexKey('K1:', 'D') const K1_A = this.regexKeyB('K1','@', '°') const K1_R = this.regexKeyB('K1', '/', 'mm') const K2_D = this.regexKey('K2:', 'D') const K2_A = this.regexKeyB('K2','@', '°') const K2_R = this.regexKeyB('K2', '/', 'mm') const ACD = this.regexKey('ACD:', 'mm') const Cyl = this.regexKey('Cyl.:', 'D') const Cyl_A = this.regexKeyB('Cyl.:','@', '°') data = [ { AL: AL.length === 2 ? AL[0] : '', K1_D: K1_D.length === 2 ? K1_D[0] : '', K1_A: K1_A.length === 2 ? K1_A[0] : '', K1_R: K1_R.length === 2 ? K1_R[0] : '', K2_D: K2_D.length === 2 ? K2_D[0] : '', K2_A: K2_A.length === 2 ? K2_A[0] : '', K2_R: K2_R.length === 2 ? K2_R[0] : '', ACD: ACD.length === 2 ? ACD[0] : '', Cyl: Cyl.length === 2 ? Cyl[0] : '', Cyl_A: Cyl_A.length === 2 ? Cyl_A[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: 'OD' },{ AL: AL.length === 2 ? AL[1] : '', K1_D: K1_D.length === 2 ? K1_D[1] : '', K1_A: K1_A.length === 2 ? K1_A[1] : '', K1_R: K1_R.length === 2 ? K1_R[1] : '', K2_D: K2_D.length === 2 ? K2_D[1] : '', K2_A: K2_A.length === 2 ? K2_A[1] : '', K2_R: K2_R.length === 2 ? K2_R[1] : '', ACD: ACD.length === 2 ? ACD[1] : '', Cyl: Cyl.length === 2 ? Cyl[1] : '', Cyl_A: Cyl_A.length === 2 ? Cyl_A[1] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: 'OS' },{ AL: AL.length === 1 ? AL[0] : '', K1_D: K1_D.length === 1 ? K1_D[0] : '', K1_A: K1_A.length === 1 ? K1_A[0] : '', K1_R: K1_R.length === 1 ? K1_R[0] : '', K2_D: K2_D.length === 1 ? K2_D[0] : '', K2_A: K2_A.length === 1 ? K2_A[0] : '', K2_R: K2_R.length === 1 ? K2_R[0] : '', ACD: ACD.length === 1 ? ACD[0] : '', Cyl: Cyl.length === 1 ? Cyl[0] : '', Cyl_A: Cyl_A.length === 1 ? Cyl_A[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: '' }] console.log(data) return data; } /** * master700 */ master700() { let data = {} const examTime = this.regexKey('测量日期:', 'n:') const AL = this.regexKey('AL:', 'mm') const WTW = this.regexKey('WTW:', 'mm') data = [ { AL: AL.length === 2 ? AL[0] : '', WTW: WTW.length === 2 ? WTW[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: 'OD' },{ AL: AL.length === 2 ? AL[1] : '', WTW: WTW.length === 2 ? WTW[1] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: 'OS' },{ AL: AL.length === 1 ? AL[0] : '', WTW: WTW.length === 1 ? WTW[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: '' }] console.log(data) return data; } /** * OPTIKON Keratron Scout */ corneal() { let data = {} const regex2 = /Date of Exam\.: (\d{4}\/\d{2}\/\d{2})/; const examDate = this.extractData.match(regex2); console.log('examDate',examDate[1]); const regex3 = /Time of Exam\.: (\d{2}:\d{2}:\d{2})/; const examTime = this.extractData.match(regex3); console.log('examTime',examTime[1]); //OD const CF_K1_D_OD = this.regexKey('OD-Steep:', 'D') const CF_K1_A_OD = this.regexKeyD()[0] const CF_K2_D_OD = this.regexKey('OD-Flat:', 'D') const CF_K2_A_OD = this.regexKeyD()[1] console.log('CF_K1_A_OD',CF_K1_A_OD); console.log('CF_K1_D_OD',CF_K1_D_OD); console.log('CF_K2_A_OD',CF_K2_A_OD); console.log('CF_K2_D_OD',CF_K2_D_OD); const CF_Offset_MM = this.regexKey('Off:','mm') // OS const CF_K1_D_OS = this.regexKey('OS-Steep:', 'D') const CF_K1_A_OS = this.regexKeyE()[0] const CF_K2_D_OS = this.regexKey('OS-Flat:', 'D') const CF_K2_A_OS = this.regexKeyE()[1] const CF_Offset_A = this.regexKeyF() console.log('CF_Offset_A',CF_Offset_A); data = [ { CF_K1_D: CF_K1_D_OD.length === 1 ? CF_K1_D_OD[0] : '', CF_K1_A: CF_K1_A_OD ? CF_K1_A_OD : '', CF_K2_D: CF_K2_D_OD.length === 1 ? CF_K2_D_OD[0] : '', CF_K2_A: CF_K2_A_OD ? CF_K2_A_OD : '', CF_Offset_MM: CF_Offset_MM.length === 2 ? CF_Offset_MM[0] : '', CF_Offset_A: CF_Offset_A.length === 2 ? CF_Offset_A[0] : '', examTime: examDate[1].replace(/\//g, '-') + ' ' + examTime[1], eye_type: 'OD' }, { CF_K1_D: CF_K1_D_OS.length === 1 ? CF_K1_D_OS[0] : '', CF_K1_A: CF_K1_A_OS ? CF_K1_A_OS : '', CF_K2_D: CF_K2_D_OS.length === 1 ? CF_K2_D_OS[0] : '', CF_K2_A: CF_K2_A_OS ? CF_K2_A_OS : '', CF_Offset_MM: CF_Offset_MM.length === 2 ? CF_Offset_MM[1] : '', CF_Offset_A: CF_Offset_A.length === 2 ? CF_Offset_A[1] : '', examTime: examDate[1].replace(/\//g, '-') + ' ' + examTime[1], eye_type: 'OS' }, ] console.log('data',data) return data; } /** * UBM */ extractValidDates(text) { const dateRegex = /\b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])\b/g; const potentialDates = text.match(dateRegex) || []; return potentialDates.filter(dateStr => { const date = new Date(dateStr); return !isNaN(date.getTime()); // 检查是否是有效日期 }); } ubmData(){ let data = {} const sourceData = JSON.parse(JSON.stringify(this.extractData)) this.extractData = this.extractData.replace(/[\s\n]+/g, ''); console.log(this.extractData); const examTime = this.extractValidDates(sourceData) const UBN_QFSD = this.regexKey('前房深度约为', 'mm') const GDG_SP = this.regexKey('水平两睫状沟间距离约', 'mm') const GDG_CZ = this.regexKey('垂直两睫状沟间距离约', 'mm') const JTQG = this.regexKey('矢高约为', 'mm') const eye_type = this.extractData.match(/右眼/) console.log('eye_type',this.extractData.match(/右眼/)); data = [{ UBN_QFSD: UBN_QFSD.length ? UBN_QFSD[0] : '', GDG_SP: GDG_SP.length ? GDG_SP[0] : '', GDG_CZ: GDG_CZ.length ? GDG_CZ[0] : '', JTQG: JTQG.length ? JTQG[0] : '', examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', eye_type: eye_type.length ? eye_type[0] : '', },{ // AL: AL.length === 2 ? AL[1] : '', // K1_D: K1_D.length === 2 ? K1_D[1] : '', // K2_D: K1_D.length === 2 ? K2_D[1] : '', // examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', // eye_type: 'OS' }, { // AL: AL.length === 1 ? AL[0] : '', // K1_D: K1_D.length === 1 ? K1_D[0] : '', // K2_D: K1_D.length === 1 ? K2_D[0] : '', // examTime: examTime.length === 1 ? examTime[0].replace(/\//g, '-') + ' 00:00:00' : '', // eye_type: '' }] console.log(data) return data; } } window.dealData = (msg, device) => { return new ParseDataType(msg, device).analysis() }