33import gov .cms .madie .madiefhirservice .constants .UriConstants ;
44import gov .cms .madie .madiefhirservice .cql .LibraryCqlVisitorFactory ;
55import gov .cms .madie .madiefhirservice .dto .CqlLibraryDetails ;
6+ import gov .cms .madie .models .dto .CqlLibraryDto ;
67import gov .cms .madie .madiefhirservice .utils .FhirResourceHelpers ;
78import gov .cms .madie .models .library .CqlLibrary ;
89import lombok .extern .slf4j .Slf4j ;
@@ -42,40 +43,48 @@ public LibraryTranslatorService(
4243
4344 public Library convertToFhirLibrary (
4445 CqlLibrary cqlLibrary , Set <String > expressions , String accessToken ) {
45- var visitor = libCqlVisitorFactory .visit (cqlLibrary .getCql ());
46+ return convertToFhirLibrary (LibrarySource .from (cqlLibrary ), expressions , accessToken );
47+ }
48+
49+ public Library convertToFhirLibrary (
50+ CqlLibraryDto cqlLibrary , Set <String > expressions , String accessToken ) {
51+ return convertToFhirLibrary (LibrarySource .from (cqlLibrary ), expressions , accessToken );
52+ }
53+
54+ private Library convertToFhirLibrary (
55+ LibrarySource cqlLibrary , Set <String > expressions , String accessToken ) {
56+ var visitor = libCqlVisitorFactory .visit (cqlLibrary .cql ());
4657 Library library = new Library ();
47- library .setId (cqlLibrary .getCqlLibraryName ());
58+ library .setId (cqlLibrary .name ());
4859 library .setLanguage ("en" );
49- library .setName (cqlLibrary .getCqlLibraryName ());
50- library .setVersion (cqlLibrary .getVersion (). toString ());
60+ library .setName (cqlLibrary .name ());
61+ library .setVersion (cqlLibrary .version ());
5162 library .setDate (new Date ());
5263 library .setStatus (Enumerations .PublicationStatus .ACTIVE );
5364 library .setPublisher (
54- cqlLibrary .getPublisher () != null && StringUtils .isNotBlank (cqlLibrary .getPublisher ())
55- ? cqlLibrary .getPublisher ()
65+ cqlLibrary .publisher () != null && StringUtils .isNotBlank (cqlLibrary .publisher ())
66+ ? cqlLibrary .publisher ()
5667 : UNKNOWN_VALUE );
57- library .setDescription (Objects .toString (cqlLibrary .getDescription (), UNKNOWN_VALUE ));
58- library .setExperimental (cqlLibrary .isExperimental ());
59- library .setContent (
60- createContent (cqlLibrary .getCql (), cqlLibrary .getElmJson (), cqlLibrary .getElmXml ()));
68+ library .setDescription (Objects .toString (cqlLibrary .description (), UNKNOWN_VALUE ));
69+ library .setExperimental (cqlLibrary .experimental ());
70+ library .setContent (createContent (cqlLibrary .cql (), cqlLibrary .elmJson (), cqlLibrary .elmXml ()));
6171 library .setType (createType (UriConstants .CodeSystem .LIBRARY_SYSTEM_TYPE_URI , SYSTEM_CODE ));
62- library .setUrl (
63- FhirResourceHelpers .buildResourceFullUrl ("Library" , cqlLibrary .getCqlLibraryName ()));
72+ library .setUrl (FhirResourceHelpers .buildResourceFullUrl ("Library" , cqlLibrary .name ()));
6473 library .getExtension ().addAll (visitor .getDrcExtensions ());
6574 library .setMeta (createLibraryMeta ());
66- library .setTitle (cqlLibrary .getCqlLibraryName ());
67- library .setPublisher (cqlLibrary .getPublisher ());
75+ library .setTitle (cqlLibrary .name ());
76+ library .setPublisher (cqlLibrary .publisher ());
6877 Identifier identifier = new Identifier ();
6978 identifier .setUse (IdentifierUse .OFFICIAL );
7079 identifier .setSystem ("https://madie.cms.gov/login" );
71- identifier .setValue (cqlLibrary .getId ());
80+ identifier .setValue (cqlLibrary .id ());
7281 library .setIdentifier (List .of (identifier ));
7382 // Use the DataRequirementsProcessor to construct data requirements and related artifacts.
7483 Library libraryModuleDefinition =
7584 retrieveLibraryModuleDefinition (
7685 CqlLibraryDetails .builder ()
77- .libraryName (cqlLibrary .getCqlLibraryName ())
78- .cql (cqlLibrary .getCql ())
86+ .libraryName (cqlLibrary .name ())
87+ .cql (cqlLibrary .cql ())
7988 .expressions (expressions )
8089 .build (),
8190 accessToken );
@@ -84,6 +93,44 @@ public Library convertToFhirLibrary(
8493 return library ;
8594 }
8695
96+ private record LibrarySource (
97+ String id ,
98+ String name ,
99+ String version ,
100+ String cql ,
101+ String elmJson ,
102+ String elmXml ,
103+ String publisher ,
104+ String description ,
105+ boolean experimental ) {
106+
107+ private static LibrarySource from (CqlLibrary cqlLibrary ) {
108+ return new LibrarySource (
109+ cqlLibrary .getId (),
110+ cqlLibrary .getCqlLibraryName (),
111+ cqlLibrary .getVersion ().toString (),
112+ cqlLibrary .getCql (),
113+ cqlLibrary .getElmJson (),
114+ cqlLibrary .getElmXml (),
115+ cqlLibrary .getPublisher (),
116+ cqlLibrary .getDescription (),
117+ cqlLibrary .isExperimental ());
118+ }
119+
120+ private static LibrarySource from (CqlLibraryDto cqlLibrary ) {
121+ return new LibrarySource (
122+ cqlLibrary .getId (),
123+ cqlLibrary .getCqlLibraryName (),
124+ cqlLibrary .getVersion (),
125+ cqlLibrary .getCql (),
126+ cqlLibrary .getElmJson (),
127+ cqlLibrary .getElmXml (),
128+ cqlLibrary .getPublisher (),
129+ cqlLibrary .getDescription (),
130+ cqlLibrary .isExperimental ());
131+ }
132+ }
133+
87134 private Library retrieveLibraryModuleDefinition (
88135 CqlLibraryDetails cqlLibraryDetails , String accessToken ) {
89136 org .hl7 .fhir .r5 .model .Library r5moduleDefinition =
0 commit comments