001package org.hl7.fhir.validation.instance.type; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import org.hl7.fhir.r5.elementmodel.Element; 007import org.hl7.fhir.r5.model.Attachment; 008import org.hl7.fhir.r5.model.Library; 009import org.hl7.fhir.r5.model.Measure; 010import org.hl7.fhir.r5.model.Measure.MeasureGroupComponent; 011import org.hl7.fhir.utilities.xml.XMLUtil; 012 013public class MeasureContext { 014 015 016 public static final String USER_DATA_ELM = "validator.ELM"; 017 private List<Library> libs = new ArrayList<>(); 018 private Measure measure; 019 private Element report; 020 021 public MeasureContext() { 022 023 } 024 public MeasureContext(Measure measure, Element report) { 025 this.measure = measure; 026 this.report = report; 027 } 028 029 public void seeLibrary(Library l) { 030 libs.add(l); 031 for (Attachment att : l.getContent()) { 032 if ("application/elm+xml".equals(att.getContentType())) { 033 try { 034 l.setUserData(USER_DATA_ELM, XMLUtil.parseToDom(att.getData(), true)); 035 } catch (Exception e) { 036 l.setUserData(USER_DATA_ELM, e.getMessage()); 037 } 038 } 039 } 040 } 041 042 public List<MeasureGroupComponent> groups() { 043 return measure.getGroup(); 044 } 045 046 public Measure measure() { 047 return measure; 048 } 049 050 public String reportType() { 051 return report.getChildValue("type"); 052 } 053 public String scoring() { 054 return measure.getScoring().getCodingFirstRep().getCode(); 055 } 056 public List<Library> libraries() { 057 return libs; 058 } 059 060}