<commit_before>namespace :fhir do

  desc 'console'
  task :console, [] do |t, args|
    binding.pry
  end

  desc 'WIP to test the new API; delete when done'
  task :api_testing, [] do |t, args|

    client = FHIR::Client.new 'http://fhirtest.uhn.ca/baseDstu3'
    client2 = FHIR::Client.new 'http://sqlonfhir-may.azurewebsites.net/fhir'

    FHIR::Model.configure { |c| c.client = client }

    patient1 = FHIR::Patient.create(client, name: {given: 'Joe', family: 'Smith'})
    patient2 = FHIR::Patient.create(client2, name: {given: 'Joe', family: 'Smith'})

    results = FHIR::Patient.search(client, given: 'Joe', family: 'Smith')
    results = FHIR::Patient.search(client2, given: 'Joe', family: 'Smith')

    patient1.update
    patient2.name[0].family = 'Smithfield'
    patient2.update

    patient_check = FHIR::Patient.read(client2, patient1.id)
    patient_check = FHIR::Patient.read(client, patient1.id)

    patient3 = FHIR::Patient.new(name: {given: 'Sam', family: 'Jones'})
    patient3.client = client
    patient3.update
    patient4 = FHIR::Patient.new(name: {given: 'Sam', family: 'Jones'})
    patient4.client = client
    patient4.update
    patient_check = FHIR::Patient.read(client, patient1.id)

    #all_patients = FHIR::Patient.all()
    #all_patients = FHIR::Patient.all(client: client2)

    # all_patients.count() # enumerable

    patient1.destroy
    patient2.destroy
    patient3.destroy

  end

  desc 'WIP to test the new API; delete when done'
  task :api_testing_noconfig, [] do |t, args|

    client = FHIR::Client.new 'http://fhirtest.uhn.ca/baseDstu3'
    patient = FHIR::Patient.create(client, name: {given: 'Joe', family: 'Smith'})
    patient.destroy

  end

  #
  # Prerequisites & Assumptions:
  #
  #  1. Running SMART-on-FHIR (DSTU2 branch) server  [http://example/fhir]
  #  2. Running OpenID Connect server [http://example:8080/openid-connect-server-webapp]
  #  3. Configured client under OpenID Connect server:
  #     a. Create a system scope if necessary. SMART-on-FHIR requires 'fhir_complete' scope.
  #     b. Add the scope created in (a) to client.
  #     c. Add the FHIR server URL to the list of allowed redirect URIs (required?)
  #     d. Ensure client has 'client credentials' grant type
  #     d. Whitelist the client
  #  4. 'client_id' and 'client_secret' variables are the name and secret of the client created in (3)
  #  5. :authorize_url is the authorization endpoint of the OpenID connect server
  #  6. :token_url is the token endpoint of the OpenID connect server
  #  
  desc 'OAuth2 Example'
  task :oauth2, [:url,:client_id,:client_secret] do |t, args|
    client = FHIR::Client.new(args.url)
    client_id = args.client_id
    client_secret = args.client_secret
    options = client.get_oauth2_metadata_from_conformance
    if options.empty?
      puts 'This server does not support the expected OAuth2 extensions.'<commit_msg>Remove temporary rake tasks<commit_after>namespace :fhir do

  desc 'console'
  task :console, [] do |t, args|
    binding.pry
  end

  #
  # Prerequisites & Assumptions:
  #
  #  1. Running SMART-on-FHIR (DSTU2 branch) server  [http://example/fhir]
  #  2. Running OpenID Connect server [http://example:8080/openid-connect-server-webapp]
  #  3. Configured client under OpenID Connect server:
  #     a. Create a system scope if necessary. SMART-on-FHIR requires 'fhir_complete' scope.
  #     b. Add the scope created in (a) to client.
  #     c. Add the FHIR server URL to the list of allowed redirect URIs (required?)
  #     d. Ensure client has 'client credentials' grant type
  #     d. Whitelist the client
  #  4. 'client_id' and 'client_secret' variables are the name and secret of the client created in (3)
  #  5. :authorize_url is the authorization endpoint of the OpenID connect server
  #  6. :token_url is the token endpoint of the OpenID connect server
  #  
  desc 'OAuth2 Example'
  task :oauth2, [:url,:client_id,:client_secret] do |t, args|
    client = FHIR::Client.new(args.url)
    client_id = args.client_id
    client_secret = args.client_secret
    options = client.get_oauth2_metadata_from_conformance
    if options.empty?
      puts 'This server does not support the expected OAuth2 extensions.'
{'fraction_non_alphanumeric': 0.11208323480728305, 'fraction_numerical': 0.013478363679356823, 'mean_word_length': 3.4856839872746552, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '878246', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1385, 'n_words': 416}