diff --git a/src/main/java/gov/cms/mat/cql_elm_translation/service/CqlConversionService.java b/src/main/java/gov/cms/mat/cql_elm_translation/service/CqlConversionService.java index a1d1dbec..45e4210c 100644 --- a/src/main/java/gov/cms/mat/cql_elm_translation/service/CqlConversionService.java +++ b/src/main/java/gov/cms/mat/cql_elm_translation/service/CqlConversionService.java @@ -6,6 +6,7 @@ import gov.cms.mat.cql_elm_translation.cql_translator.MadieLibrarySourceProvider; import gov.cms.mat.cql_elm_translation.cql_translator.TranslationResource; import gov.cms.mat.cql_elm_translation.data.RequestData; +import gov.cms.mat.cql_elm_translation.exceptions.InternalServerException; import gov.cms.mat.cql_elm_translation.service.filters.AnnotationErrorFilter; import gov.cms.mat.cql_elm_translation.service.filters.CqlTranslatorExceptionFilter; import gov.cms.mat.cql_elm_translation.service.support.CqlExceptionErrorProcessor; @@ -130,20 +131,25 @@ public List getElmForCql(String cql, String accessToken) throws IOExcept setUpLibrarySourceProvider(cql, accessToken); CqlTranslator translator = processCqlData(requestData); String library = translator.toJson(); - var result = new HashMap(); - for (Map.Entry entry : - translator.getTranslatedLibraries().entrySet()) { - result.put(entry.getKey(), convertToXml(entry.getValue().getLibrary())); - } + List libraries = new ArrayList<>(); + translator + .getTranslatedLibraries() + .forEach( + (key, value) -> { + try { + libraries.add(convertToJson(value.getLibrary())); + } catch (IOException e) { + throw new InternalServerException(e.getMessage()); + } + }); - List libraries = new ArrayList<>(result.values()); libraries.add(library); return libraries; } - public static String convertToXml(Library library) throws IOException { + public static String convertToJson(Library library) throws IOException { StringWriter writer = new StringWriter(); - ElmLibraryWriterFactory.getWriter(LibraryContentType.XML.mimeType()).write(library, writer); + ElmLibraryWriterFactory.getWriter(LibraryContentType.JSON.mimeType()).write(library, writer); return writer.getBuffer().toString(); }