文章
· 八月 11, 2022 阅读大约需 3 分钟

使用 iris-fhir-client 应用程序创建患者和患者观察

Hi 社区,

本文将演示如何使用 iris-fhir-client 客户端应用程序创建患者和患者观察资源。
image

建议在开始阅读本文之前可以先读一下我的  第一篇  关于这个应用程序的文章和观看 Youtube 视频

让我们开始吧:

1-创建患者资源

下面 dc.FhirClient 的 CreatePatient() 函数可用于创建患者资源

ClassMethod CreatePatient(givenName As %String, familyName As %String, birthDate As %String,gender As %String)

函数需要 giveName,failyName,birthDate 和性别来创建患者资源

下面的命令将创建病人

do ##class(dc.FhirClient).CreatePatient("PatientGN","PatientFN","2000-06-01","male")

image
下面是 irisfhirclient.py 文件中的 python 函数,它将创建患者:

import json
from fhirpy import SyncFHIRClient
from tabulate import tabulate
from fhirpy.base.searchset import Raw
import requests

def CreatePatient(givenName,familyName,birthDate,gender,url,api_key):
    headers = {"Content-Type":contentType,"x-api-key":api_key}
    client = SyncFHIRClient(url = url, extra_headers=headers)
    
    patient = client.resource("Patient")
    patient['name'] = [
        {
            'given': [givenName],
            'family': familyName,
            'use': 'official'
        }
    ]

    patient['birthDate'] = birthDate
    patient['gender'] = gender
    try:
        patient.save()
    except Exception as e:
        print("Error while creating Patient:" +str(e))       
        return
    print("Patient Created Successfully")    

 

2- 创建患者观察资源

让我们针对我们新创建的患者资源创建观察

以下 dc.FhirClient 的 CreateObservatoin() 函数可用于创建患者观察
ClassMethod CreateObservation(patientId As %String, loincCode As %String, ObrCategory As %String, ObrValue As %Integer, ObrUOM As %String, effectiveDate As %String)

参数

  • patientId 是患者的 ID
  • LioncCode 是Loinc Code,详情可查 这里
  • ObrCategory 是观察类别,详情可查 这里
  • ObrValue 是观察值
  • ObrUOM 是观察单元
  • EffectiveDate

以下命令将创建患者生命体征观察

do ##class(dc.FhirClient).CreateObservation("8111","8310-5","vital-signs",96.8,"degF","2022-01-22")

image

让我们列出患者的观察结果

do ##class(dc.FhirClient).GetPatientResources("Observation","8111")

image

下面是 irisfhirclient.py 文件中的 python 函数,它将创建患者:

import json
from fhirpy import SyncFHIRClient
from tabulate import tabulate
from fhirpy.base.searchset import Raw
import requests

#创建患者观察的功能
def CreateObservation(patientId,loincCode,ObrCategory,ObrValue,ObrUOM,effectiveDate,url,api_key):
    headers = {"Content-Type":contentType,"x-api-key":api_key}
    client = SyncFHIRClient(url = url, extra_headers=headers)
    observation = client.resource(
    'Observation',
    status='preliminary',
    category=[{
        'coding': [{
            'system': 'http://hl7.org/fhir/observation-category',
            'code': ObrCategory
        }]
    }],
    code={
        'coding': [{
            'system': 'http://loinc.org',
            'code': loincCode
        }]
    })
    observation['effectiveDateTime'] = effectiveDate
       
    observation['valueQuantity'] = {
    'system': 'http://unitsofmeasure.org',
    'value': ObrValue,
    'code': ObrUOM
    }
    
    #找到病人
    patient = client.resources('Patient').search(_id=patientId).first()
    observation['subject'] = patient.to_reference()
    
    try:
        observation.save()
    except Exception as e:
        print("Error while creating observation :"+ str(e))       
        return
    print("Patient Observation Created Successfully")

谢谢!

讨论 (0)1
登录或注册以继续