001/*- 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.narrative2; 021 022import org.apache.commons.lang3.builder.ToStringBuilder; 023import org.apache.commons.lang3.builder.ToStringStyle; 024import org.hl7.fhir.instance.model.api.IBase; 025 026import java.util.Collections; 027import java.util.HashSet; 028import java.util.Set; 029 030public class NarrativeTemplate implements INarrativeTemplate { 031 032 private final Set<String> myAppliesToProfiles = new HashSet<>(); 033 private final Set<String> myAppliesToResourceTypes = new HashSet<>(); 034 private final Set<String> myAppliesToDataTypes = new HashSet<>(); 035 private final Set<Class<? extends IBase>> myAppliesToClasses = new HashSet<>(); 036 private final Set<String> myAppliesToFragmentNames = new HashSet<>(); 037 private String myTemplateFileName; 038 private TemplateTypeEnum myTemplateType = TemplateTypeEnum.THYMELEAF; 039 private String myContextPath; 040 private String myTemplateName; 041 042 @Override 043 public String toString() { 044 return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE) 045 .append("name", myTemplateName) 046 .append("fileName", myTemplateFileName) 047 .toString(); 048 } 049 050 public Set<String> getAppliesToDataTypes() { 051 return Collections.unmodifiableSet(myAppliesToDataTypes); 052 } 053 054 public Set<String> getAppliesToFragmentNames() { 055 return Collections.unmodifiableSet(myAppliesToFragmentNames); 056 } 057 058 void addAppliesToFragmentName(String theAppliesToFragmentName) { 059 myAppliesToFragmentNames.add(theAppliesToFragmentName); 060 } 061 062 @Override 063 public String getContextPath() { 064 return myContextPath; 065 } 066 067 public void setContextPath(String theContextPath) { 068 myContextPath = theContextPath; 069 } 070 071 private String getTemplateFileName() { 072 return myTemplateFileName; 073 } 074 075 void setTemplateFileName(String theTemplateFileName) { 076 myTemplateFileName = theTemplateFileName; 077 } 078 079 @Override 080 public Set<String> getAppliesToProfiles() { 081 return Collections.unmodifiableSet(myAppliesToProfiles); 082 } 083 084 void addAppliesToProfile(String theAppliesToProfile) { 085 myAppliesToProfiles.add(theAppliesToProfile); 086 } 087 088 @Override 089 public Set<String> getAppliesToResourceTypes() { 090 return Collections.unmodifiableSet(myAppliesToResourceTypes); 091 } 092 093 void addAppliesToResourceType(String theAppliesToResourceType) { 094 myAppliesToResourceTypes.add(theAppliesToResourceType); 095 } 096 097 @Override 098 public Set<Class<? extends IBase>> getAppliesToClasses() { 099 return Collections.unmodifiableSet(myAppliesToClasses); 100 } 101 102 void addAppliesToClass(Class<? extends IBase> theAppliesToClass) { 103 myAppliesToClasses.add(theAppliesToClass); 104 } 105 106 @Override 107 public TemplateTypeEnum getTemplateType() { 108 return myTemplateType; 109 } 110 111 void setTemplateType(TemplateTypeEnum theTemplateType) { 112 myTemplateType = theTemplateType; 113 } 114 115 @Override 116 public String getTemplateName() { 117 return myTemplateName; 118 } 119 120 NarrativeTemplate setTemplateName(String theTemplateName) { 121 myTemplateName = theTemplateName; 122 return this; 123 } 124 125 @Override 126 public String getTemplateText() { 127 return NarrativeTemplateManifest.loadResource(getTemplateFileName()); 128 } 129 130 void addAppliesToDatatype(String theDataType) { 131 myAppliesToDataTypes.add(theDataType); 132 } 133}