-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.R
More file actions
101 lines (83 loc) · 4.02 KB
/
main.R
File metadata and controls
101 lines (83 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -----------------------------------------------------------------------------
# gp_practice_data PostgreSQL Database Output Script
#
# author: Michael Johns
#
# about: This script allows the user to enter a GP Practice ID to console.
# There are several functions available relating to the gp_practice_data
# database.
#
# Required Files: "ConnectPostgreSQL.R"
# "PostgreSQLHelper.R"
# "GPData2015Helper.R"
#
# Required PostgreSQL Database: gp_practice_data
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Install and Load Library Packages (uncomment to install)
#------------------------------------------------------------------------------
#install.packages('tidyverse')
#install.packages('GetoptLong')
#install.packages('RPostgreSQL')
#install.packages("gt")
library(tidyverse)
library(GetoptLong)
library(RPostgreSQL)
library(gt)
#------------------------------------------------------------------------------
# Load required source files
#------------------------------------------------------------------------------
source("ConnectPostgreSQL.R")
source("PostgreSQLHelper.R")
source("GPData2015Helper.R")
#------------------------------------------------------------------------------
# Database connections and PostgreSQL driver initialisation
#------------------------------------------------------------------------------
# Load database driver (database_name)
database_driver <- connectDriver('PostgreSQL')
# Connect to DB (Driver, name, host address, port, database username)
db <- connectDB(database_driver,
'gp_practice_data',
'localhost', 5432,
'postgres')
#------------------------------------------------------------------------------
# User selects Practice ID
#------------------------------------------------------------------------------
# User input line to populate PracticeID
# Input entry in the console window
practiceID <- userPracticeIDInput()
# Get top 5 prescribed drugs for a specific practice
# Note: Requires populated practiceID
topFivePrescribedDrugs <- getTopFiveDrugSpendSinglePractice(db, practiceID)
#------------------------------------------------------------------------------
# Comparison and Correlation Plots
#
# All below functions run independantly of each other
#
# Note: As these are live updates, each executed function can take a while
# to populate details (Approx 1-2 minutes)
#------------------------------------------------------------------------------
# Show Comparison graph of practice, practice's region(by health board)
# and wales cancer diagnosis rates
barCancerRate <- barCancerRateComparisonPracticeRegionWales(db, practiceID)
# Visualisation of spend on medication per patient by practice across Wales
# Colour coded by health board
scatterPerPatientSpend <- scatterPlotPerPatientSpend(db)
# Correlation between each Practice total spend on medication and diseases:
# Cancer, Diabetes, Dementia and Hypertension
correlationCanDiabDemenHyp <- getCorDiagnosedCanDiabDemenHyperAndTotalSpend(db)
# Correlation between each Practice total spend on medication and diseases:
# Cancer, Smoking, Asthma and Obesity
correlationCanSmokAsthObesgetCor <- getCorDiagnosedCanSmokAsthObesAndTotalSpend(db)
# Correlation between each Practice total spend on medication
# Cancer, Diabetes, Dementia, Hypertension Smoking, Asthma and Obesity
correlationAll <- getCorAllDiagnosedTotalSpend(db)
# Correlation between each Region's total spend on medication and diseases:
# Cancer, Diabetes, Dementia, Hypertension Smoking, Asthma and Obesity
correlationAllRegion <- getCorAllDiagnosedTotalSpendRegion(db)
#------------------------------------------------------------------------------
# Disconnect database and driver
#------------------------------------------------------------------------------
dbListConnections(database_driver)
disconnect_Database(db, database_driver)
dbListConnections(database_driver)