<commit_before># -*- coding: utf-8 -*-
import os
import urllib


import requests
from fhirclient import client
import fhirclient.models.patient as p
import fhirclient.models.medicationstatement as cm
import fhirclient.models.observation as ob


__author__ = 'glow'


class FHIRConnection(object):

    def __init__(self, base_url="https://fhir-open-api-dstu2.smarthealthit.org"):
        smart = client.FHIRClient(settings=dict(api_base=base_url, app_id='my_client'))

    @property
    def patients(self):
        search = p.Patient.where(struct=dict())
        pt_list = []
        for patient in search.perform_resources(smart.server):
            pt_list.append(patient.as_json())
        return pt_list

    def get_patient(self, patient_id):
        patient = p.Patient.read(patient_id, smart.server)
        return patient.as_json()

    def get_patient_medications(self, patient_id):
        # ??? need the right patient id
        search_meds = cm.MedicationStatement.where(struct=dict(patient=patient_id))
        meds = []
        for meds in search_meds.perform_resources(smart.server):
           meds.append(meds.as_json())
        return meds

    def get_medication(self, medication_id):
        medication = cm.MedicationStatement.read(medication_id, smart.server)
        return medication.as_json();

    def get_obs(self, patient_id, loinc_code):
        search_obs = ob.Observation.where(struct=dict(patient=patient_id, code=loinc_code))
        obs = ""
        if len(search_obs.perform_resources(smart.server)) > 0:
            sysbp = search_obs.perform_resources(smart.server).pop().as_json()
        return obs

    def get_vitals_sysbp(self, patient_id):
        return self.get_obs(patient_id, "8480-6")

    def get_vitals_diabp(self, patient_id):
        return self.get_obs(patient_id, "55284-4")

    def get_vitals_bmi(self, patient_id):
        return self.get_obs(patient_id, "39156-5")

    def get_vitals_hr(self, patient_id):
        return self.get_obs(patient_id, "8867-4")

    def get_vitals_temp(self, patient_id):
        return self.get_obs(patient_id, "8310-5")<commit_msg>tidied imports added missing self decl removed dangling semi-colon<commit_after># -*- coding: utf-8 -*-

from fhirclient import client
import fhirclient.models.patient as p
import fhirclient.models.medicationstatement as cm
import fhirclient.models.observation as ob


__author__ = 'glow'


class FHIRConnection(object):

    def __init__(self, base_url):
        self.smart = client.FHIRClient(settings=dict(api_base=base_url, app_id='tornado-id'))

    @property
    def patients(self):
        search = p.Patient.where(struct=dict())
        patients = []
        for patient in search.perform_resources(self.smart.server):
            patients.append(patient.as_json())
        return patients


    def get_patient(self, patient_id):
        patient = p.Patient.read(patient_id, self.smart.server)
        return patient.as_json()

    def get_patient_medications(self, patient_id):
        # ??? need the right patient id
        search_meds = cm.MedicationStatement.where(struct=dict(patient=patient_id))
        meds = []
        for meds in search_meds.perform_resources(self.smart.server):
           meds.append(meds.as_json())
        return meds

    def get_medication(self, medication_id):
        medication = cm.MedicationStatement.read(medication_id, self.smart.server)
        return medication.as_json()

    def get_obs(self, patient_id, loinc_code):
        search_obs = ob.Observation.where(struct=dict(patient=patient_id, code=loinc_code))
        obs = ""
        if len(search_obs.perform_resources(self.smart.server)) > 0:
            sysbp = search_obs.perform_resources(self.smart.server).pop().as_json()
        return obs

    def get_vitals_sysbp(self, patient_id):
        return self.get_obs(patient_id, "8480-6")

    def get_vitals_diabp(self, patient_id):
        return self.get_obs(patient_id, "55284-4")

    def get_vitals_bmi(self, patient_id):
        return self.get_obs(patient_id, "39156-5")

    def get_vitals_hr(self, patient_id):
        return self.get_obs(patient_id, "8867-4")

    def get_vitals_temp(self, patient_id):
        return self.get_obs(patient_id, "8310-5")
{'fraction_non_alphanumeric': 0.10770681121847749, 'fraction_numerical': 0.013905255715295781, 'mean_word_length': 3.3439099283520983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1381178', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1347, 'n_words': 255}