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