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