<commit_before>module Api
  class ProvidersController < ApplicationController
    resource_description do
      short 'Providers'
      formats ['json']
      description <<-PRCDESC
        This resource allows for the management of providers in popHealth

        popHealth assumes that providers are in a hierarchy. This resource allows users
        to see the hierarchy of providers
      PRCDESC
    end
    include PaginationHelper
    # load resource must be before authorize resource
    load_resource except: %w{index create new}
    authorize_resource
    respond_to :json
    before_filter :authenticate_user!

    api :GET, "/providers", "Get a list of providers. Returns all providers that the user has access to."
    param_group :pagination, Api::PatientsController
    def index
      if current_user.admin? || APP_CONFIG['use_opml_structure']
        @providers = Provider.all
      else
        @providers = Provider.where(parent_id: current_user.practice.provider_id)
      end
      authorize_providers(@providers)
      render json: @providers
    end

    api :GET, "/providers/:id", "Get an individual provider"
    param :id, String, :desc => "Provider ID", :required => true
    description <<-SDESC
      This will return an individual provider. It will include the id and name of its parent, if it
      has a parent. Children providers one level deep will be included in the children property
      if any children for this provider exist.
    SDESC
    example <<-EXAMPLE
      {
        "_id": "5331db9575efe558ad000bc9",
        "address": "1601 S W Archer Road Gainesville FL 32608",
        "cda_identifiers": [
          {
            "_id": "5331db9575efe558ad000bca",
            "extension": "573",
            "root": "Division"
          }
        ],
        "family_name": null,
        "given_name": "<NAME>\/South Georgia HCS-Gainesville",
        "level": null,
        "parent_id": "5331db9575efe558ad000bc7",
        "parent_ids": [
          "5331db9475efe558ad0008da",
          "5331db9575efe558ad000b8d",
          "5331db9575efe558ad000bc7"
        ],
        "phone": null,
        "specialty": null,
        "team_id": null,
        "title": null,
        "parent": {
          "_id": "5331db9575efe558ad000bc7",
          "address": "1601 S W Archer Road Gainesville FL 32608",
          "cda_identifiers": [
            {
              "_id": "5331db9575efe558ad000bc8",
              "extension": "573",
              "root": "Facility"
            }
          ],
          "family_name": null,
          "given_name": "North Florida\/South Georgia HCS-Gainesville",
          "level": null,
          "parent_id": "5331db9575efe558ad000b8d",
          "parent_ids": [
            "5331db9475efe558ad0008da",
            "5331db9575efe558ad000b8d"
          ],
          "phone": null,
          "specialty": null,
          "team_id": null,
          "title": null
        }
      }
    EXAMPLE
    def show
      if can? :read, @provider
        provider_json = @provider.as_json
        provider_json[:parent] = Provider.find(@provider.parent_id) if @provider.parent_id
        provider_json[:children] = @provider.children if @provider.children.present?
      else
        provider_json = {}
      end
      render json: provider_json<commit_msg>add patient count for provider<commit_after>module Api
  class ProvidersController < ApplicationController
    resource_description do
      short 'Providers'
      formats ['json']
      description <<-PRCDESC
        This resource allows for the management of providers in popHealth

        popHealth assumes that providers are in a hierarchy. This resource allows users
        to see the hierarchy of providers
      PRCDESC
    end
    include PaginationHelper
    # load resource must be before authorize resource
    load_resource except: %w{index create new}
    authorize_resource
    respond_to :json
    before_filter :authenticate_user!

    api :GET, "/providers", "Get a list of providers. Returns all providers that the user has access to."
    param_group :pagination, Api::PatientsController
    def index
      if current_user.admin? || APP_CONFIG['use_opml_structure']
        @providers = Provider.all
      else
        @providers = Provider.where(parent_id: current_user.practice.provider_id)
      end
      authorize_providers(@providers)
      render json: @providers
    end

    api :GET, "/providers/:id", "Get an individual provider"
    param :id, String, :desc => "Provider ID", :required => true
    description <<-SDESC
      This will return an individual provider. It will include the id and name of its parent, if it
      has a parent. Children providers one level deep will be included in the children property
      if any children for this provider exist.
    SDESC
    example <<-EXAMPLE
      {
        "_id": "5331db9575efe558ad000bc9",
        "address": "1601 S W Archer Road Gainesville FL 32608",
        "cda_identifiers": [
          {
            "_id": "5331db9575efe558ad000bca",
            "extension": "573",
            "root": "Division"
          }
        ],
        "family_name": null,
        "given_name": "North Florida\/South Georgia HCS-Gainesville",
        "level": null,
        "parent_id": "5331db9575efe558ad000bc7",
        "parent_ids": [
          "5331db9475efe558ad0008da",
          "5331db9575efe558ad000b8d",
          "5331db9575efe558ad000bc7"
        ],
        "phone": null,
        "specialty": null,
        "team_id": null,
        "title": null,
        "parent": {
          "_id": "5331db9575efe558ad000bc7",
          "address": "1601 S W Archer Road Gainesville FL 32608",
          "cda_identifiers": [
            {
              "_id": "5331db9575efe558ad000bc8",
              "extension": "573",
              "root": "Facility"
            }
          ],
          "family_name": null,
          "given_name": "North Florida\/South Georgia HCS-Gainesville",
          "level": null,
          "parent_id": "5331db9575efe558ad000b8d",
          "parent_ids": [
            "5331db9475efe558ad0008da",
            "5331db9575efe558ad000b8d"
          ],
          "phone": null,
          "specialty": null,
          "team_id": null,
          "title": null
        }
      }
    EXAMPLE
    def show
      if can? :read, @provider
        provider_json = @provider.as_json
        provider_json[:parent] = Provider.find(@provider.parent_id) if @provider.parent_id
        provider_json[:children] = @provider.children if @provider.children.present?
        provider_json[:patient_count] = @provider.records.count
      else
        provider_json = {}
      end
      render json: provider_json
{'fraction_non_alphanumeric': 0.09301283965362794, 'fraction_numerical': 0.056136160047775455, 'mean_word_length': 2.237796036732721, 'pattern_counts': {'":': 62, '<': 18, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206094', 'n_tokens_mistral': 2159, 'n_tokens_neox': 1943, 'n_words': 532}