示例#1
0
def patient_list():
    start = request.args.get('start', 0)
    length = request.args.get('length', 100)

    start = int(start)
    length = int(length)

    count = db.engine.execute("select count(*) from T_Patients").scalar()
    result = db.engine.execute("select * from T_Patients limit %d, %d" %
                               (start, length))
    plist = []
    total = count

    for row in result:
        patient = p.Patient({'id': row['pat_id']})

        name = hn.HumanName()
        name.given = [row['pat_first']]
        name.family = row['pat_last']
        patient.name = [name]

        address = addr.Address()
        address.city = row['pat_city']
        address.state = row['pat_state']
        address.postalCode = row['pat_zip']
        address.district = row['pat_address']
        patient.address = [address]

        patient.gender = row['pat_gender']
        patient.birthDate = fd.FHIRDate(
            datetime.strftime(row['pat_birthdate'], "%Y-%m-%d"))
        # patient.maritalStatus = row['pat_marital']
        plist.append(patient.as_json())

    return jsonify(results=plist, total=total)
示例#2
0
def patient(id):
    # https://{FHIR Base URL}/Patient/{id}?
    # name={name}&
    # family={family name}&
    # gender={gender}&
    # _format=json

    # TODO: query params
    name = request.args.get('name', None)
    family = request.args.get('family', None)
    gender = request.args.get('gender', None)

    # TODO: connect to database to search patient

    result = db.engine.execute("select * from T_Patients limit 1")
    names = []
    for row in result:
        patient = p.Patient({'id': row['pat_id']})
        name = hn.HumanName()
        name.given = [row['pat_first']]
        name.family = row['pat_last']
        patient.name = [name]

        address = addr.Address()
        address.city = row['pat_city']
        address.state = row['pat_state']
        address.postalCode = row['pat_zip']
        address.district = row['pat_address']
        patient.address = [address]

        patient.gender = row['pat_gender']
        patient.birthDate = fd.FHIRDate(
            datetime.strftime(row['pat_birthdate'], "%Y-%m-%d"))
        patient.maritalStatus = row['pat_marital']
    return jsonify(result=patient.as_json())
 def to_fhir_obj(self):
     patient = p.Patient()
     identifier = p.identifier.Identifier()
     identifier.value = self.id
     patient.identifier = [identifier]
     name = hn.HumanName()
     name.given = [self.first_name]
     name.family = self.last_name
     patient.name = [name]
     patient.gender = self.sex
     patient.birthDate = fd.FHIRDate(str(datetime.utcnow().date()))
     # prints patient's JSON representation, now with id and name
     address = a.Address()
     address.state = self.state
     address.district = self.district
     patient.address = [address]
     json = patient.as_json()
     return patient
示例#4
0
def build_location(ct_loc):
    """
    Turn a Location (ct.gov) to a Location (fhir)
    :param Location ct_loc: location from ct.gov
    """
    l = location.Location()
    if not ct_loc.facility.name:
        print("Missing facility name: ")
        name = "{}-{}".format(ct_loc.facility.address.city,
                              ct_loc.facility.address.country)
    else:
        name = ct_loc.facility.name
    l.id = quote(name)
    l.name = ct_loc.facility.name
    a = address.Address(
        dict(city=ct_loc.facility.address.city,
             country=ct_loc.facility.address.country,
             postalCode=ct_loc.facility.address.zip,
             type='both'))
    l.address = a
    return l
示例#5
0
    def __init__(self):
        """
        Creates, validates, and posts an Organization FHIR resource. Currently, using class variables.

        :returns: practitioner id created by server
        """
        Organization = org.Organization()
        Organization.active = True
        Organization.name = self.organization_name
        Address = a.Address()
        Address.line = self.organization_line
        Address.city = self.organization_city
        Address.postalCode = self.organization_postalCode
        Address.state = self.organization_state
        Organization.address = [Address]
        ContactPoint = cp.ContactPoint()
        ContactPoint.system = 'phone'
        ContactPoint.value = self.organization_phone
        Organization.telecom = [ContactPoint]
        self._validate(Organization)
        self.response = self.post_resource(Organization)
        Organization.id = self._extract_id()
        self.Organization = Organization
        print(self)
示例#6
0
    def __init__(self):
        """
        Uses fhirclient.models to create and post location resource. Currently, using class variables.

        :returns: GenerateLocation object that has Location object as an attribute.
        """
        Location = l.Location()
        LocationPosition = l.LocationPosition()
        Address = a.Address()
        Location.status = 'active'
        Location.name = self.location_name
        Address.line = self.location_line
        Address.city = self.location_city
        Address.postalCode = self.location_postalCode
        Address.state = self.location_state
        Location.address = Address
        LocationPosition.latitude = self.location_latitude
        LocationPosition.longitude = self.location_longitude
        Location.position = LocationPosition
        # self._validate(Location)
        self.response = self.post_resource(Location)
        Location.id = self._extract_id()
        self.Location = Location
        print(self)
示例#7
0
    def create_fhir_object(self):
        """
        method: create_fhir_object()
        Create a fhir-client.model.address.Adress object and stores to the self.fhir attribute

        :return:
            None
        """
        # Initialize FHIRclient Address object
        # Assign Address object attributes to FHIRclient Address object
        fa = fhir_address.Address()

        if self.address1:
            fa.line = [self.address1]

            if self.address2:
                fa.line.append(self.address2)

        if self.city:
            fa.city = self.city

        if self.state:
            fa.state = self.state

        if self.zipcode:
            fa.postalCode = self.zipcode

        fa.text = self.formatted_address()

        if isinstance(self.start_date, date) or isinstance(self.end_date, date):
            p = period.Period()

            if self.start_date:
                fhirdate_start = fhirdate.FHIRDate()
                fhirdate_start.date = self.start_date
                p.start = fhirdate_start

            if self.end_date:
                fhirdate_end = fhirdate.FHIRDate()
                fhirdate_end.date = self.end_date
                p.end = fhirdate_end

            fa.period = p

        if self.use:
            fa.use = self.use.lower()

        if self.is_postal and self.is_physical:
            fa.type = 'both'

        elif self.is_postal:
            fa.type = 'postal'

        elif self.is_physical:
            fa.type = 'physical'

        if self.district:
            fa.district = self.district

        if self.country:
            fa.country = self.country

        self.fhir = fa
示例#8
0
    def _generate_patient_fhir_object(self):
        """Creates a test patient using fhirclient.models."""
        Patient = p.Patient()
        HumanName = hn.HumanName()
        HumanName.family = [self.name_last]
        HumanName.given = [self.name_first]
        Patient.name = [HumanName]

        Patient.gender = self.gender

        birthDay = fd.FHIRDate()
        birthDay.date = self.bday
        Patient.birthDate = birthDay

        Address = a.Address()
        Address.country = 'USA'
        Address.postalCode = self.zipcode
        Address.state = self.state
        Address.city = self.city
        Address.line = [f'{self.address_number} {self.address_street}']
        Address.use = 'home'
        Address.type = 'postal'
        Patient.active = True
        Patient.address = [Address]
        PatientCommunication = p.PatientCommunication()
        PatientCommunication.language = self._create_FHIRCodeableConcept(
            'en-US', 'urn:ietf:bcp:47', 'English')
        # PatientCommunication.language = self._create_FHIRCodeableConcept('en-US','http://hl7.org/fhir/ValueSet/languages','English')
        PatientCommunication.preferred = True
        Patient.communication = [PatientCommunication]

        race = e.Extension()
        race.url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race'
        us_core = e.Extension()
        us_core.url = 'ombCategory'
        us_core.valueCoding = self._create_FHIRCoding(
            self.race_code, 'urn:oid:2.16.840.1.113883.6.238',
            self.race_description)
        race_detailed = e.Extension()
        race_detailed.url = 'detailed'
        race_detailed.valueCoding = self._create_FHIRCoding(
            self.race_code, 'urn:oid:2.16.840.1.113883.6.238',
            self.race_description)
        race_text = e.Extension()
        race_text.url = 'text'
        race_text.valueString = self.race_description
        race.extension = [us_core, race_detailed, race_text]

        ethnicity = e.Extension()
        ethnicity.url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity'

        us_core = e.Extension()
        us_core.url = 'ombCategory'
        us_core.valueCoding = self._create_FHIRCoding(
            self.ethnicity_code, 'urn:oid:2.16.840.1.113883.6.238',
            self.ethnicity_description)
        ethnicity_text = e.Extension()
        ethnicity_text.url = 'text'
        ethnicity_text.valueString = self.ethnicity_description
        ethnicity.extension = [us_core, ethnicity_text]

        Patient.extension = [race, ethnicity]
        Patient.managingOrganization = self._create_FHIRReference(
            self.Organization)

        self._validate(Patient)
        self.response = self.post_resource(Patient)
        Patient.id = self._extract_id()
        self.Patient = Patient
        print(self)
示例#9
0
def patient():
    user = get_jwt_identity()
    print("user:"******"name_given"]]
            name.family = request.form["name_family"]
            patient.name = [name]
            # 设置性别 只能是male或者female
            patient.gender = request.form["gender"] if request.form[
                "gender"] == "男" or request.form["女"] == "female" else ""
            # 设置生日
            patient.birthDate = fdate.FHIRDate().with_json(
                request.form["birthDate"])
            # 设置逻辑删除
            patient.active = True
            # 设置地址
            patient.address = [ad.Address({"city": request.form["city"]})]
            ret = mongodb.basic_information.insert_one(patient.as_json())
            print(ret)
            return ret_data(200, '请求成功', 1003)
        else:
            return ret_data(200, "请求成功", 2008)

    elif request.method == 'GET':
        dict01 = mongodb.basic_information.find_one({
            'id': str(user),
            'active': True
        })
        if dict01 is None:
            return ret_data(200, '请求成功', 2011)
        dict02 = {}
        del dict01['_id']
        dict02['city'] = dict01['address'][0]['city']
        dict02['birthDate'] = dict01['birthDate']
        dict02['gender'] = dict01['gender']
        dict02['name'] = str(dict01['name'][0]['family']) + str(
            dict01['name'][0]['given'][0])
        return ret_data(200, '请求成功', 1005, **dict02)

    elif request.method == 'DELETE':
        count = 0
        for i in patientList:
            print(i['active'])
            if i['active'] is True:
                count += 1
        if count >= 1:
            mongodb.basic_information.update_one(
                {
                    'id': str(user),
                    'active': True
                }, {'$set': {
                    'active': False
                }})
            # mongodb.basic_information.delete_one({'id':str(user)})
            return ret_data(200, '请求成功', 1004)
        else:
            return ret_data(200, '请求成功', 2010)

    elif request.method == 'PUT':
        count = 0
        for i in patientList:
            print(i['active'])
            if i['active'] is True:
                count += 1
        if count == 1:
            patient = p.Patient({'id': str(user)})
            # 设置名字
            name = hn.HumanName()
            name.given = [request.form["name_given"]]
            name.family = request.form["name_family"]
            patient.name = [name]
            # 设置性别 只能是male或者female
            patient.gender = request.form["gender"] if request.form[
                "gender"] == "男" or request.form["女"] == "female" else ""
            # 设置生日
            patient.birthDate = fdate.FHIRDate().with_json(
                request.form["birthDate"])
            # 设置逻辑删除
            patient.active = True
            # 设置地址
            patient.address = [ad.Address({"city": request.form["city"]})]
            mongodb.basic_information.update_one({'id': str(user)},
                                                 {'$set': patient.as_json()})
            return ret_data(200, '请求成功', 1006)
        else:
            return ret_data(200, '请求成功', 2009)
    return ret_data(200, '请求成功', 1000, test='hello world')