R/WebApiProfile.R

Defines functions getProfileDataForPerson

Documented in getProfileDataForPerson

# @file WebApiProfile
#
# Copyright 2019 Observational Health Data Sciences and Informatics
#
# This file is part of StudyManagement
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#' Get the results from individual Achilles reports by data Source definition expression
#'
#' @details
#' Obtain the JSON expression from WebAPI for a given dataSource
#'
#' @param baseUrl        The base URL for the WebApi instance, for example:
#'                       "http://server.org:80/WebAPI".
#' @param sourceKey      The source key for a CDM instance in WebAPI, as defined in the
#'                       Configuration page
#' @param personId       The personId of the person whoose profile is being reviewed
#' @param cohortId       <OPTIONAL> The cohortId of the cohort that the person belongs to
#' @return
#' A list of objects
#'
#' @examples
#' \dontrun{
#' # This will obtain pre-computed summary regarding dataSource
#'
#' getDataSourceReportDataForSourceKey(baseUrl = "http://server.org:80/WebAPI", dataSource = 'dataSource', reportType = 'dashboard')
#' }
#'
#'
#' @export

getProfileDataForPerson <- function(baseUrl,
                                    sourceKey,
                                    personId,
                                    cohortId = NULL){
  .checkBaseUrl(baseUrl)
  if (is.null(cohortId)) {
    url <- sprintf("%1s/%2s/person/%3s", baseUrl, sourceKey, personId)
  } else {
    url <- sprintf("%1s/%2s/person/%3s?cohort=%4s", baseUrl, sourceKey, personId,cohortId)
  }
  json <- .getApiResponseParse(url)


  json$parsed$records$startDate <- .millisecondsToDate(json$parsed$records$startDate)
  json$parsed$records$endDate <- .millisecondsToDate(json$parsed$records$endDate)
  json$parsed$cohorts$startDate <- .millisecondsToDate(json$parsed$cohorts$startDate)
  json$parsed$cohorts$endDate <- .millisecondsToDate(json$parsed$cohorts$endDate)
  json$parsed$cohorts$personId <- personId
  json$parsed$observationPeriods$startDate <- .millisecondsToDate(json$parsed$observationPeriods$startDate)
  json$parsed$observationPeriods$endDate <- .millisecondsToDate(json$parsed$observationPeriods$endDate)

  json
}
gowthamrao/StudyManagement documentation built on March 9, 2020, 10:48 p.m.