13 KiB
13 KiB
In [ ]:
import pandas as pd
# how many rows of table to show
pd.set_option("display.max_rows", 1000)
# we want to see the full error messages (often longer than default colwidth)
pd.set_option("max_colwidth", 10000)In [ ]:
#from fhirvalidation import Validator
#validator = Validator()
#validator.validate_resource_and_render_validation_outcome ('Condition/resource1')
In [ ]:
from fhirvalidation import Validator
validator = Validator()
# Set auth parameters for your FHIR server (if you do not want to use basic auth credentials from the environment variables in .env)
# Documentation: https://requests.readthedocs.io/en/latest/user/authentication/#basic-authentication
# validator.requests_kwargs['auth'] = ( 'myusername', 'mypassword )
# Search for all resources of the resource_type
search_parameters = {}
# Search resources with for certain code
#search_parameters={"code": "A00.0"}
df = validator.search_and_validate(resource_type="Condition", search_parameters=search_parameters, limit=10000)In [ ]:
import pandas as pd
len( pd.unique(df['fullUrl']) )In [ ]:
df[['severity', 'location_aggregated', 'diagnostics_aggregated', 'fullUrl']].groupby(["severity", "location_aggregated", "diagnostics_aggregated"]).count().sort_values(['fullUrl'], ascending=False)In [ ]:
df[['severity', 'location_aggregated', 'diagnostics_aggregated', 'fullUrl']].groupby(["severity", "location_aggregated", "diagnostics_aggregated"]).count().sort_values(['severity','fullUrl'], ascending=False)In [ ]:
df[['severity', 'location', 'diagnostics', 'fullUrl']].groupby(["severity", "location", "diagnostics"]).count().sort_values(['fullUrl'], ascending=False)
In [ ]:
len( pd.unique(df[df['severity']=="error"]['fullUrl']) )In [ ]:
df.query('severity=="error"')[['location_aggregated', 'diagnostics_aggregated', 'fullUrl']].groupby(["location_aggregated", "diagnostics_aggregated"]).count().sort_values(['fullUrl'], ascending=False)In [ ]:
df.query('severity=="error"')[['location', 'diagnostics', 'fullUrl']].groupby(["location", "diagnostics"]).count().sort_values(['fullUrl'], ascending=False)In [ ]:
myerror = "Condition.code.coding:icd10-gm.version: minimum required = 1, but only found 0 (from https://www.medizininformatik-initiative.de/fhir/core/modul-diagnose/StructureDefinition/Diagnose|2024.0.0)"
# Use Python syntax:
# df[df['diagnostics']==myerror]
#
# or use df.query
# https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html and https://docs.python.org/3/reference/lexical_analysis.html#f-strings:
df_query = f'diagnostics=="{myerror}"'
df.query(df_query)In [ ]:
df.info()
df.memory_usage(deep=True)In [ ]:
df.head()In [ ]:
# Reserved char pipe | has to be escaped by | (https://github.com/astanin/python-tabulate/issues/241)
df_escaped = df.applymap(lambda s: s.replace('|','\\|') if isinstance(s, str) else s)
print(df_escaped[['severity', 'location_aggregated', 'diagnostics_aggregated', 'fullUrl']].groupby(["severity", "location_aggregated", "diagnostics_aggregated"]).count().sort_values(['fullUrl'], ascending=False).to_markdown(tablefmt="github") )
In [ ]:
# Install pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install pygwalkerIn [ ]:
# render dataframe with pygwalker
import pygwalker as pyg
walker = pyg.walk(df)
In [ ]: