001package org.hl7.fhir.r5.renderers; 002 003import org.hl7.fhir.r5.model.DomainResource; 004import org.hl7.fhir.r5.model.Resource; 005import org.hl7.fhir.r5.renderers.utils.RenderingContext; 006import org.hl7.fhir.r5.renderers.utils.ResourceWrapper; 007import org.hl7.fhir.utilities.Utilities; 008 009public class RendererFactory { 010 011 public static ResourceRenderer factory(String resourceName, RenderingContext context) { 012 013 if (context.getTemplateProvider() != null) { 014 String liquidTemplate = context.getTemplateProvider().findTemplate(context, resourceName); 015 if (liquidTemplate != null) { 016 return new LiquidRenderer(context, liquidTemplate); 017 } 018 } 019 switch (resourceName) { 020 case "ActorDefinition": return new ActorDefinitionRenderer(context); 021 case "Bundle": return new BundleRenderer(context); 022 case "CapabilityStatement": return new CapabilityStatementRenderer(context); 023 case "CodeSystem": return new CodeSystemRenderer(context); 024 case "CompartmentDefinition": return new CompartmentDefinitionRenderer(context); 025 case "ConceptMap": return new ConceptMapRenderer(context); 026 case "DiagnosticReport": return new DiagnosticReportRenderer(context); 027 case "ExampleScenario": return new ExampleScenarioRenderer(context); 028 case "ImplementationGuide": return new ImplementationGuideRenderer(context); 029 case "Library": return new LibraryRenderer(context); 030 case "List": return new ListRenderer(context); 031 case "NamingSystem": return new NamingSystemRenderer(context); 032 case "OperationDefinition": return new OperationDefinitionRenderer(context); 033 case "OperationOutcome": return new OperationOutcomeRenderer(context); 034 case "Parameters": return new ParametersRenderer(context); 035 case "Patient": return new PatientRenderer(context); 036 case "Provenance": return new ProvenanceRenderer(context); 037 case "Questionnaire": return new QuestionnaireRenderer(context); 038 case "QuestionnaireResponse": return new QuestionnaireResponseRenderer(context); 039 case "Requirements": return new RequirementsRenderer(context); 040 case "SearchParameter": return new SearchParameterRenderer(context); 041 case "StructureDefinition": return new StructureDefinitionRenderer(context); 042 case "StructureMap": return new StructureMapRenderer(context); 043 case "SubscriptionTopic": return new SubscriptionTopicRenderer(context); 044 case "TestPlan": return new TestPlanRenderer(context); 045 case "ValueSet": return new ValueSetRenderer(context); 046 } 047 return new ProfileDrivenRenderer(context); 048 } 049 050 public static ResourceRenderer factory(Resource resource, RenderingContext context) { 051 052 if (context.getTemplateProvider() != null && resource instanceof DomainResource) { 053 String liquidTemplate = context.getTemplateProvider().findTemplate(context, (DomainResource) resource); 054 if (liquidTemplate != null) { 055 return new LiquidRenderer(context, liquidTemplate); 056 } 057 } 058 059 return factory(resource.fhirType(), context); 060 } 061 062 063 public static ResourceRenderer factory(ResourceWrapper resource, RenderingContext context) { 064 if (context.getTemplateProvider() != null) { 065 String liquidTemplate = context.getTemplateProvider().findTemplate(context, resource.fhirType()); 066 if (liquidTemplate != null) { 067 return new LiquidRenderer(context, liquidTemplate); 068 } 069 } 070 switch (resource.fhirType()) { 071 case "DiagnosticReport": return new DiagnosticReportRenderer(context); 072 case "Library": return new LibraryRenderer(context); 073 case "Questionnaire": return new LibraryRenderer(context); 074 case "List": return new ListRenderer(context); 075 case "Patient": return new PatientRenderer(context); 076 case "Provenance": return new ProvenanceRenderer(context); 077 case "Parameters": return new ParametersRenderer(context); 078 case "QuestionnaireResponse": return new QuestionnaireResponseRenderer(context); 079 } 080 if (resource.isDirect()) { 081 switch (resource.fhirType()) { 082 083 case "ActorDefinition": return new ActorDefinitionRenderer(context); 084 case "Bundle": return new BundleRenderer(context); 085 case "CapabilityStatement": return new CapabilityStatementRenderer(context); 086 case "CodeSystem": return new CodeSystemRenderer(context); 087 case "CompartmentDefinition": return new CompartmentDefinitionRenderer(context); 088 case "ConceptMap": return new ConceptMapRenderer(context); 089 case "ExampleScenario": return new ExampleScenarioRenderer(context); 090 case "ImplementationGuide": return new ImplementationGuideRenderer(context); 091 case "NamingSystem": return new NamingSystemRenderer(context); 092 case "OperationDefinition": return new OperationDefinitionRenderer(context); 093 case "OperationOutcome": return new OperationOutcomeRenderer(context); 094 case "Requirements": return new RequirementsRenderer(context); 095 case "SearchParameter": return new SearchParameterRenderer(context); 096 case "StructureDefinition": return new StructureDefinitionRenderer(context); 097 case "StructureMap": return new StructureMapRenderer(context); 098 case "SubscriptionTopic": return new SubscriptionTopicRenderer(context); 099 case "TestPlan": return new TestPlanRenderer(context); 100 case "ValueSet": return new ValueSetRenderer(context); 101 } 102 } 103 104 return new ProfileDrivenRenderer(context); 105 } 106 107 public static boolean hasSpecificRenderer(String rt) { 108 109 return Utilities.existsInList(rt, 110 "CodeSystem", "ValueSet", "ConceptMap", 111 "CapabilityStatement", "CompartmentDefinition", "ImplementationGuide", "Library", "NamingSystem", "OperationDefinition", 112 "Questionnaire", "SearchParameter", "StructureDefinition", "ActorDefinition", "Requirements", "TestPlan", "ExampleScenario"); 113 } 114 115 /** 116 * This is a list of renderers that return something different in IG mode, and the implementation guide 117 * publisher will regenerate the narrative for the IG mode 118 * @param rt 119 * @return 120 */ 121 public static boolean hasIGSpecificRenderer(String rt) { 122 123 return Utilities.existsInList(rt, "ValueSet", "CapabilityStatement", "Questionnaire"); 124 } 125 126 127}