<commit_before>FactoryBot.define do
  factory  :measure, :class =>  Measure do
    entry = Rails.root.join('test', 'fixtures', 'artifacts', 'cms127v7.json')
    source_measure = JSON.parse(File.read(entry),:max_nesting => 100)
    sequence( :name) { |i| "Measure Name #{i}" }
    sequence( :hqmf_id) { |i| "53e3f13d-e5cf-445f-8dda-3720aff8401#{i}" }
    sequence( :hqmf_set_id) { |i| "7c00e09b-02dc-458b-8587-7f0347a443f#{i}" }
    continuous_variable false
    category 'none'
    type 'ep'
    episode_of_care true
    trait  :diagnosis do
      hqmf_doc = { 'source_data_criteria'  => { 'DiagnosisActivePregnancy'  =>
                                               { 'title'  => 'Pregnancy',
                                                 'description'  => 'Diagnosis, Active => Pregnancy',
                                                 'standard_category'  => 'diagnosis_condition_problem',
                                                 'qds_data_type'  => 'diagnosis_active',
                                                 'code_list_id'  => '1.5.6.7',
                                                 'type'  => 'conditions',
                                                 'definition'  => 'diagnosis',
                                                 'hard_status'  => false,
                                                 'negation'  => false,
                                                 'source_data_criteria'  => 'DiagnosisActivePregnancy' } },
                   'data_criteria'  => { 'DiagnosisActivePregnancy'  =>
                                        { 'title'  => 'Pregnancy',
                                          'description'  => 'Diagnosis, Active => Pregnancy',
                                          'standard_category'  => 'diagnosis_condition_problem',
                                          'qds_data_type'  => 'diagnosis_active',
                                          'code_list_id'  => '1.5.6.7',
                                          'type'  => 'conditions',
                                          'definition'  => 'diagnosis',
                                          'hard_status'  => false,
                                          'negation'  => false,
                                          'field_values'  => {
                                            'ORDINAL'  => {
                                              'type'  => 'CD',
                                              'code_list_id'  => '1.16.17.18',
                                              'title'  => 'Principal'
                                            }
                                          },
                                          'source_data_criteria'  => 'DiagnosisActivePregnancy' } } }
      hqmf_document { hqmf_doc }
    end
    trait  :no_diagnosis do
      hqmf_doc = { 'source_data_criteria'  => { 'PhysicalExamFindingBmiPercentile'  =>
                                               { 'title'  => 'BMI percentile',
                                                 'description'  => 'Physical Exam, Finding => BMI percentile',
                                                 'standard_category'  => 'physical_exam',
                                                 'qds_data_type'  => 'physical_exam',
                                                 'code_list_id'  => '1.7.8.9',
                                                 'type'  => 'physical_exams',
                                                 'definition'  => 'physical_exam',
                                                 'hard_status'  => false,
                                                 'negation'  => false,
                                                 'source_data_criteria'  => 'PhysicalExamFindingBmiPercentile' } },
                   'data_criteria'  => { 'PhysicalExamFindingBmiPercentile_precondition_8'  =>
                                        { 'title'  => 'BMI percentile',
                                          'description'  => 'Physical Exam, Finding => BMI percentile',
                                          'standard_category'  => 'physical_exam',
                                          'qds_data_type'  => 'physical_exam',
                                          'code_list_id'  => '1.7.8.9',
                                          'type'  => 'physical_exams',
                                          'definition'  => 'physical_exam',
                                          'hard_status'  => false,
                                          'negation'  => false,
                                          'source_data_criteria'  => 'PhysicalExamFindingBmiPercentile',
                                          'temporal_references'  => [
                                            { 'type'  => 'DURING',
                                              'reference'  => 'MeasurePeriod' }
                                          ] } } }
      hqmf_document { hqmf_doc }
    end

    factory  :measure_with_diagnosis, :traits => [ :diagnosis]
    factory  :measure_without_diagnosis, :traits => [ :no_diagnosis]

    factory  :static_measure do
      name 'Static Measure'
      cms_id 'CMS1234'
      hqmf_id 'BE65090C-EB1F-11E7-8C3F-9A214CF093AE'
      hqmf_set_id 'C621C7B6-EB1F-11E7-8C3F-9A214CF093AE'
      
      map_fn "function() {\n        var patient = this;\n        var effective_date = <%= effective_date %>;\n        var enable_logging = <%= enable_logging %>;\n        var enable_rationale = <%= enable_rationale %>;\n\n        hqmfjs = {}\n        <%= init_js_frameworks %>\n        \n        \n      var patient_api = new hQuery.Patient(patient);\n\n      \n        // #########################\n        // ##### DATA ELEMENTS #####\n        // #########################\n\n        OidDictionary = <%= oid_dictionary %>;\n        \n        // Measure variables\nvar MeasurePeriod = {\n  \"low\" => new TS(\"201201010000\", null, true),\n  \"high\" => new TS(\"201212312359\", null, true)\n}\nhqmfjs.MeasurePeriod = function(patient) {\n  return [new hQuery.CodedEntry(\n    {\n      \"start_time\" => MeasurePeriod.low.asDate().getTime()/1000,\n      \"end_time\" => MeasurePeriod.high.asDate().getTime()/1000,\n      \"codes\" => {}\n    }\n  )];\n}\nif (typeof effective_date === 'number') {\n  MeasurePeriod.high.date = new Date(1000*effective_date);\n  // add one minute before pulling off the year.  This turns 12-31-2012 23 =>59 into 1-1-2013 00 =>00  => 1-1-2012 00 =>00\n  MeasurePeriod.low.date = new Date(1000*(effective_date+60));\n  MeasurePeriod.low.date.setFullYear(MeasurePeriod.low.date.getFullYear()-1);\n}\n\n// Data critera\nhqmfjs.OccurrenceAPregnancy1 = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events.specific_occurrence = 'OccurrenceAPregnancy1'\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  events.specificContext=new hqmf.SpecificOccurrence(Row.buildForDataCriteria(events.specific_occurrence, events))\n  return events;\n}\n\nhqmfjs.DiagnosisActivePregnancy = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  hqmf.SpecificsManager.setIfNull(events);\n  return events;\n}\n\nhqmfjs.PatientCharacteristicSexOncAdministrativeSex = function(patient, initialSpecificContext) {\nvar value = patient.gender() || null;\nmatching = matchingValue(value, new CD(\"F\", \"Administrative Sex\"));\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.PatientCharacteristicRaceRace = function(patient, initialSpecificContext) {\nvar value = patient.race() || null;\nmatching = matchingValue(value, null);\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.PatientCharacteristicEthnicityEthnicity = function(patient, initialSpecificContext) {\nvar value = patient.ethnicity() || null;\nmatching = matchingValue(value, null);\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.PatientCharacteristicPayerPayer = function(patient, initialSpecificContext) {\nvar value = patient.payer() || null;\nmatching = matchingValue(value, null);\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.OccurrenceAPregnancy1_precondition_4 = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events.specific_occurrence = 'OccurrenceAPregnancy1'\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = SBE(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.OccurrenceAPregnancy1_precondition_2 = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events.specific_occurrence = 'OccurrenceAPregnancy1'\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = EBS(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PhysicalExamFindingBmiPercentile_precondition_8 = function(patient, initialSpecificContext) {\n  var events = patient.procedureResults();\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.7.8.9\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PhysicalExamFindingHeight_precondition_10 = function(patient, initialSpecificContext) {\n  var events = patient.procedureResults();\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.8.9.10\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PhysicalExamFindingWeight_precondition_12 = function(patient, initialSpecificContext) {\n  var events = patient.procedureResults();\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.9.10.11\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.InterventionPerformedCounselingForNutrition_precondition_17 = function(patient, initialSpecificContext) {\n  var events = patient.allProcedures();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.10.11.12\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.InterventionPerformedCounselingForPhysicalActivity_precondition_20 = function(patient, initialSpecificContext) {\n  var events = patient.allProcedures();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.11.12.13\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_23 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(new PQ(3, \"a\", true), null));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_25 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(null, new PQ(17, \"a\", true)));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_27 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.4.5.6\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedOfficeVisit_precondition_29 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.3.4.5\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_31 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.12.13.14\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_33 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.13.14.15\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_35 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.14.15.16\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_37 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.15.16.17\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedHomeHealthcareServices_precondition_39 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.6.7.8\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_44 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(new PQ(3, \"a\", true), null));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_46 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(null, new PQ(11, \"a\", true)));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_48 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.4.5.6\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedOfficeVisit_precondition_50 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.3.4.5\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_52 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.12.13.14\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_54 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.13.14.15\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_56 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.14.15.16\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_58 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.15.16.17\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedHomeHealthcareServices_precondition_60 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.6.7.8\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_65 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(new PQ(12, \"a\", true), null));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_67 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(null, new PQ(17, \"a\", true)));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_69 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.4.5.6\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedOfficeVisit_precondition_71 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.3.4.5\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_73 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.12.13.14\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_75 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.13.14.15\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_77 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.14.15.16\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_79 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.15.16.17\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedHomeHealthcareServices_precondition_81 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.6.7.8\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\n\n\n        // #########################\n        // ##### MEASURE LOGIC #####\n        // #########################\n        \n        hqmfjs.initializeSpecifics = function(patient_api, hqmfjs) { hqmf.SpecificsManager.initialize(patient_api,hqmfjs,{\"id\" =>\"OccurrenceAPregnancy1\",\"type\" =>\"DIAGNOSIS_ACTIVE_PREGNANCY\",\"function\" =>\"OccurrenceAPregnancy1\"}) }\n\n        // INITIAL PATIENT POPULATION\n        hqmfjs.IPP = function(patient, initialSpecificContext) {\n  return allTrue('IPP',  \n    allTrue('43',     hqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_23(patient, initialSpecificContext),     hqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_25(patient, initialSpecificContext),    \n      atLeastOneTrue('41',       hqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_27(patient, initialSpecificContext),       hqmfjs.EncounterPerformedOfficeVisit_precondition_29(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_31(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_33(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_35(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_37(patient, initialSpecificContext),       hqmfjs.EncounterPerformedHomeHealthcareServices_precondition_39(patient, initialSpecificContext)\n      )\n    )\n  );\n};\n\n\n        // DENOMINATOR\n        hqmfjs.DENOM = function(patient) { return new Boolean(true); }\n        // NUMERATOR\n        hqmfjs.NUMER = function(patient, initialSpecificContext) {\n  return allTrue('NUMER',  \n    allTrue('16',    \n      allTrue('14',       hqmfjs.PhysicalExamFindingBmiPercentile_precondition_8(patient, initialSpecificContext),       hqmfjs.PhysicalExamFindingHeight_precondition_10(patient, initialSpecificContext),       hqmfjs.PhysicalExamFindingWeight_precondition_12(patient, initialSpecificContext)\n      )\n    )\n  );\n};\n\n\n        hqmfjs.DENEX = function(patient, initialSpecificContext) {\n  return atLeastOneTrue('DENEX',  \n    allTrue('7',     hqmfjs.OccurrenceAPregnancy1_precondition_4(patient, initialSpecificContext),    \n      allFalse('6',       hqmfjs.OccurrenceAPregnancy1_precondition_2(patient, initialSpecificContext)\n      )\n    )\n  );\n};\n\n\n        hqmfjs.DENEXCEP = function(patient) { return new Boolean(false); }\n        // CV\n        hqmfjs.MSRPOPL = function(patient) { return new Boolean(false); }\n        hqmfjs.OBSERV = function(patient) { return new Boolean(false); }\n        \n      \n      var occurrenceId = null;\n\n      hqmfjs.initializeSpecifics(patient_api, hqmfjs)\n      \n      var population = function() {\n        return executeIfAvailable(hqmfjs.IPP, patient_api);\n      }\n      var denominator = function() {\n        return executeIfAvailable(hqmfjs.DENOM, patient_api);\n      }\n      var numerator = function() {\n        return executeIfAvailable(hqmfjs.NUMER, patient_api);\n      }\n      var exclusion = function() {\n        return executeIfAvailable(hqmfjs.DENEX, patient_api);\n      }\n      var denexcep = function() {\n        return executeIfAvailable(hqmfjs.DENEXCEP, patient_api);\n      }\n      var msrpopl = function() {\n        return executeIfAvailable(hqmfjs.MSRPOPL, patient_api);\n      }\n      var observ = function(specific_context) {\n        \n        var observFunc = hqmfjs.OBSERV\n        if (typeof(observFunc)==='function')\n          return observFunc(patient_api, specific_context);\n        else\n          return [];\n      }\n      \n      var executeIfAvailable = function(optionalFunction, patient_api) {\n        if (typeof(optionalFunction)==='function') {\n          result = optionalFunction(patient_api);\n          \n          return result;\n        } else {\n          return false;\n        }\n      }\n\n      \n      if (typeof Logger != 'undefined') {\n        // clear out logger\n        Logger.logger = [];\n        Logger.rationale={};\n      \n        // turn on logging if it is enabled\n        if (enable_logging || enable_rationale) {\n          injectLogger(hqmfjs, enable_logging, enable_rationale);\n        }\n      }\n\n      map(patient, population, denominator, numerator, exclusion, denexcep, msrpopl, observ, occurrenceId,false);\n      \n      };\n      "
      continuous_variable false
      category 'static'
      type 'ep'
      episode_of_care true
      sub_id 'a'
      hqmf_doc = source_measure
    end 
  end
end<commit_msg>forgot to add to hqmf doc to the factory<commit_after>FactoryBot.define do
  factory  :measure, :class =>  Measure do
    entry = Rails.root.join('test', 'fixtures', 'artifacts', 'cms127v7.json')
    source_measure = JSON.parse(File.read(entry),:max_nesting => 100)
    sequence( :name) { |i| "Measure Name #{i}" }
    sequence( :hqmf_id) { |i| "53e3f13d-e5cf-445f-8dda-3720aff8401#{i}" }
    sequence( :hqmf_set_id) { |i| "7c00e09b-02dc-458b-8587-7f0347a443f#{i}" }
    continuous_variable false
    category 'none'
    type 'ep'
    episode_of_care true
    trait  :diagnosis do
      hqmf_doc = { 'source_data_criteria'  => { 'DiagnosisActivePregnancy'  =>
                                               { 'title'  => 'Pregnancy',
                                                 'description'  => 'Diagnosis, Active => Pregnancy',
                                                 'standard_category'  => 'diagnosis_condition_problem',
                                                 'qds_data_type'  => 'diagnosis_active',
                                                 'code_list_id'  => '1.5.6.7',
                                                 'type'  => 'conditions',
                                                 'definition'  => 'diagnosis',
                                                 'hard_status'  => false,
                                                 'negation'  => false,
                                                 'source_data_criteria'  => 'DiagnosisActivePregnancy' } },
                   'data_criteria'  => { 'DiagnosisActivePregnancy'  =>
                                        { 'title'  => 'Pregnancy',
                                          'description'  => 'Diagnosis, Active => Pregnancy',
                                          'standard_category'  => 'diagnosis_condition_problem',
                                          'qds_data_type'  => 'diagnosis_active',
                                          'code_list_id'  => '1.5.6.7',
                                          'type'  => 'conditions',
                                          'definition'  => 'diagnosis',
                                          'hard_status'  => false,
                                          'negation'  => false,
                                          'field_values'  => {
                                            'ORDINAL'  => {
                                              'type'  => 'CD',
                                              'code_list_id'  => '1.16.17.18',
                                              'title'  => 'Principal'
                                            }
                                          },
                                          'source_data_criteria'  => 'DiagnosisActivePregnancy' } } }
      hqmf_document { hqmf_doc }
    end
    trait  :no_diagnosis do
      hqmf_doc = { 'source_data_criteria'  => { 'PhysicalExamFindingBmiPercentile'  =>
                                               { 'title'  => 'BMI percentile',
                                                 'description'  => 'Physical Exam, Finding => BMI percentile',
                                                 'standard_category'  => 'physical_exam',
                                                 'qds_data_type'  => 'physical_exam',
                                                 'code_list_id'  => '1.7.8.9',
                                                 'type'  => 'physical_exams',
                                                 'definition'  => 'physical_exam',
                                                 'hard_status'  => false,
                                                 'negation'  => false,
                                                 'source_data_criteria'  => 'PhysicalExamFindingBmiPercentile' } },
                   'data_criteria'  => { 'PhysicalExamFindingBmiPercentile_precondition_8'  =>
                                        { 'title'  => 'BMI percentile',
                                          'description'  => 'Physical Exam, Finding => BMI percentile',
                                          'standard_category'  => 'physical_exam',
                                          'qds_data_type'  => 'physical_exam',
                                          'code_list_id'  => '1.7.8.9',
                                          'type'  => 'physical_exams',
                                          'definition'  => 'physical_exam',
                                          'hard_status'  => false,
                                          'negation'  => false,
                                          'source_data_criteria'  => 'PhysicalExamFindingBmiPercentile',
                                          'temporal_references'  => [
                                            { 'type'  => 'DURING',
                                              'reference'  => 'MeasurePeriod' }
                                          ] } } }
      hqmf_document { hqmf_doc }
    end

    factory  :measure_with_diagnosis, :traits => [ :diagnosis]
    factory  :measure_without_diagnosis, :traits => [ :no_diagnosis]

    factory  :static_measure do
      name 'Static Measure'
      cms_id 'CMS1234'
      hqmf_id 'BE65090C-EB1F-11E7-8C3F-9A214CF093AE'
      hqmf_set_id 'C621C7B6-EB1F-11E7-8C3F-9A214CF093AE'
      
      map_fn "function() {\n        var patient = this;\n        var effective_date = <%= effective_date %>;\n        var enable_logging = <%= enable_logging %>;\n        var enable_rationale = <%= enable_rationale %>;\n\n        hqmfjs = {}\n        <%= init_js_frameworks %>\n        \n        \n      var patient_api = new hQuery.Patient(patient);\n\n      \n        // #########################\n        // ##### DATA ELEMENTS #####\n        // #########################\n\n        OidDictionary = <%= oid_dictionary %>;\n        \n        // Measure variables\nvar MeasurePeriod = {\n  \"low\" => new TS(\"201201010000\", null, true),\n  \"high\" => new TS(\"201212312359\", null, true)\n}\nhqmfjs.MeasurePeriod = function(patient) {\n  return [new hQuery.CodedEntry(\n    {\n      \"start_time\" => MeasurePeriod.low.asDate().getTime()/1000,\n      \"end_time\" => MeasurePeriod.high.asDate().getTime()/1000,\n      \"codes\" => {}\n    }\n  )];\n}\nif (typeof effective_date === 'number') {\n  MeasurePeriod.high.date = new Date(1000*effective_date);\n  // add one minute before pulling off the year.  This turns 12-31-2012 23 =>59 into 1-1-2013 00 =>00  => 1-1-2012 00 =>00\n  MeasurePeriod.low.date = new Date(1000*(effective_date+60));\n  MeasurePeriod.low.date.setFullYear(MeasurePeriod.low.date.getFullYear()-1);\n}\n\n// Data critera\nhqmfjs.OccurrenceAPregnancy1 = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events.specific_occurrence = 'OccurrenceAPregnancy1'\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  events.specificContext=new hqmf.SpecificOccurrence(Row.buildForDataCriteria(events.specific_occurrence, events))\n  return events;\n}\n\nhqmfjs.DiagnosisActivePregnancy = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  hqmf.SpecificsManager.setIfNull(events);\n  return events;\n}\n\nhqmfjs.PatientCharacteristicSexOncAdministrativeSex = function(patient, initialSpecificContext) {\nvar value = patient.gender() || null;\nmatching = matchingValue(value, new CD(\"F\", \"Administrative Sex\"));\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.PatientCharacteristicRaceRace = function(patient, initialSpecificContext) {\nvar value = patient.race() || null;\nmatching = matchingValue(value, null);\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.PatientCharacteristicEthnicityEthnicity = function(patient, initialSpecificContext) {\nvar value = patient.ethnicity() || null;\nmatching = matchingValue(value, null);\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.PatientCharacteristicPayerPayer = function(patient, initialSpecificContext) {\nvar value = patient.payer() || null;\nmatching = matchingValue(value, null);\nmatching.specificContext=hqmf.SpecificsManager.identity();\nreturn matching;\n\n}\n\nhqmfjs.OccurrenceAPregnancy1_precondition_4 = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events.specific_occurrence = 'OccurrenceAPregnancy1'\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = SBE(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.OccurrenceAPregnancy1_precondition_2 = function(patient, initialSpecificContext) {\n  var events = patient.allProblems();\n  events.specific_occurrence = 'OccurrenceAPregnancy1'\n  events = events.withStatuses([\"active\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.5.6.7\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = EBS(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PhysicalExamFindingBmiPercentile_precondition_8 = function(patient, initialSpecificContext) {\n  var events = patient.procedureResults();\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.7.8.9\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PhysicalExamFindingHeight_precondition_10 = function(patient, initialSpecificContext) {\n  var events = patient.procedureResults();\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.8.9.10\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PhysicalExamFindingWeight_precondition_12 = function(patient, initialSpecificContext) {\n  var events = patient.procedureResults();\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.9.10.11\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.InterventionPerformedCounselingForNutrition_precondition_17 = function(patient, initialSpecificContext) {\n  var events = patient.allProcedures();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.10.11.12\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.InterventionPerformedCounselingForPhysicalActivity_precondition_20 = function(patient, initialSpecificContext) {\n  var events = patient.allProcedures();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.11.12.13\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_23 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(new PQ(3, \"a\", true), null));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_25 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(null, new PQ(17, \"a\", true)));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_27 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.4.5.6\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedOfficeVisit_precondition_29 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.3.4.5\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_31 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.12.13.14\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_33 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.13.14.15\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_35 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.14.15.16\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_37 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.15.16.17\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedHomeHealthcareServices_precondition_39 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.6.7.8\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_44 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(new PQ(3, \"a\", true), null));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_46 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(null, new PQ(11, \"a\", true)));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_48 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.4.5.6\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedOfficeVisit_precondition_50 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.3.4.5\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_52 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.12.13.14\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_54 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.13.14.15\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_56 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.14.15.16\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_58 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.15.16.17\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedHomeHealthcareServices_precondition_60 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.6.7.8\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_65 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(new PQ(12, \"a\", true), null));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_67 = function(patient, initialSpecificContext) {\nvar value = patient.birthtime() || null;\nvar events = [value];\nevents = SBS(events, hqmfjs.MeasurePeriod(patient), new IVL_PQ(null, new PQ(17, \"a\", true)));\nevents.specificContext=hqmf.SpecificsManager.identity();\nreturn events;\n\n}\n\nhqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_69 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.4.5.6\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedOfficeVisit_precondition_71 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.3.4.5\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_73 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.12.13.14\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_75 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.13.14.15\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_77 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.14.15.16\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_79 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.15.16.17\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\nhqmfjs.EncounterPerformedHomeHealthcareServices_precondition_81 = function(patient, initialSpecificContext) {\n  var events = patient.encounters();\n  events = events.withStatuses([\"performed\"]);\n  events = events.withoutNegation();\n  var codes = getCodes(\"1.6.7.8\");\n  var start = null;\n  var end = null;\n  events = events.match(codes, start, end, true);\n\n  if (events.length > 0) events = DURING(events, hqmfjs.MeasurePeriod(patient));\n  else events.specificContext=hqmf.SpecificsManager.empty();\n  return events;\n}\n\n\n\n        // #########################\n        // ##### MEASURE LOGIC #####\n        // #########################\n        \n        hqmfjs.initializeSpecifics = function(patient_api, hqmfjs) { hqmf.SpecificsManager.initialize(patient_api,hqmfjs,{\"id\" =>\"OccurrenceAPregnancy1\",\"type\" =>\"DIAGNOSIS_ACTIVE_PREGNANCY\",\"function\" =>\"OccurrenceAPregnancy1\"}) }\n\n        // INITIAL PATIENT POPULATION\n        hqmfjs.IPP = function(patient, initialSpecificContext) {\n  return allTrue('IPP',  \n    allTrue('43',     hqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_23(patient, initialSpecificContext),     hqmfjs.PatientCharacteristicBirthdateBirthDate_precondition_25(patient, initialSpecificContext),    \n      atLeastOneTrue('41',       hqmfjs.EncounterPerformedFaceToFaceInteraction_precondition_27(patient, initialSpecificContext),       hqmfjs.EncounterPerformedOfficeVisit_precondition_29(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareServicesIndividualCounseling_precondition_31(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareInitialOfficeVisit0To17_precondition_33(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareEstablishedOfficeVisit0To17_precondition_35(patient, initialSpecificContext),       hqmfjs.EncounterPerformedPreventiveCareServicesGroupCounseling_precondition_37(patient, initialSpecificContext),       hqmfjs.EncounterPerformedHomeHealthcareServices_precondition_39(patient, initialSpecificContext)\n      )\n    )\n  );\n};\n\n\n        // DENOMINATOR\n        hqmfjs.DENOM = function(patient) { return new Boolean(true); }\n        // NUMERATOR\n        hqmfjs.NUMER = function(patient, initialSpecificContext) {\n  return allTrue('NUMER',  \n    allTrue('16',    \n      allTrue('14',       hqmfjs.PhysicalExamFindingBmiPercentile_precondition_8(patient, initialSpecificContext),       hqmfjs.PhysicalExamFindingHeight_precondition_10(patient, initialSpecificContext),       hqmfjs.PhysicalExamFindingWeight_precondition_12(patient, initialSpecificContext)\n      )\n    )\n  );\n};\n\n\n        hqmfjs.DENEX = function(patient, initialSpecificContext) {\n  return atLeastOneTrue('DENEX',  \n    allTrue('7',     hqmfjs.OccurrenceAPregnancy1_precondition_4(patient, initialSpecificContext),    \n      allFalse('6',       hqmfjs.OccurrenceAPregnancy1_precondition_2(patient, initialSpecificContext)\n      )\n    )\n  );\n};\n\n\n        hqmfjs.DENEXCEP = function(patient) { return new Boolean(false); }\n        // CV\n        hqmfjs.MSRPOPL = function(patient) { return new Boolean(false); }\n        hqmfjs.OBSERV = function(patient) { return new Boolean(false); }\n        \n      \n      var occurrenceId = null;\n\n      hqmfjs.initializeSpecifics(patient_api, hqmfjs)\n      \n      var population = function() {\n        return executeIfAvailable(hqmfjs.IPP, patient_api);\n      }\n      var denominator = function() {\n        return executeIfAvailable(hqmfjs.DENOM, patient_api);\n      }\n      var numerator = function() {\n        return executeIfAvailable(hqmfjs.NUMER, patient_api);\n      }\n      var exclusion = function() {\n        return executeIfAvailable(hqmfjs.DENEX, patient_api);\n      }\n      var denexcep = function() {\n        return executeIfAvailable(hqmfjs.DENEXCEP, patient_api);\n      }\n      var msrpopl = function() {\n        return executeIfAvailable(hqmfjs.MSRPOPL, patient_api);\n      }\n      var observ = function(specific_context) {\n        \n        var observFunc = hqmfjs.OBSERV\n        if (typeof(observFunc)==='function')\n          return observFunc(patient_api, specific_context);\n        else\n          return [];\n      }\n      \n      var executeIfAvailable = function(optionalFunction, patient_api) {\n        if (typeof(optionalFunction)==='function') {\n          result = optionalFunction(patient_api);\n          \n          return result;\n        } else {\n          return false;\n        }\n      }\n\n      \n      if (typeof Logger != 'undefined') {\n        // clear out logger\n        Logger.logger = [];\n        Logger.rationale={};\n      \n        // turn on logging if it is enabled\n        if (enable_logging || enable_rationale) {\n          injectLogger(hqmfjs, enable_logging, enable_rationale);\n        }\n      }\n\n      map(patient, population, denominator, numerator, exclusion, denexcep, msrpopl, observ, occurrenceId,false);\n      \n      };\n      "
      continuous_variable false
      category 'static'
      type 'ep'
      episode_of_care true
      sub_id 'a'
      hqmf_doc = source_measure
      hqmf_document { hqmf_doc }
    end 
  end
end
{'fraction_non_alphanumeric': 0.143114223080195, 'fraction_numerical': 0.01711219448352583, 'mean_word_length': 3.240513354144988, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 221, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 70, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 202, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7629396', 'n_tokens_mistral': 19748, 'n_tokens_neox': 18553, 'n_words': 3395}