a U¸mg»ã@sdZddlZGdd„dƒZdS)zW Functionality for processing query data output - set_query_mode - process_data_output éNc@s€eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„ZdS)ÚQueryFormatterz0 fe -> filter editor object is required cCs| ¡|_d|_d|_dS)N)Ú cache_loaderÚ_QueryFormatter__filter_cacheÚ_QueryFormatter__query_modeÚ_QueryFormatter__private_filter)ÚselfÚfe©r úR/home/cmiss/Jenkins/workspace/12-Labours-API/app/function/query/query_formatter.pyÚ__init__s zQueryFormatter.__init__cCs ||_dS)z0 Handler for setting query_mode N)r)rÚmoder r r Úset_query_modeszQueryFormatter.set_query_modecCs ||_dS)z4 Handler for setting private_filter N)r)rÚfilter_r r r Úset_private_filtersz!QueryFormatter.set_private_filtercCs`i}|D]R}|d}| d¡d}| d¡}|||…}||vrL|g||<q|| |¡q|S)z: Handler for generating related mri paths Úfilenameú/éÚ_)ÚrindexÚappend)rÚdataZ mri_pathsrÚfilepathÚstartÚendrr r r Ú_handle_mri_paths   zQueryFormatter._handle_mri_pathcCsJ||vrFi}||d<|d ¡|d<|d›d|d›|d<|||<dS) z@ Handler for updating facet mode related facets ÚfacetÚtitleÚtermÚnodeÚ>ÚfieldÚ facetPropPathN)Ú capitalize)rÚrelated_facetsÚ facet_nameÚcontentZ facet_formatr r r Ú_update_facet_mode/s z!QueryFormatter._update_facet_modecCs>|d ¡}||vr0|||vr:|| |¡n |g||<dS)zA Handler for updating detail mode related facets rN)r"r)rr#r$r%rr r r Ú_update_detail_mode;s   z"QueryFormatter._update_detail_modecCsHt|tƒr.t|tƒr ||vr dS||krDdSnt|tƒrD||vrDdSdS)z: Handler for checking whether facet exist TF)Ú isinstanceÚstrÚlist)rÚ facet_valueÚ field_valuer r r Ú_handle_facet_checkFs z"QueryFormatter._handle_facet_checkc Cs–d| ¡›}|j|}||jvr,|j|}|d ¡D]X\}}|D]J}||} | || ¡rD|jdkrv| |||¡qD|jdkrD| |||¡qDq8dS)z4 Handler for updating related facet ZMAPPED_ÚfacetsÚdetailrN)ÚupperrrÚitemsr-rr'r&) rr#r rÚmapped_elementr%r$r+rr,r r r Ú_update_related_facetXs      z$QueryFormatter._update_related_facetcCsŠg}|j ¡D]v}t dd|d¡}|d}|dkr6q|dkrp| d|›¡| d|›¡| d |›¡q| |›d |›¡q|S) z5 Handler for generating facet source Z_filterÚsrr Ú experimentsZ manifestsz scaffolds>zplots>z dicomImages>r)rÚvaluesÚreÚsubr)rÚsourcesZmapped_contentrr r r r Ú_handle_facet_sourceisz#QueryFormatter._handle_facet_sourcecCsni}| ¡D]F}| d¡d}| d¡d}||vr ||gkr | ||||¡q |jdkrb|St| ¡ƒS)zQ Handler for generating related facets for corresponding dataset rrrr/)r:Úsplitr3rr*r6)rrr#rÚkeyr r r r Ú_handle_related_facet{s  z$QueryFormatter._handle_related_facetcCsBg}|D]4}|d}d|vrt dd|d¡|d<| |¡q|S)z> Handler for updating mri data, keep one only rZ_c0Ú)r7r8r)rrÚmrisrrr r r Ú _handle_mri‰s zQueryFormatter._handle_mricCsHi}|D]2}|d}| d¡}|d|…}||vr|||<qt| ¡ƒS)zF Handler for updating dicom image data, keep one only rrN)rr*r6)rrZ dicom_imagesrrÚindexZ folder_pathr r r Ú_handle_dicom_image•s   z"QueryFormatter._handle_dicom_imagecCs@|dgkr| |d¡|d<|dgkr<| |d¡|d<|S)z5 Handler for updating detail content Ú dicomImagesr?)rBr@)rrr r r Ú_handle_detail_content¤s   z%QueryFormatter._handle_detail_contentcCszi}|jdkr||d<n^|jdkr@| |¡|d<| |¡|d<n6|jdkrZ| |¡|d<n|jdkrv| |d¡|d<|S)zO Handler for processing data output to support portal services rr/rÚmrir?)rrDr=r)rrÚresultr r r Úprocess_data_output°s     z"QueryFormatter.process_data_outputN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r r rrr&r'r-r3r:r=r@rBrDrGr r r r r s    r)rKr7rr r r r Ús