sdsd
This commit is contained in:
parent
49c0136bff
commit
8ef6a6693e
56
api/ocr.js
56
api/ocr.js
@ -28,7 +28,7 @@ export const getOcr = (url) => {
|
|||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
success(res) {
|
success(res) {
|
||||||
const data = parseMarkdownTable(res.data.choices[0].message.content)
|
const data = parseOcrResult(res.data.choices[0].message.content)
|
||||||
resolve(data);
|
resolve(data);
|
||||||
},
|
},
|
||||||
fail(err) {
|
fail(err) {
|
||||||
@ -63,3 +63,57 @@ function parseMarkdownTable(md) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析类似 ```json ... ``` 格式的字符串,提取检测项目数组
|
||||||
|
* @param {string} str
|
||||||
|
* @returns {Array<Object>}
|
||||||
|
*/
|
||||||
|
function parseJsonBlock(str) {
|
||||||
|
// 去除包裹的代码块标记
|
||||||
|
const jsonStr = str.replace(/^[\s`]*```json[\s`]*|```$/g, '').replace(/↵/g, '\n').trim();
|
||||||
|
|
||||||
|
// 用正则提取所有 "key": "value"
|
||||||
|
const regex = /"([^"]+)":\s*"([^"]*)"/g;
|
||||||
|
const pairs = [];
|
||||||
|
let match;
|
||||||
|
while ((match = regex.exec(jsonStr)) !== null) {
|
||||||
|
pairs.push([match[1], match[2]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按“序号”分组
|
||||||
|
const items = [];
|
||||||
|
let current = {};
|
||||||
|
const itemFields = ['序号', '项目名称', '缩写', '结果', '单位', '参考区间', '测定方法'];
|
||||||
|
pairs.forEach(([key, value]) => {
|
||||||
|
if (key === '序号' && Object.keys(current).length > 0) {
|
||||||
|
items.push({ ...current });
|
||||||
|
current = {};
|
||||||
|
}
|
||||||
|
if (itemFields.includes(key)) {
|
||||||
|
current[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (Object.keys(current).length > 0) {
|
||||||
|
items.push({ ...current });
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动判断OCR返回内容格式并调用对应解析方法
|
||||||
|
* @param {string} content
|
||||||
|
* @returns {Array<Object>}
|
||||||
|
*/
|
||||||
|
function parseOcrResult(content) {
|
||||||
|
// 判断是否为JSON代码块
|
||||||
|
if (/^```json/.test(content.trim())) {
|
||||||
|
return parseJsonBlock(content);
|
||||||
|
}
|
||||||
|
// 判断是否为Markdown表格(以|开头,且有---分隔行)
|
||||||
|
if (/\|.*\|/.test(content) && /\|[\s\-:|]+\|/.test(content)) {
|
||||||
|
return parseMarkdownTable(content);
|
||||||
|
}
|
||||||
|
// 其它情况返回空数组或原始内容
|
||||||
|
return [];
|
||||||
|
}
|
||||||
@ -316,14 +316,18 @@ Page({
|
|||||||
console.error('上传失败:', error); // 输出具体的错误信息
|
console.error('上传失败:', error); // 输出具体的错误信息
|
||||||
} else {
|
} else {
|
||||||
// getOcr(data)
|
// getOcr(data)
|
||||||
wx.showToast({ title: '上传成功!', icon: 'success' });
|
wx.showToast({ title: '上传成功,正在识别内容!', icon: 'success' });
|
||||||
const { mode } = e.currentTarget.dataset;
|
const { mode } = e.currentTarget.dataset;
|
||||||
let arr = this.data.form[mode]
|
let arr = this.data.form[mode]
|
||||||
arr.unshift(data)
|
arr.unshift(data)
|
||||||
this.setData({
|
this.setData({
|
||||||
[`form.${mode}`]: arr
|
[`form.${mode}`]: arr
|
||||||
})
|
})
|
||||||
getOcr(data)
|
getOcr(data).then(ocrRes => {
|
||||||
|
console.log(ocrRes)
|
||||||
|
wx.showToast({ title: '识别完成!', icon: 'success' })
|
||||||
|
this.setFormData(ocrRes, mode)
|
||||||
|
})
|
||||||
console.log('上传成功:', data); // 输出上传成功后的数据
|
console.log('上传成功:', data); // 输出上传成功后的数据
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -407,6 +411,71 @@ Page({
|
|||||||
form: data
|
form: data
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 遍历识别结果,填充字段
|
||||||
|
setFormData(ocrs, mode) {
|
||||||
|
console.log(ocrs, mode)
|
||||||
|
ocrs.forEach(ocr => {
|
||||||
|
console.log(ocr['项目名称'], ocr['结果'])
|
||||||
|
// 血常规
|
||||||
|
if (mode == 'blood_routine_image') {
|
||||||
|
if (ocr['项目名称'] == '血红蛋白') {
|
||||||
|
this.setData({
|
||||||
|
[`form.hemoglobin`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 凝血功能
|
||||||
|
if (mode == 'coagulation_function_image') {
|
||||||
|
|
||||||
|
if (ocr['项目名称'] == '凝血酶原时间') {
|
||||||
|
this.setData({
|
||||||
|
[`form.pt`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (ocr['项目名称'] == '凝血酶原活动度') {
|
||||||
|
this.setData({
|
||||||
|
[`form.pta`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (ocr['项目名称'] == '国际标准化比值') {
|
||||||
|
this.setData({
|
||||||
|
[`form.inr`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (ocr['项目名称'] == '活化部分凝血活酶时间') {
|
||||||
|
this.setData({
|
||||||
|
[`form.aptt`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (ocr['项目名称'] == '凝血酶时间') {
|
||||||
|
this.setData({
|
||||||
|
[`form.tt`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (ocr['项目名称'] == '纤维蛋白原') {
|
||||||
|
this.setData({
|
||||||
|
[`form.fib`]: ocr['结果']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 肝功能
|
||||||
|
if (mode == 'liver_function_image') {
|
||||||
|
|
||||||
|
}
|
||||||
|
// 营养指数
|
||||||
|
if (mode == 'nutritional_indicator_image') {
|
||||||
|
|
||||||
|
}
|
||||||
|
// B超
|
||||||
|
if (mode == 'b_mode_image') {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生命周期函数--监听页面初次渲染完成
|
* 生命周期函数--监听页面初次渲染完成
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -91,7 +91,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">总胆红素(µmol/L)</view>
|
<view class="input-example__label">总胆红素(µmol/L)</view>
|
||||||
<t-input placeholder="请输入" size="small" bind:change="onInput" value="{{form.total_bilirubin}}" data-key="total_bilirubin" borderless="{{true}}" style="{{style}}"
|
<t-input placeholder="请输入" size="small" bind:change="onInput" value="{{form.total_bilirubin}}" data-key="total_bilirubin" borderless="{{true}}" style="{{style}}"
|
||||||
type="digit" />
|
type="digit" />
|
||||||
</view>
|
</view>
|
||||||
@ -100,7 +100,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">直接胆红素(µmol/L)</view>
|
<view class="input-example__label">直接胆红素(µmol/L)</view>
|
||||||
<t-input placeholder="请输入" bind:change="onInput" value="{{form.direct_bilirubin}}" data-key="direct_bilirubin" borderless="{{true}}" style="{{style}}"
|
<t-input placeholder="请输入" bind:change="onInput" value="{{form.direct_bilirubin}}" data-key="direct_bilirubin" borderless="{{true}}" style="{{style}}"
|
||||||
type="digit" />
|
type="digit" />
|
||||||
</view>
|
</view>
|
||||||
@ -354,7 +354,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">25(OH)D3 (ng/ml)</view>
|
<view class="input-example__label">25(OH)D3(ng/ml)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.oh_d3}}" data-key="oh_d3" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.oh_d3}}" data-key="oh_d3" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -362,7 +362,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">25(OH)D2 (ng/ml)</view>
|
<view class="input-example__label">25(OH)D2(ng/ml)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.oh_d2}}" data-key="oh_d2" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.oh_d2}}" data-key="oh_d2" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -370,7 +370,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">25(OH)D (ng/ml)</view>
|
<view class="input-example__label">25(OH)D(ng/ml)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.oh_d}}" data-key="oh_d" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.oh_d}}" data-key="oh_d" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -378,7 +378,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">维生素A (ng/ml)</view>
|
<view class="input-example__label">维生素A(ng/ml)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.vitamin_a}}" data-key="vitamin_a" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.vitamin_a}}" data-key="vitamin_a" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -386,7 +386,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">维生素K (ng/ml)</view>
|
<view class="input-example__label">维生素K(ng/ml)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.vitamin_k}}" data-key="vitamin_k" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.vitamin_k}}" data-key="vitamin_k" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -394,7 +394,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">维生素E (ng/ml)</view>
|
<view class="input-example__label">维生素E(ng/ml)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.vitamin_e}}" data-key="vitamin_e" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.vitamin_e}}" data-key="vitamin_e" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -433,7 +433,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">肝肋下(mm)</view>
|
<view class="input-example__label">肝肋下(mm)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.under_the_liver_rib}}" data-key="under_the_liver_rib" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.under_the_liver_rib}}" data-key="under_the_liver_rib" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -441,7 +441,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">肝剑突下(mm)</view>
|
<view class="input-example__label">肝剑突下(mm)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.under_the_xiphoid_liver}}" data-key="under_the_xiphoid_liver" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.under_the_xiphoid_liver}}" data-key="under_the_xiphoid_liver" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -449,7 +449,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">脾肋下(mm)</view>
|
<view class="input-example__label">脾肋下(mm)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.spleen_rib_area}}" data-key="spleen_rib_area" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.spleen_rib_area}}" data-key="spleen_rib_area" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -457,7 +457,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">门静脉主干内径(mm)</view>
|
<view class="input-example__label">门静脉主干内径(mm)</view>
|
||||||
<t-input placeholder="请输入" bind:change="onInput" value="{{form.main_portal_vein}}" data-key="main_portal_vein" borderless="{{true}}" style="{{style}}" />
|
<t-input placeholder="请输入" bind:change="onInput" value="{{form.main_portal_vein}}" data-key="main_portal_vein" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -473,7 +473,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">胆囊大小(mm)</view>
|
<view class="input-example__label">胆囊大小(mm)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.gallbladder_size}}" data-key="gallbladder_size" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.gallbladder_size}}" data-key="gallbladder_size" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -481,7 +481,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">胆总管(mm)</view>
|
<view class="input-example__label">胆总管(mm)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.common_bile_duct}}" data-key="common_bile_duct" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.common_bile_duct}}" data-key="common_bile_duct" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -489,7 +489,7 @@
|
|||||||
<t-col span="12">
|
<t-col span="12">
|
||||||
<view class="dark">
|
<view class="dark">
|
||||||
<view class="input-example">
|
<view class="input-example">
|
||||||
<view class="input-example__label">纤维块大小(mm)</view>
|
<view class="input-example__label">纤维块大小(mm)</view>
|
||||||
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.fiber_block_size}}" data-key="fiber_block_size" size="small" borderless="{{true}}" style="{{style}}" />
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.fiber_block_size}}" data-key="fiber_block_size" size="small" borderless="{{true}}" style="{{style}}" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -532,6 +532,30 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</t-col>
|
</t-col>
|
||||||
|
<t-col span="12">
|
||||||
|
<view class="dark">
|
||||||
|
<view class="input-example">
|
||||||
|
<view class="input-example__label">弹性成像最小值(kPa)</view>
|
||||||
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.elastography_median}}" data-key="elastography_median" borderless="{{true}}" style="{{style}}" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</t-col>
|
||||||
|
<t-col span="12">
|
||||||
|
<view class="dark">
|
||||||
|
<view class="input-example">
|
||||||
|
<view class="input-example__label">弹性成像最大值(kPa)</view>
|
||||||
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.elastography_maximum}}" data-key="elastography_maximum" borderless="{{true}}" style="{{style}}" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</t-col>
|
||||||
|
<t-col span="12">
|
||||||
|
<view class="dark">
|
||||||
|
<view class="input-example">
|
||||||
|
<view class="input-example__label">弹性成像中位数(kPa)</view>
|
||||||
|
<t-input type="digit" placeholder="请输入" bind:change="onInput" value="{{form.elastography_median}}" data-key="elastography_median" borderless="{{true}}" style="{{style}}" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</t-col>
|
||||||
</t-row>
|
</t-row>
|
||||||
</view>
|
</view>
|
||||||
<view class="follow-item">
|
<view class="follow-item">
|
||||||
|
|||||||
0
pages/followUp/ocrDate.js
Normal file
0
pages/followUp/ocrDate.js
Normal file
Loading…
x
Reference in New Issue
Block a user