Store, Protect, Optimize Your Healthcare Data with AWS: Part 2
AWS Architecture BlogStore, Protect, Optimize Your Healthcare Data with AWS: Part 2by Stephen Jepsen | on04 OCT 2018| inAmazon Athena,Amazon QuickSight,Amazon Redshift,Amazon SageMaker,Analytics,Architecture,Artificial Intelligence,AWS Glue|Permalink|ShareLeveraging Analytics and Machine Learning Tools for Readmissions PredictionThis blog post was co-authored by Ujjwal Ratan, a senior AI/ML solutions architect on the global life sciences team.InPart 1, we looked at various options to ingest and store sensitive healthcare data using AWS. The post described our shared responsibility model and provided a reference architecture that healthcare organizations could use as a foundation to build a robust platform on AWS to store and protect their sensitive data, including protected health information (PHI). In Part 2, we will dive deeper into how customers can optimize their healthcare datasets for analytics and machine learning (ML) to address clinical and operational challenges.There are a number of factors creating pressures for healthcare organizations, both providers and payers, to adopt analytic tools to better understand their data: regulatory requirements, changing reimbursement models from volume- to value-based care, population health management for risk-bearing organizations, and movement toward personalized medicine. As organizations deploy new solutions to address these areas, the availability of large and complex datasets from electronic health records, genomics, images (for example, CAT, PET, MRI, ultrasound, X-ray), and IoT has been increasing. With these data assets growing in size, healthcare organizations want to leverage analytic and ML tools to derive new actionable insights across their departments.One example of the use of ML in healthcare is diagnostic image analysis, including digital pathology. Pathology is extremely important in diagnosing and treating patients, but it is also extremely time-consuming and largely a manual process. While the complexity and quantity of workloads are increasing, the number of pathologists is decreasing. According to one study, the number of active pathologists could drop by 30 percent by 2030 compared to 2010 levels. (1) A cloud architecture and solution can automate part of the workflow, including sample management, analysis, storing, sharing, and comparison with previous samples to complement existing provider workflows effectively. A recent study using deep learning to analyze metastatic breast cancer tissue samples resulted in an approximately 85% reduction in human error rate. (2)ML is also being used to assist radiologists in examining other diagnostic images such as X-rays, MRIs, and CAT scans. Having large quantities of images and metadata to train the algorithms that are the key to ML is one of the main challenges for ML adoption. To help address this problem, the National Institutes of Health recently released 90,000 X-ray plates tagged either with one of 14 diseases or tagged as being normal. Leading academic medical centers are using these images to build their neural networks and train their algorithms. With advanced analytics and ML, we can answer the hard questions such as “what is the next best action for my patient, the expected outcome, and the cost.”The foundations for a great analytical layerLet’s pick up from where we left off in Part 1. We have seen how providers can ingest data into AWS from their data centers and store it securely into different services depending on the type of data. For example:All object data is stored in Amazon S3, Amazon S3 Infrequent Access, or Amazon Glacier depending on how often they are used.Data from the provider’s database is either processed and stored as objects in Amazon S3 or aggregated into data marts on Amazon Redshift.Metadata of the objects on Amazon S3 are maintained in the DynamoDB database.Amazon Athena is used to query the objects directly stored on Amazon S3 to address ad hoc requirements.We will now look at two best practices that are key to building a robust analytical layer using these datasets.Separating storage and compute: You should not be compelled to scale compute resources just to store more data. The scaling rules of the two layers should be separate.Leverage the vast array of AWS big data services when it comes to building the analytical platforms instead of concentrating on just a few of them. Remember, one size does not fit all.Technical overviewIn this overview, we will demonstrate how we can leverage AWS big data and ML services to build a scalable analytical layer for our healthcare data. We will use a single source of data stored in Amazon S3 for performing ad hoc analysis using Amazon Athena, integrate it with a data warehouse on Amazon Redshift, build a visual dashboard for some metrics using Amazon QuickSight, and finally build a ML model to predict readmissions using Amazon SageMaker. By not moving the data around and just connecting to it using different services, we avoid building redundant copies of the same data. There are multiple advantages to this approach:We optimize our storage. Not having redundant copies reduces the amount of storage required.We keep the data secure with only authorized services having access to it. Keeping multiple copies of the data can result in higher security risk.We are able to scale the storage and compute separately as needed.It becomes easier to manage the data and monitor usage metrics centrally such as how often the data has been accessed, who has been accessing it, and what has been the growth pattern of the data over a period of time. These metrics can be difficult to aggregate if the data is duplicated multiple times.Let’s build out this architecture using the following steps:Create a database in AWS Glue Data CatalogWe will do this using a Glue crawler. First create a JSON file that contains the parameters for the Glue crawler.{
"Name": "readmissions",
"Role": "arn of the role for Glue",
"DatabaseName": "readmissions",
"Description": "glue data catalog for storing readmission data",
"Targets": {
"S3Targets": [
{
"Path": "s3://<bucket>/<prefix>"
},
{
"Path": "s3://<bucket>/<prefix>"
}
]
}
}As you can see, the crawler will crawl two locations in Amazon S3 and save the resulting tables in a new database called “readmissions.” Replace the role ARN and Amazon S3 locations with your corresponding details. Save this in a filecreate_crawler.json. Then from theAWS CLI, call the following command to create the crawler:aws glue create-crawler --cli-input-json file://create_crawler.jsonOnce the crawler is created, run it by calling the following command:aws glue start-crawler --name readmissionsLog on to the AWS Glue console, navigate to the crawlers, and wait until the crawler completes running.This will create two tables — phi and non-phi — in a database named “readmissions” in the AWS Glue Data Catalog as shown below.Query the data using AthenaThe Amazon Glue Data Catalog is seamlessly integrated with Amazon Athena. For details on how to enable this, seeIntegration with AWS Glue.As a result of this integration, the tables created using the Glue crawler can now be queried using Amazon Athena. Amazon Athena allows you to do ad hoc analysis on the dataset. You can do exploratory analysis on the data and also determine its structure and quality. This type of upfront ad hoc analysis is invaluable for ensuring the data quality in your downstream data warehouse or your ML algorithms that will make use of this data for training models. In the next few sections, we will explore these aspects in greater detail.To query the data using Amazon Athena, navigate to theAmazon Athena console.NOTE:Make sure the region is the same as the region you chose in the previous step. If it’s not the same, switch the region by using the drop-down menu on the top right-hand corner of the screen.Once you arrive in the Amazon Athena console, you should already see the tables and databases you created previously, and you should be able to see the data in the two tables by writing Amazon Athena queries. Here is a list of the top 10 rows from the tablereadmissions.nonphi:Now that we are able to query the dataset, we can run some queries for exploratory analysis. Here are just a few examples:AnalysisAmazon Athena QueryHow many Patients have been discharged to home?SELECT count(*) from nonphi where discharge_disposition = ‘Discharged to home’What’s the minimum and the maximum number of procedures carried out on a patient?SELECT min(num_procedures), max(num_procedures) from nonphiHow many patients were referred to this hospital by another physician?SELECT count(*) FROM nonphi group by admission_source having admission_source = ‘Physician Referral’What were the top 5 specialties with positive readmissions?SELECT count(readmission_result) as num_readmissions, medical_specialty from(select readmission_result,medical_specialty from nonphi where readmission_result = ‘Yes’)group by medical_specialty order by num_readmissions desc limit 5Which payer was responsible for paying for treatments that involved more than 5 procedures?SELECT distinct payer_code from nonphi where num_procedures >5 and payer_code !='(null)’While this information is valuable, you typically do not want to invest too much time and effort into building an ad hoc query platform like this because at this stage, you are not even sure if the data is of any value for your business-critical analytical applications. One benefit of using Amazon Athena for ad hoc analysis is that it requires little effort or time. It uses Schema-On-Read instead of schema on write, allowing you to work with various source data formats without worrying about the underlying structures. You can put the data on Amazon S3 and start querying immediately.Create an external table in Amazon Redshift Spectrum with the same dataNow that we are satisfied with the data quality and understand the structure of the data, we would like to integrate this with a data warehouse. We’ll useAmazon Redshift Spectrumto create external tables on the files in S3 and then integrate these external tables with a physical table in Amazon Redshift.Amazon Redshift Spectrum allows you to run Amazon Redshift SQL queries against data on Amazon S3, extending the capabilities of your data warehouse beyond the physical Amazon Redshift clusters. You don’t need to do any elaborate ETL or move the data around. The data exists in one place in Amazon S3 and you interface with it using different services (Athena and Redshift Spectrum) to satisfy different requirements.Before beginning, please look at thisstep by step guideto set up Redshift Spectrum.After you have set up Amazon Redshift Spectrum, you can begin executing the steps below:Create an external schema called “readmissions.” Amazon Redshift Spectrum integrates with the Amazon Glue Data Catalog and allows you to create spectrum tables by referring the catalog. This feature allows you to build the external table on the same data that you analyzed with Amazon Athena in the previous step without the need for ETL. This can be achieved by the following:create external schema readmissions
from data catalog
database 'readmissions'
iam_role 'arn for your redshift spectrum role '
region ‘region when the S3 data exists’;NOTE:Make sure you select the appropriate role arn and region.Once the command executes successfully, you can confirm the schema was created by running the following:select * from svv_external_schemas;You should see a row similar to the one above with your corresponding region and role.You can also see the external tables that were created by running the following command:select * from SVV_EXTERNAL_TABLES;Let’s confirm we can see all the rows in the external table by counting the number of rows:select count(*) from readmissions.phi;
select count(*) from readmissions.nonphi;You should see 101,766 rows in both the tables, confirming that your external tables contain all the records that you read using the AWS Glue data crawler and analyzed using Athena.Now that we have all the external tables created, let’s create an aggregate fact table in the physical Redshift data warehouse. We can use the “As Select” clause of the Redshift create table query to do this:create table readmissions_aggregate_fact as
select
readmission_result,admission_type,discharge_disposition,diabetesmed,
avg(time_in_hospital) as avg_time_in_hospital,
min(num_procedures) as min_procedures,
max(num_procedures) as max_procedures,
avg(num_procedures) as avg_num_procedures,
avg(num_medications) as avg_num_medications,
avg(number_outpatient) as avg_number_outpatient,
avg(number_emergency) as avg_number_emergency,
avg(number_inpatient) as avg_number_inpatient,
avg(number_diagnoses) as avg_number_diagnoses
from readmissions.nonphi
group by readmission_result,admission_type,discharge_disposition,diabetesmedOnce this query executes successfully, you can see a new table created in the physical public schema of your Amazon Redshift cluster. You can confirm this by executing the following query:select distinct(tablename) from pg_table_def where schemaname = 'public'Build a QuickSight Dashboard from the aggregate factWe can now create dashboards to visualize the data in our readmissions aggregate fact table using Amazon QuickSight. Here are some examples of reports you can generate using Amazon QuickSight on the readmission data.For more details on Amazon QuickSight, refer to theservice documentation.Build a ML model in Amazon SageMaker to predict readmissionsAs a final step, we will create a ML model to predict the attributereadmission_result, which denotes if a patient was readmitted or not, using the non-PHI dataset.Create a notebook instancein Amazon SageMaker that is used to develop our code.The code reads non-PHI data from the Amazon S3 bucket as a data frame in Python. This is achieved using thepandas.readcsvfunction.Use thepandas.get_dummiesfunction to encode categorical values into numeric values for use with the model.Split the data into two, 80% for training and 20% for testing, using thenumpy.random.randfunction.Form train_X, train_y and test_X, test_y corresponding to training features, training labels, testing features, and testing labels respectively.Use the Amazon SageMaker Linear learner algorithm to train our model. The implementation of the algorithm uses dense tensor format to optimize the training job. Use the functionwrite_numpy_to_dense_tensorfrom the Amazon SageMaker library to convert the numpy array into the dense tensor format.Create the training job in Amazon SageMaker with appropriate configurations and run it.Once the training job completes, create an endpoint in Amazon SageMaker to host our model, using the linear.deploy function to deploy the endpoint.Finally, run a prediction by invoking the endpoint using thelinear_predictor.predictfunction.You can view the complete notebookhere.Data, analytics, and ML are strategic assets to help you manage your patients, staff, equipment, and supplies more efficiently. These technologies can also help you be more proactive in treating and preventing disease. Industry luminaries share this opinion: “By leveraging big data and scientific advancements while maintaining the important doctor-patient bond, we believe we can create a health system that will go beyond curing disease after the fact to preventing disease before it strikes by focusing on health and wellness,” writes Lloyd B. Minor, MD, dean of theStanford School of Medicine.ML and analytics offer huge value in helping achieve the quadruple aim : improved patient satisfaction, improved population health, improved provider satisfaction, and reduced costs. Technology should never replace the clinician but instead become an extension of the clinician and allow them to be more efficient by removing some of the mundane, repetitive tasks involved in prevention, diagnostics, and treatment of patients.(1) “The Digital Future of Pathology.” The Medical Futurist, 28 May 2018, medicalfuturist.com/digital-future-pathology.(2) Wang, Dayong, et al. “Deep Learning for Identifying Metastatic Breast Cancer.” Deep Learning for Identifying Metastatic Breast Cancer, 18 June 2016, arxiv.org/abs/1606.05718.TAGS:healthcare dataStephen JepsenStephen Jepsen is a Global HCLS Practice Manager in AWS Professional Services.
Leveraging Analytics and Machine Learning Tools for Readmissions Prediction This blog post was co-authored by Ujjwal Ratan, a senior AI/ML solutions architect on the global life sciences team. In Part 1, we looked at various options to ingest and store sensitive healthcare data using AWS. The post described our shared responsibility model and provided a […]
Stephen Jepsen
Amazon Athena Amazon QuickSight Amazon Redshift Amazon SageMaker Analytics Architecture Artificial Intelligence AWS Glue