<commit_before>###
@namespace scoping into the CQL_QDM namespace
###
@CQL_QDM ||= {}


###
Represents a patient (using the HDS model) for use by the CQL execution
engine.
###
class CQL_QDM.CQLPatient
  constructor: (@patient) ->
    @_patient = @patient
    @_datatypes = @buildDatatypes()

  ###
  @returns {String}
  ###
  id: ->
    @_patient.id

  ###
  @returns {Object}
  ###
  findRecords: (profile) ->
    if profile == 'Patient'
      #@getPatientCharacteristics()
      [{ 'birth datetime': cql.DateTime.fromDate(moment.utc(@patient.get('birthdate'), 'X').toDate()) }]
    else
      @_datatypes[profile]

  ###
  @returns {Object}
  ###
  buildDatatypes: ->
    types = [
      'allergies',
      'care_goals',
      'conditions',
      'encounters',
      'communications',
      'family_history',
      'immunizations',
      'medical_equipment',
      'medications',
      'procedures',
      'results',
      'social_history'
    ]
    datatypes = {}
    for type in types
      data_criteria = @_patient.get(type)
      if data_criteria
        for dc in data_criteria
          classname = CQL_QDM.OIDMap.oidToClassName(dc.oid)
          unless classname
            classname = dc.description.substr(0, dc.description.indexOf(':'))
          unless datatypes[classname]?
            datatypes[classname] = []
          datatypes[classname].push new window['CQL_QDM'][classname](dc)
    datatypes

  ###
  @returns {Object}
  ###
  getPatientCharacteristics: ->
    characteristics = {}
    characteristics['birthDatetime'] = cql.DateTime.fromDate(moment.utc(@_patient.get('birthdate'), 'X').toDate())
    characteristics['gender'] = cql.DateTime.fromDate(moment.utc(@_patient.get('gender'), 'X').toDate())
    # TODO: More characteristics?
    [characteristics]<commit_msg>Fixed issue in findRecords that was returning undefined<commit_after>###
@namespace scoping into the CQL_QDM namespace
###
@CQL_QDM ||= {}


###
Represents a patient (using the HDS model) for use by the CQL execution
engine.
###
class CQL_QDM.CQLPatient
  constructor: (@patient) ->
    @_patient = @patient
    @_datatypes = @buildDatatypes()

  ###
  @returns {String}
  ###
  id: ->
    @_patient.id

  ###
  @returns {Object}
  ###
  findRecords: (profile) ->
    if profile == 'Patient'
      @getPatientCharacteristics()
    else
      return if @_datatypes[profile]? then @_datatypes[profile] else []

  ###
  @returns {Object}
  ###
  buildDatatypes: ->
    types = [
      'allergies',
      'care_goals',
      'conditions',
      'encounters',
      'communications',
      'family_history',
      'immunizations',
      'medical_equipment',
      'medications',
      'procedures',
      'results',
      'social_history'
    ]
    datatypes = {}
    for type in types
      data_criteria = @_patient.get(type)
      if data_criteria
        for dc in data_criteria
          classname = CQL_QDM.OIDMap.oidToClassName(dc.oid)
          unless classname
            classname = dc.description.substr(0, dc.description.indexOf(':'))
          unless datatypes[classname]?
            datatypes[classname] = []
          datatypes[classname].push new window['CQL_QDM'][classname](dc)
    datatypes

  ###
  @returns {Object}
  ###
  getPatientCharacteristics: ->
    # characteristics = {}
    # characteristics['birthDatetime'] = cql.DateTime.fromDate(moment.utc(@_patient.get('birthdate'), 'X').toDate())
    # characteristics['gender'] = cql.DateTime.fromDate(moment.utc(@_patient.get('gender'), 'X').toDate())
    # # TODO: More characteristics?
    # [characteristics]
    [{ 'birth datetime': cql.DateTime.fromDate(moment.utc(@patient.get('birthdate'), 'X').toDate()) }]
{'fraction_non_alphanumeric': 0.14907508161044614, 'fraction_numerical': 0.000544069640914037, 'mean_word_length': 3.027382256297919, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2878859', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1195, 'n_words': 221}