001package ca.uhn.fhir.cql.dstu3.builder;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Server - Clinical Quality Language
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.cql.common.builder.BaseBuilder;
024import org.hl7.fhir.dstu3.model.MeasureReport;
025import org.hl7.fhir.dstu3.model.Period;
026import org.hl7.fhir.dstu3.model.Reference;
027import org.hl7.fhir.exceptions.FHIRException;
028import org.opencds.cqf.cql.engine.runtime.Interval;
029
030import java.util.Date;
031
032public class MeasureReportBuilder extends BaseBuilder<MeasureReport> {
033        private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(MeasureReportBuilder.class);
034
035    public MeasureReportBuilder() {
036        super(new MeasureReport());
037    }
038
039    public MeasureReportBuilder buildStatus(String status) {
040        try {
041            this.complexProperty.setStatus(MeasureReport.MeasureReportStatus.fromCode(status));
042        } catch (FHIRException e) {
043                        ourLog.warn("Exception caught while attempting to set Status to '" + status + "', assuming status COMPLETE!"
044                                        + System.lineSeparator() + e.getMessage());
045            this.complexProperty.setStatus(MeasureReport.MeasureReportStatus.COMPLETE);
046        }
047        return this;
048    }
049
050    public MeasureReportBuilder buildType(MeasureReport.MeasureReportType type) {
051        this.complexProperty.setType(type);
052        return this;
053    }
054
055    public MeasureReportBuilder buildMeasureReference(String measureRef) {
056        this.complexProperty.setMeasure(new Reference(measureRef));
057        return this;
058    }
059
060    public MeasureReportBuilder buildPatientReference(String patientRef) {
061        this.complexProperty.setPatient(new Reference(patientRef));
062        return this;
063    }
064
065    public MeasureReportBuilder buildPeriod(Interval period) {
066        this.complexProperty.setPeriod(new Period().setStart((Date) period.getStart()).setEnd((Date) period.getEnd()));
067        return this;
068    }
069}