/**
 * Copyright 2017 - 2019  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 { AsyncSubject , Observable , of as observableOf } from 'rxjs' ; import { Study } from '../../models/constraint-models/study' ; import { ExportJob } from '../../models/export-models/export-job' ; import { Cohort } from '../../models/cohort-models/cohort' ; import { Constraint } from '../../models/constraint-models/constraint' ; import { DataTable } from '../../models/table-models/data-table' ; import { CrossTable } from '../../models/table-models/cross-table' ; import { Aggregate } from '../../models/aggregate-models/aggregate' ; import { ConceptConstraint } from '../../models/constraint-models/concept-constraint' ; import { TrialVisit } from '../../models/constraint-models/trial-visit' ; import { CountItem } from '../../models/aggregate-models/count-item' ; import { TransmartHttpService } from '../http/transmart-http.service' ; import { ExportDataType } from '../../models/export-models/export-data-type' ; import { CategoricalAggregate } from '../../models/aggregate-models/categorical-aggregate' ; import { TransmartPatient } from '../../models/transmart-models/transmart-patient' ; import { SubjectSet } from '../../models/constraint-models/subject-set' ; import { TransmartDimension } from '../../models/transmart-models/transmart-dimension' ; import { ServerStatus } from '../../models/server-status' ; export class ResourceServiceMock { private studies : Study [ ] ; private queries : Cohort [ ] ; private treeNodes : object [ ] ; private exportJobs : ExportJob [ ] ; private dataTable : DataTable ; private crossTable : CrossTable ; private aggregate : Aggregate ; cohortSelectionCounts : CountItem ; private _status : AsyncSubject < ServerStatus > = new AsyncSubject < ServerStatus > ( ) ; serverStatus = ServerStatus . UP ; constructor ( ) { this . studies = [ ] ; this . queries = [ ] ; this . treeNodes = [ ] ; this . exportJobs = [ ] ; this . dataTable = new DataTable ( ) ; this . crossTable = new CrossTable ( ) ; this . aggregate = new Aggregate ( ) ; } init ( ) { this . _status . next ( this . serverStatus ) ; this . _status . complete ( ) ; } get status ( ) : AsyncSubject < ServerStatus > { return this . _status ; } updateCohortSelectionCounts ( constraint ) { return new Promise < any > ( ( resolve , reject ) => { this . cohortSelectionCounts = new CountItem ( 200 , 1000 ) ; resolve ( true ) ; } ) ; } getStudies ( ) { return observableOf ( this . studies ) ; } getPedigrees ( ) { return observableOf ( [ ] ) ; } getCohorts ( ) { return observableOf ( this . queries ) ; } getSubjects ( constraint ) { let p1 = new TransmartPatient ( ) ; p1 . id = 1 ; p1 . inTrialId = 'in1' ; p1 . subjectIds = { SUBJ_ID : 'one' } ; let p2 = new TransmartPatient ( ) ; p2 . id = 2 ; p2 . inTrialId = 'in2' ; p2 . subjectIds = { SUBJ_ID : 'two' } ; let p3 = new TransmartPatient ( ) ; p3 . id = 3 ; p3 . inTrialId = 'in3' ; p3 . subjectIds = { SUBJ_ID : 'three' } ; return observableOf ( [ p1 , p2 , p3 ] ) ; } getTreeNodes ( root , depth , hasCounts , hasTags ) { return observableOf ( this . treeNodes ) ; } getExportJobs ( ) { let newExportJob = new ExportJob ( ) ; newExportJob . id = 'id' ; newExportJob . name = 'test job name' ; this . exportJobs = [ newExportJob ] ; return observableOf ( this . exportJobs ) ; } getDataTable ( dataTable ) { return observableOf ( this . dataTable ) ; } get sortableDimensions ( ) : Set < string > { return TransmartHttpService . sortableDimensions ; } getCrossTable ( crossTable ) { return observableOf ( this . crossTable ) ; } getCounts ( constraint ) { return observableOf ( { } ) ; } getCountsPerStudyAndConcept ( constraint ) { let map1 = new Map < string , CountItem > ( ) ; let item1 = new CountItem ( 10 , 20 ) ; map1 . set ( 'concept1' , item1 ) ; let map2 = new Map < string , CountItem > ( ) ; let item2 = new CountItem ( 30 , 110 ) ; let item3 = new CountItem ( 70 , 90 ) ; map2 . set ( 'concept2' , item2 ) ; map2 . set ( 'concept3' , item3 ) ; let map = new Map < string , Map < string , CountItem > > ( ) ; map . set ( 'study1' , map1 ) ; map . set ( 'study2' , map2 ) ; return observableOf ( map ) ; } getCountsPerStudy ( constraint ) { let map = new Map < string , CountItem > ( ) ; let item1 = new CountItem ( 10 , 20 ) ; let item2 = new CountItem ( 100 , 200 ) ; map . set ( 'study1' , item1 ) ; map . set ( 'study2' , item2 ) ; return observableOf ( map ) ; } getCountsPerConcept ( constraint ) { let map = new Map < string , CountItem > ( ) ; let item1 = new CountItem ( 10 , 20 ) ; let item2 = new CountItem ( 30 , 110 ) ; let item3 = new CountItem ( 70 , 90 ) ; map . set ( 'concept1' , item1 ) ; map . set ( 'concept2' , item2 ) ; map . set ( 'concept3' , item3 ) ; return observableOf ( map ) ; } getAggregate ( constraint ) { return observableOf ( this . aggregate ) ; } getCategoricalAggregate ( constraint ) { let agg = new CategoricalAggregate ( ) ; return observableOf ( agg ) ; } getTrialVisits ( constraint ) { return observableOf ( [ ] ) ; } logout ( ) { return observableOf ( { } ) ; } diffCohort ( id ) { return observableOf ( [ { } ] ) ; } deleteCohort ( id ) { return observableOf ( { } ) ; } getExportDataTypes ( constraint ) { return observableOf ( [ ] ) ; } saveCohort ( target ) { return observableOf ( new Cohort ( 'id' , 'name' ) ) ; } createExportJob ( name ) { let newExportJob = new ExportJob ( ) ; newExportJob . id = 'id' ; newExportJob . name = 'test job name' ; return observableOf ( newExportJob ) ; } runExportJob ( job , dataTypes , constraint , dataTable , dateColumnsIncluded ) { let newExportJob = new ExportJob ( ) ; newExportJob . id = 'id' ; newExportJob . name = 'test job name' ; return observableOf ( newExportJob ) ; } downloadExportJob ( jobId ) { return Observable . of ( new Blob ( ) ) ; } cancelExportJob ( jobId ) { return Observable . of ( { } ) ; } archiveExportJob ( jobId ) { return Observable . of ( { } ) ; } saveSubjectSet ( name , constraint ) { let subjectSet = new SubjectSet ( ) ; subjectSet . id = 1 ; subjectSet . requestConstraints = constraint ; return Observable . of ( subjectSet ) ; } get subjectDimensions ( ) : Observable < TransmartDimension [ ] > { return Observable . of ( [ ] ) ; } }