/**
 * Copyright 2017 - 2018  The Hyve B.V.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */ import { TransmartCrossTable } from '../../models/transmart-models/transmart-cross-table' ; import { Row } from '../../models/table-models/row' ; import { CrossTable } from '../../models/table-models/cross-table' ; import { Col } from '../../models/table-models/col' ; export class TransmartCrossTableMapper { param { TransmartCrossTable } tmCrossTable param { CrossTable } crossTable return { CrossTable } public static mapTransmartCrossTable ( tmCrossTable , crossTable ) { const matrix = tmCrossTable . rows ; crossTable . rows = [ ] ; crossTable . cols = [ ] ; let colHeaders = crossTable . columnHeaderConstraints ; for ( let i = 0 ; i < crossTable . columnConstraints . length ; i ++ ) { let row = new Row ( ) ; for ( let rowCon of crossTable . rowConstraints ) { row . addDatumObject ( { isHeader : false , value : '' } ) ; } for ( let colHeader of colHeaders ) { row . addDatumObject ( { isHeader : true , value : colHeader [ i ] . textRepresentation } ) ; } crossTable . rows . push ( row ) ; } let rowHeaders = crossTable . rowHeaderConstraints ; for ( let i = 0 ; i < rowHeaders . length ; i ++ ) { let row = new Row ( ) ; rowHeaders [ i ] . forEach ( constraint => { row . addDatumObject ( { isHeader : true , value : constraint . textRepresentation } ) ; } ) ; for ( let j = 0 ; j < colHeaders . length ; j ++ ) { row . addDatumObject ( { isHeader : false , value : matrix [ i ] [ j ] } ) ; } crossTable . rows . push ( row ) ; } for ( let field in crossTable . rows [ 0 ] . data ) { let col = new Col ( ' - ' , field ) ; crossTable . cols . push ( col ) ; } return crossTable ; } }