001package ca.uhn.fhir.narrative2; 002 003/*- 004 * #%L 005 * HAPI FHIR - Core Library 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.rest.server.exceptions.InternalErrorException; 024import org.hl7.fhir.instance.model.api.IBase; 025 026import java.io.IOException; 027import java.util.Collections; 028import java.util.HashSet; 029import java.util.Set; 030 031public class NarrativeTemplate implements INarrativeTemplate { 032 033 private String myTemplateFileName; 034 private Set<String> myAppliesToProfiles = new HashSet<>(); 035 private Set<String> myAppliesToResourceTypes = new HashSet<>(); 036 private Set<String> myAppliesToDataTypes = new HashSet<>(); 037 private Set<Class<? extends IBase>> myAppliesToClasses = new HashSet<>(); 038 private TemplateTypeEnum myTemplateType = TemplateTypeEnum.THYMELEAF; 039 private String myContextPath; 040 private String myTemplateName; 041 042 public Set<String> getAppliesToDataTypes() { 043 return Collections.unmodifiableSet(myAppliesToDataTypes); 044 } 045 046 @Override 047 public String getContextPath() { 048 return myContextPath; 049 } 050 051 public void setContextPath(String theContextPath) { 052 myContextPath = theContextPath; 053 } 054 055 private String getTemplateFileName() { 056 return myTemplateFileName; 057 } 058 059 void setTemplateFileName(String theTemplateFileName) { 060 myTemplateFileName = theTemplateFileName; 061 } 062 063 @Override 064 public Set<String> getAppliesToProfiles() { 065 return Collections.unmodifiableSet(myAppliesToProfiles); 066 } 067 068 void addAppliesToProfile(String theAppliesToProfile) { 069 myAppliesToProfiles.add(theAppliesToProfile); 070 } 071 072 @Override 073 public Set<String> getAppliesToResourceTypes() { 074 return Collections.unmodifiableSet(myAppliesToResourceTypes); 075 } 076 077 void addAppliesToResourceType(String theAppliesToResourceType) { 078 myAppliesToResourceTypes.add(theAppliesToResourceType); 079 } 080 081 @Override 082 public Set<Class<? extends IBase>> getAppliesToClasses() { 083 return Collections.unmodifiableSet(myAppliesToClasses); 084 } 085 086 void addAppliesToClass(Class<? extends IBase> theAppliesToClass) { 087 myAppliesToClasses.add(theAppliesToClass); 088 } 089 090 @Override 091 public TemplateTypeEnum getTemplateType() { 092 return myTemplateType; 093 } 094 095 void setTemplateType(TemplateTypeEnum theTemplateType) { 096 myTemplateType = theTemplateType; 097 } 098 099 @Override 100 public String getTemplateName() { 101 return myTemplateName; 102 } 103 104 NarrativeTemplate setTemplateName(String theTemplateName) { 105 myTemplateName = theTemplateName; 106 return this; 107 } 108 109 @Override 110 public String getTemplateText() { 111 try { 112 return NarrativeTemplateManifest.loadResource(getTemplateFileName()); 113 } catch (IOException e) { 114 throw new InternalErrorException(e); 115 } 116 } 117 118 void addAppliesToDatatype(String theDataType) { 119 myAppliesToDataTypes.add(theDataType); 120 } 121 122}