示例#1
0
def _get_opid(lisResult):
    opName = lisResult.OPERATOR_NAME  # 报告医生
    auditName = lisResult.AUDIT_NAME if lisResult.AUDIT_NAME else lisResult.OPERATOR_NAME  # 审核医生,如果审核医生为空,则使用报告医生

    log.info('获取到报告医生:{}  审核医生:{}'.format(opName, auditName))

    opUser = tjAssert(getUserInfo(_get_login_name(opName), opName))

    opId = opUser['msg']['userId']

    log.info("获取报告医生id:{}  用户名:{}".format(opId, opName))

    if not auditName:
        raise TJException('没有发现有效的审核医生')

    auditUser = tjAssert(getUserInfo(_get_login_name(auditName), auditName))

    auditId = auditUser['msg']['userId']

    log.info("获取审核医生id:{}  用户名:{}".format(auditId, auditName))
    return opId, auditId
def _confirmRisRegData(tree):
    log.info("开始执行{}方法".format("_confirmRisRegData"))

    # 获取预约号 ORDER_ID
    orderId = getElementText(tree, "//ORDER_ID")

    # 获取确认的部位编码
    itemCode = getElementText(tree, "//EXAM_ITEMCODE")

    # 获取确认医生姓名(如果用户编号,即id和体检中心的一致可否)
    doctorName = getElementText(tree, "//CONFIRM_DOCTOR_NAME")

    log.info("获取到预约号:{} 需要确认的部位id:{}  确认医生姓名:{}".format(
        orderId, itemCode, doctorName))

    # 尝试登录体检系统
    log.info("开始尝试登录体检系统...")

    result = tjAssert(login())

    log.info(result['msg'])

    # 尝试用得到的真实用户获取用户id
    log.info("尝试用得到的真实用户获取用户id...")

    result = tjAssert(getUserByRealName(doctorName))

    user = result['msg']

    log.info("获取用户id:{}  用户名:{}".format(user['id'], user['name']))

    # 开始登记项目组(使项目组变为登入状态)
    log.info("开始登记项目组")
    result = tjAssert(loginAssems(orderId, itemCode, user['id']))

    log.info(result['msg'])

    return tostring(setHeadXML(getReturnXML(), '0000'))
def _getRisRegData(tree):
    log.info("开始执行{}方法".format("_getRisRegData"))
    # 获取预约号 ORDER_ID
    orderId = getElementText(tree, "//ORDER_ID")
    # 获取医技类型编码
    risTypeCode = getElementText(tree, "//RISTYPE_CODE")
    log.info("获取到预约号为:{0}  医技类型编码为:{1}".format(orderId, risTypeCode))

    # 对应体检科室类型
    department = _getDepartment(risTypeCode)

    # 尝试登录体检系统
    log.info("开始尝试登录体检系统...")

    result = tjAssert(login())

    log.info(result['msg'])

    # 从体检系统中获取本科室的检查信息
    log.info("开始从体检系统中获取体检信息,科室为{},预约号为:{}".format(department, orderId))

    msg = tjAssert(loadExam(department, orderId))

    # 获取体检结果
    exam = msg['msg']

    # 获取体检科室列表
    assems = exam['assems']

    tree = getReturnXML()

    table = addElement(tree, '//ROOT/DETAIL', 'TABLE')

    # 开始操作返回的结果
    for assem in assems:
        record = addElementByNode(table, 'RECORD')
        # 体检号 EXAM_NO
        addElementByNode(record, 'EXAM_NO', exam['examNo'])
        # 预约号 ORDER_ID
        addElementByNode(record, 'ORDER_ID', exam['orderId'])
        # 姓名 USERNAME
        addElementByNode(record, 'USERNAME', exam['username'])
        # 出生日期 BIRTHDAY
        addElementByNode(record, 'BIRTHDAY',
                         getBirthday(exam['birthday'], exam['age']))
        # 性别 SEX_NAME
        addElementByNode(record, 'SEX_NAME', exam['sexVal'])

        # 年龄 AGE
        addElementByNode(record, 'AGE', exam['age'])

        # 手机 TELEPHONE
        addElementByNode(record, 'TELEPHONE', exam['telephone'])

        # 地址 address
        addElementByNode(record, 'ADDRESS', exam['address'])

        # 医技类型编号 RISTYPE_CODE
        addElementByNode(record, 'RISTYPE_CODE', risTypeCode)

        # 医技类型名称 RISTYPE_NAME
        addElementByNode(record, 'RISTYPE_NAME', getBaseName(risTypeCode))

        # 检查部位名称 EXAM_ITEMNAME
        addElementByNode(record, 'EXAM_ITEMNAME', assem['assemName'])

        # 检查部位ID EXAM_ITEMCODE
        addElementByNode(record, 'EXAM_ITEMCODE', assem['assemId'])

        # 申请医生 REQ_DOCTOR
        addElementByNode(record, 'REQ_DOCTOR', '体检中心')

        # 申请日期 REQ_DATE
        addElementByNode(
            record, 'REQ_DATE',
            time.strftime('%Y-%m-%d', time.localtime(time.time())))

    setHeadXML(tree, '0000')

    return tostring(tree)
def _saveLisReport(tree):
    log.info("开始执行{}方法".format("_saveLisReport"))

    barcodeId = getElementText(tree, "//BARCODE_ID")
    log.info("获取条码号:{}".format(barcodeId))

    orderId = getElementText(tree, '//ORDER_ID')
    log.info("获取预约号:{}".format(orderId))

    operatorCode = getElementText(tree, "//OPERATOR_ID")
    log.info("获取检验者ID:{}".format(operatorCode))

    operatorName = getElementText(tree, "//OPERATOR_NAME")
    log.info("获取检验者姓名:{}".format(operatorName))

    auditCode = getElementText(tree, "//AUDIT_ID")
    log.info("获取审核者ID:{}".format(auditCode))

    auditName = getElementText(tree, "//AUDIT_NAME")
    log.info("获取审核者姓名:{}".format(auditName))

    # 获取项目结果
    log.info("开始获取项目结果...")

    records = getElementList(tree, "//ROOT/DETAIL/TABLE/RECORD")

    acceptAssems = {}

    acceptElements = {}

    for record in records:

        lisElementId = getElementText(record, "LIS_ELEMENT_ID")
        lisElementName = getElementText(record, "LIS_ELEMENT_NAME")
        result = getElementText(record, "CONTENT_RESULT")
        unit = getElementText(record, "RESULT_UNIT")
        # fe getElementText(record,"//FERENCE_VALUE")
        lower = getElementText(record, "FERENCE_LOWER_LIMIT")
        upper = getElementText(record, "FERENCE_UPPER_LIMIT")
        positiveSymbol = getElementText(record, "POSITIVE_SYMBOL")
        criticalSymbol = getElementText(record, "CRITICAL_VALUES_SYMBOL")
        fkKey = getElementText(record, "FK_KEY")

        log.info('fkey:{}'.format(fkKey))

        if fkKey is None:
            raise XMLException('项目:{}  {}的fkKey值为空.'.format(
                lisElementId, lisElementName))

        # 解析项目组ID和小项ID
        keys = fkKey.split('|')
        if len(keys) != 3:
            raise TJException("无效的FK_KEY:{} 条码号:{} 预约号:{}  项目:{}".format(
                fkKey, barcodeId, orderId, lisElementName))

        assemId = keys[1]
        elementId = keys[2]

        if assemId not in acceptAssems.keys():
            acceptAssems[assemId] = []

        item = {}

        item['lisElementId'] = lisElementId
        item['lisElementName'] = lisElementName
        item['result'] = result
        item['unit'] = unit
        item['lower'] = lower
        item['upper'] = upper
        item['positiveSymbol'] = positiveSymbol
        item['criticalSymbol'] = criticalSymbol
        item['elementId'] = elementId

        acceptAssems[assemId].append(item)

        acceptElements[elementId] = item

    # 尝试登录体检系统
    log.info("开始尝试登录体检系统...")

    result = tjAssert(login())

    log.info(result['msg'])

    # 获取检验医生的ID
    result = tjAssert(getUserByRealName(operatorName))
    operatorId = result['msg']['id']
    log.info("获取检验医生的ID为:{}".format(operatorId))

    # 获取审核医生ID
    result = tjAssert(getUserByRealName(auditName))
    auditId = result['msg']['id']
    log.info("获取审核者医生ID为:{}".format(auditId))

    # 获取体检项目
    # 从体检系统中获取本科室的检查信息

    for key in acceptAssems.keys():
        log.info("开始从体检系统中获取体检信息,科室为{},预约号为:{},项目组ID:{}".format(
            JYK, orderId, key))
        msg = tjAssert(loadExam(JYK, orderId, filterAssemIds=key))
        exam = msg['msg']

        lisDatas = {
            'orderId': orderId,
            'elementAssemId': key,
            'departmentId': JYK,
            'sampleOpId': operatorId,
            'opId': auditId,
            'items': []
        }

        assem = exam['assems'][0]

        elements = assem['elements']

        log.info(acceptElements)

        for e in elements:
            ekey = str(e['elementId'])
            if ekey not in acceptElements.keys():
                # 这里报异常,先去掉,无法报存
                raise TJException(
                    "管号为:{}  预约号:{}  项目组:{} 项目:{}在审核的结果中不存在,不能保存到检验结果".format(
                        barcodeId, orderId, assem['assemName'],
                        e['elementName']))
                # continue

            acceptElement = acceptElements[ekey]

            lisElement = {}

            lisElement['elementId'] = e['elementId']
            lisElement['checkElementResult'] = acceptElement['result']
            lisElement['ferenceLower'] = acceptElement['lower']
            lisElement['ferenceUpper'] = acceptElement['upper']
            lisElement['unit'] = acceptElement['unit']
            lisElement['resultType'] = e['resultType']
            lisElement['referenceType'] = '1'  # e['refType']

            # 危机值的标识?
            lisElement['criticalValuesSymbol'] = acceptElement[
                'criticalSymbol']

            # 阳性标识,如何表达呢?
            if acceptElement['positiveSymbol'] == '↑':
                lisElement['positiveSymbol'] = '高'
            elif acceptElement['positiveSymbol'] == '↓':
                lisElement['positiveSymbol'] = '低'
            else:
                lisElement['positiveSymbol'] = None

            lisDatas['items'].append(lisElement)

        # 开始保存LIS结果
        examData = json.dumps(lisDatas)
        log.info(examData)

        log.info("开始保存LIS结果....")
        result = tjAssert(saveLisExamData(examData))
        log.info(result['msg'])

    return tostring(setHeadXML(getReturnXML(), '0000'))
def _saveRisReport(tree):
    log.info("开始执行{}方法".format("_saveRisReport"))

    orderId = getElementText(tree, '//ORDER_ID')
    log.info("获取预约号:{}".format(orderId))

    risTypeCode = getElementText(tree, '//RISTYPE_CODE')
    log.info("获取医技类型编码:{}".format(risTypeCode))

    # 检查项目,大项ID
    examItemCode = getElementText(tree, '//EXAM_ITEMCODE')
    log.info("获取项目组id:{}".format(examItemCode))

    examItemName = getElementText(tree, '//EXAM_ITEMNAME')
    log.info("获取项目组名字:{}".format(examItemName))

    reportDoctorCode = getElementText(tree, '//CONFIRM_DOCTOR_CODE')
    log.info("获取报告医生编码:{}".format(reportDoctorCode))

    reportDoctorName = getElementText(tree, '//REPORT_DOCTOR_NAME')
    log.info("获取报告医生名字:{}".format(reportDoctorName))

    confirmDoctorCode = getElementText(tree, '//CONFIRM_DOCTOR_CODE')
    log.info("获取审核医生编码:{}".format(confirmDoctorCode))

    confirmDoctorName = getElementText(tree, '//CONFIRM_DOCTOR_NAME')
    log.info("获取审核医生姓名:{}".format(confirmDoctorName))

    findings = getElementText(tree, "//FINDINGS")
    log.info("获取检查所见信息:{}".format(findings))

    impression = getElementText(tree, "//IMPRESSION")
    log.info("获取诊断结果:{}".format(impression))

    sickFlag = getElementText(tree, "//SICK_FLAG")
    log.info("获取疾病标识:{}".format(sickFlag))

    sickName = getElementText(tree, "//SICK_NAME")
    log.info("获取疾病名称:{}".format(sickName))

    # 对应体检科室类型
    department = _getDepartment(risTypeCode)

    # 尝试登录体检系统
    log.info("开始尝试登录体检系统...")

    result = tjAssert(login())

    log.info(result['msg'])

    # 获取报告医生的ID
    result = tjAssert(getUserByRealName(reportDoctorName))
    reporterId = result['msg']['id']
    log.info("获取报告医生ID为:{}".format(reporterId))

    # 获取审核医生ID
    result = tjAssert(getUserByRealName(confirmDoctorName))
    confirmId = result['msg']['id']
    log.info("获取审核者医生ID为:{}".format(confirmId))

    # 从体检系统中获取本科室的检查信息
    log.info("开始从体检系统中获取体检信息,科室为{},预约号为:{},项目组ID:{}".format(
        department, orderId, examItemCode))

    msg = tjAssert(loadExam(department, orderId, filterAssemIds=examItemCode))

    exam = msg['msg']

    # 初始化保存数据
    saveExam = initSaveExam(exam, department, confirmId, reporterId)

    # 小项结果
    fs = {'others': findings}
    addElementResult(saveExam,
                     exam=exam,
                     opId=reporterId,
                     elementAssemId=examItemCode,
                     **fs)

    # 结论部分,开始拆分影印字段
    log.info('获取结论...')
    # summaries = impression.split('\t') #试着用4个字符串解析换行?
    # summaries = impression.splitlines()
    #
    # summaries =  re.split(r'[\d]+\.',impression)

    imp = '' if impression is None else impression
    if imp.strip() == '':
        raise XMLException('结论不能为空,保存RIS结果失败')

    summaries = re.split(r'\t|\n', imp)

    for s in summaries:
        summary = re.sub(r'^[\d]+\.', '', s.strip())

        # summary = s.strip()

        if len(summary) == 0:
            continue

        log.info('获取结论:{}'.format(summary))

        writeSymbol = None
        diseaseCode = None
        if summary.find('未见异常') >= 0 or summary.find('未见明显异常') >= 0:
            writeSymbol = '03'
        else:
            result = getDiseaseByName(summary)
            if result is None:
                writeSymbol = '02'
            else:
                writeSymbol = '01'
                diseaseCode = result['msg']['id']
        log.info("获取诊断方式:{},疾病名称:{},疾病id:{}".format(writeSymbol, summary,
                                                    diseaseCode))
        addDisease(saveExam,
                   exam=exam,
                   deptId=department,
                   opId=reporterId,
                   writeSymbol=writeSymbol,
                   diseaseName=summary,
                   diseaseCode=diseaseCode,
                   elementAssemId=examItemCode)

    # 重大阳性
    if sickFlag == '1':
        addPosReport(saveExam,
                     content=findings,
                     advice=sickName,
                     opId=reporterId)

    # 开始提交分科结果
    examData = json.dumps(saveExam)
    log.info(examData)
    log.info('开始提交分科结果...')
    result = tjAssert(saveExamData(examData))
    log.info(result['msg'])

    return tostring(setHeadXML(getReturnXML(), '0000'))
示例#6
0
def transLis(departmentId, order_id, assemId, lis_result_dict):
    """
    上传LIS数据到体检系统中
    :param departmentId: 科室ID
    :param assemId:项目组ID
    :lis_result_dict:项目结果字典
    :return:
    """

    lis_result_key_set = set()
    for key in lis_result_dict.keys():
        lis_result_key_set.add(key)

    # 开始尝试登录到体检系统
    log.info('开始尝试登录体检系统,用户名:{} 密码:{}'.format(app.config['JK_EXAM_USERNAME'], app.config['JK_EXAM_PASSWORD']))
    result = tjAssert(loginByUserNamePwd(app.config['JK_EXAM_USERNAME'], app.config['JK_EXAM_PASSWORD']))
    log.info('开始根据科室、项目组、预约号获取体检信息,科室ID:{} 预约号:{}  项目组ID:{}'.format(departmentId, order_id, assemId))
    msg = tjAssert(loadExam(dept=departmentId, orderId=order_id, filterAssemIds=assemId))

    log.info('开始检查以及组装体检项目...')

    exam = msg['msg']

    assem = exam['assems'][0]

    elements = assem['elements']

    # 使用外键组成项目字典
    examElementDict = {}
    examElementSet = set()

    for element in elements:
        extCode = element['extSysControlCode']
        if not extCode:
            raise TJException('项目名:{} 的系统对照为空'.format(element['elementName']))

        # 开始分割项目对照码,一个小项,可以有多个对照码,使用,,|^,进行分割
        keys = re.split(r',|,|\^|\|', extCode)
        for key in keys:
            if key:
                code = key.strip()
                if code:
                    examElementDict[code] = element
                    examElementSet.add(code)

    # 计算体检检查项目及lis项目结果列表的交集
    both_set = set.intersection(examElementSet, lis_result_key_set)

    # 开始对小项进行标记
    for code in both_set:
        examElementDict[code]['bingo'] = True

    errMsgs = []
    log.info('开始检查哪些项目,在HIS中没有结果...')
    # 开始检查哪些项目没有结果
    for element in elements:
        if 'bingo' not in element.keys():
            errMsg = '在LIS提供的项目列表中,未发现项目id:{} 项目名:{} 项目对照:{}的项目'.format(element['elementId'],
                                                                        element['elementName'],
                                                                        element['extSysControlCode'])
            errMsgs.append(errMsg)

    if len(errMsgs) > 0:
        raise TJException(';'.join(errMsgs))

    log.info('开始生成LIS体检项目...')

    lisDatas = {

        'orderId': order_id,
        'elementAssemId': assemId,
        'departmentId': departmentId,
        'sampleOpId': None,  # 报告人
        'opId': None,  # 审核人
        'items': []
    }

    c = 0

    item_results = []

    for code in both_set:
        try:
            examElement = examElementDict[code]

            hisLisElement = lis_result_dict[code]

            if c == 0:
                sampleOpId, opId = _get_opid(hisLisElement)
                lisDatas['sampleOpId'] = sampleOpId
                lisDatas['opId'] = opId

            lisElement = {}
            lisElement['elementId'] = examElement['elementId']
            lisElement[
                'checkElementResult'] = hisLisElement.CONTENT_RESULT.strip() if hisLisElement.CONTENT_RESULT else None

            lisElement['ferenceLower'] = hisLisElement.FERENCE_LOWER_LIMIT if _is_number(
                hisLisElement.FERENCE_LOWER_LIMIT) else 0

            lisElement['ferenceUpper'] = hisLisElement.FERENCE_UPPER_LIMIT if _is_number(
                hisLisElement.FERENCE_UPPER_LIMIT) else 0

            lisElement['unit'] = hisLisElement.RESULT_UNIT
            lisElement['resultType'] = examElement['resultType']
            lisElement['referenceType'] = '1'  # e['refType']

            # 危机值的标识?
            lisElement['criticalValuesSymbol'] = hisLisElement.CRITICAL_VALUES_SYMBOL

            if hisLisElement.POSITIVE_SYMBOL == '↓':
                lisElement['positiveSymbol'] = '低'
            elif hisLisElement.POSITIVE_SYMBOL == '↑':
                lisElement['positiveSymbol'] = '高'
            else:
                lisElement['positiveSymbol'] = None
            lisDatas['items'].append(lisElement)

            # 项目的结果值列表保存,作为将来的参考,结构为 项目名称^项目结果^审核时间
            item_results.append('{}^{}^{}'.format(hisLisElement.LIS_ELEMENT_NAME,
                                                  hisLisElement.CONTENT_RESULT,
                                                  hisLisElement.AUDIT_DATE.strftime(
                                                      '%Y-%m-%d %H:%M:%S') if hisLisElement.AUDIT_DATE else None
                                                  ))

        finally:
            c += 1

    log.info('开始上传LIS结果数据...')

    examData = json.dumps(lisDatas)
    log.info(examData)

    log.info("开始保存LIS结果....")
    result = tjAssert(saveLisExamData(examData))
    log.info(result['msg'])

    return '\n'.join(item_results)