Class: FHIR::Scorecard

Inherits:
Object
  • Object
show all
Defined in:
lib/scorecard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointsObject

Returns the value of attribute points.



5
6
7
# File 'lib/scorecard.rb', line 5

def points
  @points
end

#reportObject

Returns the value of attribute report.



4
5
6
# File 'lib/scorecard.rb', line 4

def report
  @report
end

Instance Method Details

#score(bundle_raw) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scorecard.rb', line 7

def score(bundle_raw)
  @report = {}
  @points = 0

  # Check that the patient record is a FHIR Bundle.
  bundle = FHIR.from_contents(bundle_raw)
  if bundle.is_a?(FHIR::Bundle)
    @points += 10
    @report[:bundle] = { :points=>10, :message=>'Patient Record is a FHIR Bundle.'}
  else
    @report[:bundle] = { :points=>0, :message=>'Patient Record must be a FHIR Bundle.'}
  end

  if bundle.is_a?(FHIR::Bundle)

    # Check that the patient record contains a FHIR Patient.
    @patient = nil
    count = 0
    bundle.entry.each do |entry|
      if entry.resource && entry.resource.is_a?(FHIR::Patient)
        @patient = entry.resource
        count += 1
      end
    end
    if @patient && count==1
      @points += 10
      @report[:patient] = { :points=>10, :message=>'Patient Record contains one FHIR Patient.'}
    else
      @report[:patient] = { :points=>0, :message=>'Patient Record must contain one FHIR Patient.'}
    end

    report.merge!(FHIR::Rubrics.apply(bundle))
  end

  @report[:points] = @report.values.inject(0){|sum,section| sum+=section[:points]}
  @report
end