Closed DEQcdonald closed 2 years ago
I can make this change. There is going to be a major update pushed tomorrow to reenable the criteria code lookups. I'll integrate this in that update.
Fantastic, thanks Travis!
Updated in version 2.0 #22 which is live now. Note that you must now run AWQMS_set_servers() to get the servers to run. See readme, attend today's R meeting, or email me for instructions.
Would it be possible to add CAS number as a query option. I have edited your AWQMS_Data code (below) to what I believe would work in lieu of creating a fork and merge request.
' AWQMS_Data
'
' This function will retrieve data from OregonDEQ AWQMS
' @param startdate Required parameter setting the startdate of the data being fetched. Format 'yyyy-mm-dd'
' @param enddate Optional parameter setting the enddate of the data being fetched. Format 'yyyy-mm-dd'
' @param station Optional vector of stations to be fetched
' @param AU_ID Optional vector of Assessment Units to be fetched
' @param project Optional vector of projects to be fetched
' @param char Optional vector of characteristics to be fetched
' @param casnumber Optional vector of CAS numbers to be fetched
' @param stat_base Optional vector of Result Stattistical Bases to be fetched ex. Maximum
' @param media Optional vector of sample media to be fetched
' @param org optional vector of Organizations to be fetched
' @param HUC8 Optional vector of HUC8s to be fetched
' @param HUC8_Name Optional vector of HUC8 names to be fetched
' @param HUC10 Optional vector of HUC10s to be fetched
' @param HUC12 Optional vector of HUC12s to be fetched
' @param HUC12_Name Optional vector of HUC12 names to be fetched
' @param crit_codes If true, include standard codes used in determining criteria
' @param filterQC If true, do not return MLocID 10000-ORDEQ or sample replicates
' @param return_query If true, return the query language that would have been sent to AWQMS. If TRUE, nothing is sent to AWQMS. This is useful for troubleshooting.
' @return Dataframe of data from AWQMS
' @examples
' AWQMS_Data(startdate = '2017-1-1', enddate = '2000-12-31', station = c('10591-ORDEQ', '29542-ORDEQ'),
' project = 'Total Maximum Daily Load Sampling', filterQC = FALSE, crit_codes = FALSE)
' @export
'
'
AWQMS_Data <- function(startdate = '1949-09-15', enddate = NULL, station = NULL, AU_ID = NULL, project = NULL, char = NULL, casnumber = NULL, stat_base = NULL, media = NULL, submedia = NULL, org = NULL, HUC8 = NULL, HUC8_Name = NULL, HUC10 = NULL, HUC12 = NULL, HUC12_Name = NULL, crit_codes = FALSE, filterQC = TRUE, return_query = FALSE) {
, a.[Org_Name] , a.[Project1] , a.[Project2] , a.[Project3] , a.[MLocID] , a.[StationDes] , a.[MonLocType] , a.[EcoRegion3] , a.[EcoRegion4] , a.[HUC8] , a.[HUC8_Name] , a.[HUC10] , a.[HUC12] , a.[HUC12_Name] , a.[Lat_DD] , a.[Long_DD] , a.[Reachcode] , a.[Measure] , a.[AU_ID] , a.[act_id] , a.[Activity_Type] , a.[SampleStartDate] , cast(a.[SampleStartTime] AS time(0)) as [SampleStartTime] , a.[SampleStartTZ] , a.[SampleMedia] , a.[SampleSubmedia] , a.[SamplingMethod] , a.[chr_uid] , a.[Char_Name] , a.[Char_Speciation] , a.[Sample_Fraction] , a.[CASNumber] , a.[Result_UID] , a.[Result_status] , a.[Result_Type] , a.[Result_Text] , a.[Result_Numeric] , a.[Result_Operator] , a.[Result_Unit] , a.[Unit_UID] , a.[ResultCondName] , a.[RelativeDepth] , a.[Result_Depth] , a.[Result_Depth_Unit] , a.[Result_Depth_Reference] , a.[act_depth_height] , a.[ActDepthUnit] , a.[Act_depth_Reference] , a.[Act_Depth_Top] , a.[Act_Depth_Top_Unit] , a.[Act_Depth_Bottom] , a.[Act_Depth_Bottom_Unit] , a.[Time_Basis] , a.[Statistical_Base] , a.[Statistic_N_Value] , a.[act_sam_compnt_name] , a.[stant_name] , a.[Bio_Intent] , a.[Taxonomic_Name] , a.[Analytical_method] , a.[Method_Code] , a.[Method_Context] , a.[Analytical_Lab] , a.[Activity_Comment] , a.[Result_Comment] , a.[DQL] , a.[QualifierAbbr] , a.[QualifierTxt] , a.[IDLType] , a.[IDLValue] , a.[IDLUnit] , a.[MDLType] , a.[MDLValue] , a.[MDLUnit] , a.[MRLType] , a.[MRLValue] , a.[MRLUnit] , a.[URLType] , a.[URLValue] , a.[URLUnit] , a.[WQX_submit_date] ,s.FishCode ,s.SpawnCode ,s.WaterTypeCode ,s.WaterBodyCode ,s.BacteriaCode ,s.DO_code ,s.ben_use_code ,s.pH_code ,s.DO_SpawnCode FROM [awqms].[dbo].[VW_AWQMS_Results] a LEFT JOIN [Stations].[dbo].[VWStationsFinal] s ON a.MLocID = s.MLocID WHERE SampleStartDate >= Convert(datetime, {startdate})" } else { query <- "SELECT a.[OrganizationID] , a.[Org_Name] , a.[Project1] , a.[Project2] , a.[Project3] , a.[MLocID] , a.[StationDes] , a.[MonLocType] , a.[EcoRegion3] , a.[EcoRegion4] , a.[HUC8] , a.[HUC8_Name] , a.[HUC10] , a.[HUC12] , a.[HUC12_Name] , a.[Lat_DD] , a.[Long_DD] , a.[Reachcode] , a.[Measure] , a.[AU_ID] , a.[act_id] , a.[Activity_Type] , a.[SampleStartDate] , cast(a.[SampleStartTime] AS time(0)) as [SampleStartTime] , a.[SampleStartTZ] , a.[SampleMedia] , a.[SampleSubmedia] , a.[SamplingMethod] , a.[chr_uid] , a.[Char_Name] , a.[Char_Speciation] , a.[Sample_Fraction] , a.[CASNumber] , a.[Result_UID] , a.[Result_status] , a.[Result_Type] , a.[Result_Text] , a.[Result_Numeric] , a.[Result_Operator] , a.[Result_Unit] , a.[Unit_UID] , a.[ResultCondName] , a.[RelativeDepth] , a.[Result_Depth] , a.[Result_Depth_Unit] , a.[Result_Depth_Reference] , a.[act_depth_height] , a.[ActDepthUnit] , a.[Act_depth_Reference] , a.[Act_Depth_Top] , a.[Act_Depth_Top_Unit] , a.[Act_Depth_Bottom] , a.[Act_Depth_Bottom_Unit] , a.[Time_Basis] , a.[Statistical_Base] , a.[Statistic_N_Value] , a.[act_sam_compnt_name] , a.[stant_name] , a.[Bio_Intent] , a.[Taxonomic_Name] , a.[Analytical_method] , a.[Method_Code] , a.[Method_Context] , a.[Analytical_Lab] , a.[Activity_Comment] , a.[Result_Comment] , a.[DQL] , a.[QualifierAbbr] , a.[QualifierTxt] , a.[IDLType] , a.[IDLValue] , a.[IDLUnit] , a.[MDLType] , a.[MDLValue] , a.[MDLUnit] , a.[MRLType] , a.[MRLValue] , a.[MRLUnit] , a.[URLType] , a.[URLValue] , a.[URLUnit] , a.[WQX_submit_date] FROM [awqms].[dbo].[VW_AWQMS_Results] a WHERE SampleStartDate >= Convert(datetime, {startdate})"
}