import { TestPage } from "./lforms_testpage.po" ; import TestUtil from "./util" ; import { browser , logging , element , by , WebElementPromise , ExpectedConditions } from 'protractor' ; import { protractor } from 'protractor/built/ptor' ; import * as FHIRSupport from "../../../src/fhir/versions.js" ; let fhirVersions = Object . keys ( FHIRSupport ) ; let tp ; let LForms = ( global as any ) . LForms ; tp = new TestPage ( ) ; for ( var i = 0 , len = fhirVersions . length ; i < len ; ++ i ) { ( function ( fhirVersion ) { describe ( fhirVersion , function ( ) { beforeAll ( async ( ) => { await browser . waitForAngularEnabled ( false ) ; } ) ; describe ( 'FHIRPath functionality' , function ( ) { describe ( 'FHIRPath calculated-expression' , function ( ) { function testBMIFormula ( ) { tp . loadFromTestData ( 'weightHeightQuestionnaire.json' , fhirVersion ) ; let weightField = element ( by . id ( '/29463-7/1' ) ) ; weightField . click ( ) ; TestUtil . sendKeys ( weightField , '70' ) ; let heightField = element ( by . id ( '/8302-2/1' ) ) ; TestUtil . sendKeys ( heightField , '60' ) ; heightField . click ( ) ; weightField . click ( ) ; let bmiField = element ( by . id ( '/39156-5/1' ) ) ; expect ( TestUtil . getAttribute ( bmiField , 'value' ) ) . toBeCloseTo ( 30 , 0 ) ; } it ( 'work to compute a BMI value' , function ( ) { tp . openBaseTestPage ( ) ; testBMIFormula ( ) ; } ) ; it ( 'work to compute a BMI value with the built files' , function ( ) { tp . openBuildTestFHIRPath ( ) ; testBMIFormula ( ) ; } ) ; } ) ; } ) ; } ) ; } ) ( fhirVersions [ i ] ) ; } describe ( 'answerExpression' , function ( ) { beforeAll ( async ( ) => { await browser . waitForAngularEnabled ( false ) ; tp . openBaseTestPage ( ) ; tp . loadFromTestData ( 'answerExpressionTest.json' ) ; } ) ; it ( 'should be able to populate a list' , function ( ) { var language = element ( by . id ( 'language/1' ) ) ; language . click ( ) ; TestUtil . waitForElementVisible ( element ( by . id ( "searchResults" ) ) ) ; expect ( tp . Autocomp . listIsVisible ( ) ) . toBe ( true ) ; expect ( tp . Autocomp . shownItemCount ( ) ) . toBe ( 2 ) ; } ) ; it ( 'should not cause answerOptions to be generated in the Questionnaire' , function ( ) { browser . executeScript ( 'return LForms.Util.getFormFHIRData("Questionnaire", "R4")' ) . then ( ( val ) => { expect ( val . item [ 0 ] . answerOption ) . toBe ( undefined ) ; } ) ; browser . executeScript ( 'return LForms.Util.getFormFHIRData("Questionnaire", "STU3")' ) . then ( ( val ) => { expect ( val . item [ 0 ] . option ) . toBe ( undefined ) ; } ) ; } ) ; it ( 'should not clear a list field if the form has just loaded with saved data' , function ( ) { tp . loadFromTestData ( 'rxterms.R4.json' , 'R4' ) ; var medField = element ( by . id ( 'medication/1/1' ) ) ; var EC = protractor . ExpectedConditions ; TestUtil . waitForElementPresent ( medField ) ; tp . Autocomp . helpers . autocompPickFirst ( medField , 'ar' ) ; var strengthField = element ( by . id ( 'strength/1/1' ) ) ; TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( TestUtil . fieldHasList ( strengthField ) ) ; tp . Autocomp . helpers . autocompPickFirst ( strengthField ) ; var rxcuiField = element ( by . id ( 'rxcui/1/1' ) ) ; browser . wait ( TestUtil . getAttribute ( rxcuiField , 'value' ) . then ( ( v ) => v != '' ) ) ; browser . executeScript ( 'return LForms.Util.getFormFHIRData(' + '"QuestionnaireResponse", "R4")' ) . then ( ( qr ) => { function checkSavedDataPresent ( ) { TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( ( ) => TestUtil . getAttribute ( strengthField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; browser . wait ( ( ) => TestUtil . getAttribute ( rxcuiField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; browser . wait ( ( ) => strengthField . getAttribute ( 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; browser . wait ( ( ) => rxcuiField . getAttribute ( 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; } tp . openTestPage ( '/test/addFormToPageTest.html' ) ; TestUtil . waitForElementPresent ( element ( by . id ( "/X-002/strengthAndForm/1/1" ) ) ) ; browser . executeScript ( 'LForms.Util.removeFormsFromPage("formContainer")' ) ; browser . executeScript ( 'LForms.Util.removeFormsFromPage("formContainer2")' ) ; var q = JSON . parse ( tp . getTestData ( 'rxterms.R4.json' , 'R4' ) ) ; var qOrig = JSON . parse ( JSON . stringify ( q ) ) ; var qrOrig = JSON . parse ( JSON . stringify ( qr ) ) ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( TestUtil . fieldHasList ( strengthField ) ) ; checkSavedDataPresent ( ) ; qr . item [ 0 ] . item [ 1 ] . answer [ 0 ] . valueCoding . code = 'I am not in the list' ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( TestUtil . fieldHasList ( strengthField ) ) ; checkSavedDataPresent ( ) ; q . item [ 0 ] . extension . splice ( 1 , 1 ) ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( TestUtil . fieldHasList ( strengthField ) ) ; checkSavedDataPresent ( ) ; qr . item [ 0 ] . item [ 0 ] . answer [ 0 ] . valueCoding . code = 'off-list code' ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; checkSavedDataPresent ( ) ; qr . item [ 0 ] . item [ 0 ] . answer [ 0 ] . valueCoding = { display : "Off-list drug name" } ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; checkSavedDataPresent ( ) ; q = JSON . parse ( JSON . stringify ( qOrig ) ) ; qr = JSON . parse ( JSON . stringify ( qrOrig ) ) ; q . item [ 0 ] . item [ 1 ] . repeats = true ; delete q . item [ 0 ] . item [ 2 ] . extension ; qr . item [ 0 ] . item [ 1 ] . answer [ 1 ] = { valueCoding : { display : 'other value' } } ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( TestUtil . fieldHasList ( strengthField ) ) ; TestUtil . waitForElementPresent ( strengthField ) ; browser . wait ( ( ) => TestUtil . getAttribute ( medField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; browser . executeScript ( function ( ) { var strengthField = arguments [ 0 ] ; return strengthField . autocomp . getSelectedItems ( ) ; } , strengthField ) . then ( ( values ) => { expect ( values && values . length ) . toBe ( 2 ) ; } ) ; browser . wait ( ( ) => TestUtil . getAttribute ( rxcuiField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; q = JSON . parse ( JSON . stringify ( qOrig ) ) ; qr = JSON . parse ( JSON . stringify ( qrOrig ) ) ; q . item [ 0 ] . extension . splice ( 1 , 1 ) ; q . item [ 0 ] . item [ 1 ] . extension [ 0 ] = { "url" : "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl" , "valueCodeableConcept" : { "text" : "Radio Button" , "coding" : [ { "code" : "radio-button" , "display" : "Radio Button" , "system" : "http://hl7.org/fhir/questionnaire-item-control" } ] } } ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; TestUtil . waitForElementPresent ( medField ) ; browser . wait ( ( ) => TestUtil . getAttribute ( medField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; let strengthAnswer1 = element ( by . id ( 'strength/1/1213377' ) ) . element ( by . css ( 'input' ) ) ; expect ( strengthAnswer1 . isSelected ( ) ) . toBe ( true ) ; browser . wait ( ( ) => TestUtil . getAttribute ( rxcuiField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; q = JSON . parse ( JSON . stringify ( q ) ) ; qr = JSON . parse ( JSON . stringify ( qr ) ) ; q . item [ 0 ] . item [ 1 ] . repeats = true ; q . item [ 0 ] . item [ 1 ] . extension [ 0 ] = { "url" : "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl" , "valueCodeableConcept" : { "text" : "Check-box" , "coding" : [ { "code" : "check-box" , "display" : "Check-box" , "system" : "http://hl7.org/fhir/questionnaire-item-control" } ] } } ; qr . item [ 0 ] . item [ 1 ] . answer [ 1 ] = { valueString : 'other value' } ; TestUtil . showQQR ( q , qr , 'formContainer' ) ; TestUtil . waitForElementPresent ( medField ) ; browser . wait ( ( ) => TestUtil . getAttribute ( medField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; expect ( strengthAnswer1 . isSelected ( ) ) . toBe ( true ) ; let strengthAnswerOther = element ( by . id ( 'strength/1/1_other' ) ) . element ( by . css ( 'input' ) ) ; let strengthOtherValue = element ( by . id ( 'strength/1/1_otherValue' ) ) ; expect ( strengthAnswerOther . isSelected ( ) ) . toBe ( true ) ; expect ( TestUtil . getAttribute ( strengthOtherValue , 'value' ) ) . toBe ( 'other value' ) ; browser . wait ( ( ) => TestUtil . getAttribute ( rxcuiField , 'value' ) . then ( ( v ) => v != '' ) , 5000 ) ; } ) ; } ) ; } ) ;