HL7TemplateFunctions { public String evaluateTemplate(String templateName, Map<String, Object> bindings) { if (templateName == null) { log.info("Template name is null"); return ""; } HL7Template template = getHl7queryService().getHL7TemplateByName(templateName); if (template == null) { log.info("Could not find a template by the name of " + templateName); return ""; } return getHl7queryService().evaluateTemplate(template, bindings); }  void setHl7queryService(HL7QueryService hl7queryService); void setAdminService(AdministrationService adminService); String evaluateTemplate(String templateName, Map<String, Object> bindings); String getGlobalProperty(String globalPropertyName); String getImplementationId(); String formatDate(Date date, String format); Set<Obs> getObsGroups(Encounter encounter); Concept getMedicalRecordObservationsConcept(); String getUnits(Concept concept); static Log log; }
@Test public void getGlobalProperty_shouldReturnGpIfGpExists() throws Exception { String GPNAME = "customgp"; Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(GPNAME, "acustomvalue")); HL7Template t = new HL7Template(); t.setName("customgptemplate"); t.setLanguage(HL7QueryService.LANGUAGE_GROOVY); t.setTemplate("Value is: ${ func.getGlobalProperty('" + GPNAME + "') }"); Context.getService(HL7QueryService.class).saveHL7Template(t); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals("Value is: acustomvalue", functions.evaluateTemplate("customgptemplate", null)); }
@Test public void getGlobalProperty_shouldFindGpIfHl7queryIsLeftOffBeginning() throws Exception { String GPNAME = "customgp"; Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(GPNAME, "acustomvalue")); HL7Template t = new HL7Template(); t.setName("customgp"); t.setLanguage(HL7QueryService.LANGUAGE_GROOVY); t.setTemplate("Value is: ${ func.getGlobalProperty('" + GPNAME + "') }"); Context.getService(HL7QueryService.class).saveHL7Template(t); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals("Value is: acustomvalue", functions.evaluateTemplate("customgp", null)); }
@Test public void evaluateTemplate_shouldPassThroughToServiceLayerEvaluateMethod() throws Exception { HL7Template t = new HL7Template(); t.setName("simple"); t.setLanguage(HL7QueryService.LANGUAGE_GROOVY); t.setTemplate("The value of locale.allowed.list is: ${ func.getGlobalProperty('locale.allowed.list') }"); Context.getService(HL7QueryService.class).saveHL7Template(t); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals("The value of locale.allowed.list is: en", functions.evaluateTemplate("simple", null)); }
@Test public void evaluateTemplate_shouldNotFailWithNotFoundTemplate() throws Exception { HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals("", functions.evaluateTemplate("anonexistanttemplate", null)); }
@Test public void getGlobalProperty_shouldReturnEmptyStringIfGpDoesntExist() throws Exception { HL7Template t = new HL7Template(); t.setName("nonexistantgptemplate"); t.setLanguage(HL7QueryService.LANGUAGE_GROOVY); t.setTemplate("-${ func.getGlobalProperty('nonexistantgp') }-"); Context.getService(HL7QueryService.class).saveHL7Template(t); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals("--", functions.evaluateTemplate("nonexistantgptemplate", null)); }
@Test public void getGlobalProperty_shouldPreprendHl7queryIfGpDoesntExist() throws Exception { String GPNAME = "customgp"; Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("hl7query." + GPNAME, "acustomvalue")); HL7Template t = new HL7Template(); t.setName("prefixtesttemplate"); t.setLanguage(HL7QueryService.LANGUAGE_GROOVY); t.setTemplate("Value is: ${ func.getGlobalProperty('" + GPNAME + "') }"); Context.getService(HL7QueryService.class).saveHL7Template(t); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals("Value is: acustomvalue", functions.evaluateTemplate("prefixtesttemplate", null)); }