def main():

    endpoint = 'https://ncpi-api-fhir-service-dev.kidsfirstdrc.org'
    # Create an instance
    client = SyncFHIRClient(endpoint)

    # Search for patients
    resources = client.resources('Patient')
    resources = resources.search(gender='female').limit(1000)
    patients = resources.fetch()
    print("# of patients:{}".format(len(patients)))
Beispiel #2
0
def main():

    endpoint = 'https://ncpi-api-fhir-service-dev.kidsfirstdrc.org'
    full_cookie_path = os.path.expanduser('~/.keys/kf_cookies.json')
    print(full_cookie_path)
    with open(full_cookie_path) as f:
        cookies = json.load(f)

    client = SyncFHIRClient(endpoint, extra_headers=cookies)

    # Search for patients
    resources = client.resources('Patient')
    resources = resources.search(gender='female').limit(10)
    patients = resources.fetch()
    print("# of patients:{}".format(len(patients)))
Beispiel #3
0
def main():
	
	endpoint = 'https://ncpi-api-fhir-service-dev.kidsfirstdrc.org'
	full_cookie_path = os.path.expanduser('~/.keys/kf_cookies.json')
	print(full_cookie_path)
	with open(full_cookie_path) as f:
			cookies = json.load(f)

	client = SyncFHIRClient(endpoint, extra_headers=cookies)
	
		
	document_references = client.resources("DocumentReference")
	document_references.search(_profile='http://fhir.ncpi-project-forge.io/StructureDefinition/ncpi-drs-document-reference')
	drs_ids = document_references.fetch()
	print("# of ids:{}".format(len(drs_ids)))
	for d in drs_ids:
		print(d['content'][0]['attachment']['url'])
Beispiel #4
0
    async def init_client(self, config):
        basic_auth = BasicAuth(login=config['client']['id'],
                               password=config['client']['secret'])
        self.client = AsyncFHIRClient('{}'.format(config['box']['base-url']),
                                      authorization=basic_auth.encode())
        self.sync_client = SyncFHIRClient('{}'.format(
            config['box']['base-url']),
                                          authorization=basic_auth.encode())
        await self._create_seed_resources()
        self._initialized = True

        if callable(self._on_ready):
            result = self._on_ready()
            if asyncio.iscoroutine(result):
                await self._on_ready()
Beispiel #5
0
from fhirpy import SyncFHIRClient

from fhir.resources.patient import Patient
from fhir.resources.observation import Observation
from fhir.resources.humanname import HumanName
from fhir.resources.contactpoint import ContactPoint

import json

client = SyncFHIRClient(
    url='https://dh9fytkn0e.execute-api.eu-west-2.amazonaws.com/dev',
    extra_headers={
        "x-api-key":
        "EzAVxFOjEqagIbYVHK2Mz7RUp1GOpRHMVTTxVQk9",
        "Authorization":
        "eyJraWQiOiJ2ZXZ0cUNYZitiUzNBM3hNWm5IVFhRbDlucTFZaDloRzJZNkxVXC94bTd0ST0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJmOWU4YmI3OC04MjRlLTRhZGQtOTZjNS1iZjVmMGY3YTlkNTUiLCJjb2duaXRvOmdyb3VwcyI6WyJwcmFjdGl0aW9uZXIiXSwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5ldS13ZXN0LTIuYW1hem9uYXdzLmNvbVwvZXUtd2VzdC0yX0JiTkFoUTVzTSIsImNvZ25pdG86dXNlcm5hbWUiOiJmaGlyYXBpdGVzdCIsIm9yaWdpbl9qdGkiOiIxZWQ0NmU1NS1jNmE1LTQ3MjMtYTEyZi04OTYzOWQzZGVjYWMiLCJhdWQiOiIxdXJkaWlmZjJlbWMzcGgzamdiZ3AxYm43ayIsImV2ZW50X2lkIjoiYjQ4MDM0NjctMjRjYy00OWZlLTg3NTYtNTgzZDEzNDZmOGE3IiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE2NTgyNDQ0MDUsImV4cCI6MTY1ODMzMDgwNSwiaWF0IjoxNjU4MjQ0NDA1LCJqdGkiOiJjNjJkNTc3Zi01NWJmLTQwNjQtYjYwOC0xMzA1MTQ1ODM0M2QiLCJlbWFpbCI6ImFsbWE1Lm5oc2RAZ21haWwuY29tIn0.XxflQNEL_N8XWut2MxGNTZfnjei4qCsbvEBs31n1RMemY9DneEU1haYGGaHp4T3CyBy2-eLeaDbfI16dhEnh_5D6qSgRoMPWv5ScZop2uvoqujkufsp-C6lZsRtetyowETrcaSs46jvumqzpONUO5F5i7UdEg2lh9N0iKfUi67MepgMy9gBJMZkKQhTl6S0BRNHfyGhUT5kbN2EeFeDltiSOaDZKk7IbRoUO0OnZYNFcqmDNAjPYzLFKNnYyGcsMlPSKZaULHt3P7EhAS-e5EOG5c8-Sqp7fPOZ3cpq2QHr5RF4hZcyZiUwoyYoeW4_MDvhkdew2tdnyEsFQHwuO2g"
    })
patients_resources = client.resources('Patient')
patient0 = Patient.parse_obj(
    patients_resources.search(family='Jameson',
                              given='Matt').first().serialize())
print("Our paitent:", patient0.name)
Beispiel #6
0
 def setup_class(cls):
     cls.client = SyncFHIRClient(
         cls.URL,
         authorization=FHIR_SERVER_AUTHORIZATION,
         extra_headers={'Access-Control-Allow-Origin': '*'}
     )
Beispiel #7
0
 def __init__(self, fhir_server, fhir_port, split='train', input_size=256):
     """
     Args:
         fhir_server (string): Address of FHIR Server.
         fhir_port (string): Port of FHIR Server.
     """
     self.fhir_server = fhir_server
     self.fhir_port = fhir_port
     self.split = split
     self.input_size = input_size
     # Create an instance
     client = SyncFHIRClient('http://{}:{}/fhir'.format(
         fhir_server, fhir_port))
     # Search for patients
     patients = client.resources('Patient')  # Return lazy search set
     patients_data = []
     for patient in patients:
         patient_birthDate = None
         try:
             patient_birthDate = patient.birthDate
         except:
             pass
         # patinet_id, gender, birthDate
         patients_data.append(
             [patient.id, patient.gender, patient_birthDate])
     patients_df = pd.DataFrame(
         patients_data, columns=["patient_id", "gender", "birthDate"])
     # Search for media
     media_list = client.resources('Media').include('Patient', 'subject')
     media_data = []
     for media in media_list:
         media_bodySite = None
         media_reasonCode = None
         media_note = None
         try:
             media_bodySite = media.bodySite.text
         except:
             pass
         try:
             media_reasonCode = media.reasonCode[0].text
         except:
             pass
         try:
             media_note = media.note[0].text
         except:
             pass
         media_data.append([
             media.subject.id, media.id, media_bodySite, media_reasonCode,
             media_note, media.content.url
         ])
     media_df = pd.DataFrame(media_data,
                             columns=[
                                 "patient_id", "media_id", "bodySite",
                                 "reasonCode", "note", "image_url"
                             ])
     self.data_df = pd.merge(patients_df,
                             media_df,
                             on='patient_id',
                             how='outer')
     self.data_df = self.data_df[self.data_df['note'].notna()].reset_index()
     self.trans = transforms.Compose([
         transforms.RandomHorizontalFlip(),
         transforms.RandomVerticalFlip(),
         transforms.ColorJitter(brightness=32. / 255., saturation=0.5),
         transforms.Resize(self.input_size),
         transforms.ToTensor()
     ])
Beispiel #8
0
import pytest
from fhirpy import SyncFHIRClient, AsyncFHIRClient
from fhirpy.lib import BaseFHIRReference
from fhirpy.base.utils import AttrDict, SearchList


@pytest.mark.parametrize(
    'client',
    [SyncFHIRClient('mock'), AsyncFHIRClient('mock')])
class TestLibBase(object):
    def test_to_reference_for_reference(self, client):
        reference = client.reference('Patient', 'p1')
        reference_copy = reference.to_reference(display='patient')
        assert isinstance(reference_copy, BaseFHIRReference)
        assert reference_copy.serialize() == {
            'reference': 'Patient/p1',
            'display': 'patient',
        }

    def test_serialize(self, client):
        practitioner1 = client.resource('Practitioner', id='pr1')
        practitioner2 = client.resource('Practitioner', id='pr2')
        patient = client.resource(
            'Patient',
            id='patient',
            generalPractitioner=[
                practitioner1.to_reference(display='practitioner'),
                practitioner2
            ])

        assert patient.serialize() == {
Beispiel #9
0
 def setup_class(cls):
     cls.client = SyncFHIRClient(
         cls.URL,
         authorization=_basic_auth_str('root', 'secret'),
         extra_headers={'Access-Control-Allow-Origin': '*'})
import pytest
from fhirpy import SyncFHIRClient, AsyncFHIRClient
from fhirpy.lib import BaseFHIRReference
from fhirpy.base.utils import AttrDict, SearchList, parse_pagination_url


@pytest.mark.parametrize(
    "client",
    [SyncFHIRClient("mock"), AsyncFHIRClient("mock")])
class TestLibBase(object):
    def test_to_reference_for_reference(self, client):
        reference = client.reference("Patient", "p1")
        reference_copy = reference.to_reference(display="patient")
        assert isinstance(reference_copy, BaseFHIRReference)
        assert reference_copy.serialize() == {
            "reference": "Patient/p1",
            "display": "patient",
        }

    def test_serialize(self, client):
        practitioner1 = client.resource("Practitioner", id="pr1")
        practitioner2 = client.resource("Practitioner", id="pr2")
        patient = client.resource(
            "Patient",
            id="patient",
            generalPractitioner=[
                practitioner1.to_reference(display="practitioner"),
                practitioner2,
            ],
        )
Beispiel #11
0
fhir_server = str(os.environ['FHIR_SERVER'])
fhir_port = str(os.environ['FHIR_PORT'])

## Load aggregated results from previous stations
# if run_id > 0:
#     prev_experiment_dir = osp.join(out_dir, 'run_{}'.format(str(run_id - 1)))
#     if osp.exists(osp.join(prev_experiment_dir, '')):
#         pass
#     else:
#         pass
# else:
#     pass

## Collect Data Statistic
# Create an instance
client = SyncFHIRClient('http://{}:{}/fhir'.format(fhir_server, fhir_port))
# Search for patients
patients = client.resources('Patient')  # Return lazy search set
patients_data = []
for patient in patients:
    patient_birthDate = None
    try:
        patient_birthDate = patient.birthDate
    except:
        pass
    # patinet_id, gender, birthDate
    patients_data.append([patient.id, patient.gender, patient_birthDate])
patients_df = pd.DataFrame(patients_data,
                           columns=["patient_id", "gender", "birthDate"])
# Search for media
media_list = client.resources('Media').include('Patient', 'subject')