How to use program method in ghostjs

Best JavaScript code snippet using ghostjs

manageProgramController.js

Source:manageProgramController.js Github

copy

Full Screen

1'use strict';2angular.module('bahmni.common.uicontrols.programmanagment')3 .controller('ManageProgramController', ['$scope', 'retrospectiveEntryService', '$window', 'programService',4 'spinner', 'messagingService', '$stateParams', '$q', 'confirmBox',5 function ($scope, retrospectiveEntryService, $window, programService,6 spinner, messagingService, $stateParams, $q, confirmBox) {7 var DateUtil = Bahmni.Common.Util.DateUtil;8 $scope.programSelected = {};9 $scope.workflowStateSelected = {};10 $scope.allPrograms = [];11 $scope.programWorkflowStates = [];12 $scope.workflowStatesWithoutCurrentState = [];13 $scope.outComesForProgram = [];14 $scope.configName = $stateParams.configName;15 $scope.today = DateUtil.getDateWithoutTime(DateUtil.now());16 var id = "#programEnrollmentContainer";17 var updateActiveProgramsList = function () {18 spinner.forPromise(programService.getPatientPrograms($scope.patient.uuid).then(function (programs) {19 $scope.activePrograms = programs.activePrograms;20 _.each($scope.activePrograms, function (patientProgram) {21 populateDefaultSelectedState(patientProgram);22 });23 $scope.activePrograms.showProgramSection = true;24 $scope.endedPrograms = programs.endedPrograms;25 $scope.endedPrograms.showProgramSection = true;26 }).then(function () {27 formatProgramDates();28 }), id);29 };30 var populateDefaultSelectedState = function (patientProgram) {31 var activePatientProgramState = getActivePatientProgramState(patientProgram.states);32 patientProgram.selectedState = activePatientProgramState ? activePatientProgramState.state : null;33 };34 var formatProgramDates = function () {35 _.each($scope.activePrograms, function (activeProgram) {36 activeProgram.fromDate = Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(activeProgram.dateEnrolled);37 activeProgram.toDate = Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(activeProgram.dateCompleted);38 });39 _.each($scope.endedPrograms, function (endedProgram) {40 endedProgram.fromDate = Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(endedProgram.dateEnrolled);41 endedProgram.toDate = Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(endedProgram.dateCompleted);42 });43 };44 var getCurrentDate = function () {45 var retrospectiveDate = retrospectiveEntryService.getRetrospectiveDate();46 return DateUtil.parseLongDateToServerFormat(retrospectiveDate);47 };48 var init = function () {49 spinner.forPromise(programService.getAllPrograms().then(function (programs) {50 $scope.allPrograms = programs;51 $scope.allPrograms.showProgramSection = true;52 }), id);53 spinner.forPromise(programService.getProgramAttributeTypes().then(function (programAttributeTypes) {54 $scope.programAttributeTypes = programAttributeTypes;55 }), id);56 $scope.programSelected = null;57 $scope.patientProgramAttributes = {};58 $scope.programEnrollmentDate = null;59 updateActiveProgramsList();60 };61 var successCallback = function () {62 messagingService.showMessage("info", "CLINICAL_SAVE_SUCCESS_MESSAGE_KEY");63 $scope.programSelected = null;64 $scope.workflowStateSelected = null;65 $scope.patientProgramAttributes = {};66 $scope.programEnrollmentDate = null;67 updateActiveProgramsList();68 if ($scope.patientProgram) {69 $scope.patientProgram.editing = false;70 }71 };72 var failureCallback = function (error) {73 var fieldErrorMsg = findFieldErrorIfAny(error);74 var errorMsg = _.isUndefined(fieldErrorMsg) ? "Failed to Save" : fieldErrorMsg;75 messagingService.showMessage("error", errorMsg);76 };77 var findFieldErrorIfAny = function (error) {78 var stateFieldError = objectDeepFind(error, "data.error.fieldErrors.states");79 var errorField = stateFieldError && stateFieldError[0];80 return errorField && errorField.message;81 };82 var objectDeepFind = function (obj, path) {83 if (_.isUndefined(obj)) {84 return undefined;85 }86 var paths = path.split('.'), current = obj, i;87 for (i = 0; i < paths.length; ++i) {88 if (current[paths[i]] == undefined) {89 return undefined;90 } else {91 current = current[paths[i]];92 }93 }94 return current;95 };96 var isThePatientAlreadyEnrolled = function () {97 return _.map($scope.activePrograms, function (program) {98 return program.program.uuid;99 }).indexOf($scope.programSelected.uuid) > -1;100 };101 var isProgramSelected = function () {102 return $scope.programSelected && $scope.programSelected.uuid;103 };104 $scope.hasPatientEnrolledToSomePrograms = function () {105 return !_.isEmpty($scope.activePrograms);106 };107 $scope.hasPatientAnyPastPrograms = function () {108 return !_.isEmpty($scope.endedPrograms);109 };110 $scope.enrollPatient = function () {111 if (!isProgramSelected()) {112 messagingService.showMessage("error", "PROGRAM_MANAGEMENT_SELECT_PROGRAM_MESSAGE_KEY");113 return $q.when({});114 }115 if (isThePatientAlreadyEnrolled()) {116 messagingService.showMessage("error", "PROGRAM_MANAGEMENT_ALREADY_ENROLLED_PROGRAM_MESSAGE_KEY");117 return $q.when({});118 }119 var stateUuid = $scope.workflowStateSelected && $scope.workflowStateSelected.uuid ? $scope.workflowStateSelected.uuid : null;120 return spinner.forPromise(121 programService.enrollPatientToAProgram($scope.patient.uuid, $scope.programSelected.uuid, $scope.programEnrollmentDate, stateUuid, $scope.patientProgramAttributes, $scope.programAttributeTypes)122 .then(successCallback, failureCallback)123 );124 };125 var isProgramStateChanged = function (patientProgram, activePatientProgramState) {126 if (_.isEmpty(activePatientProgramState) && patientProgram.selectedState != undefined) {127 return true;128 }129 return patientProgram.selectedState130 && (patientProgram.selectedState.uuid != activePatientProgramState.state.uuid);131 };132 var isOutcomeSelected = function (patientProgram) {133 return !_.isEmpty(objectDeepFind(patientProgram, 'outcomeData.uuid'));134 };135 var getActivePatientProgramState = function (states) {136 return _.find(states, function (state) {137 return state.endDate == null && !state.voided;138 });139 };140 $scope.updatePatientProgram = function (patientProgram) {141 $scope.patientProgram = patientProgram;142 var activePatientProgramState = getActivePatientProgramState(patientProgram.states);143 var activeStateDate = activePatientProgramState ? DateUtil.parse(activePatientProgramState.startDate) : null;144 var dateCompleted = null;145 if (isProgramStateChanged(patientProgram, activePatientProgramState)) {146 var startDate = getCurrentDate();147 if (activePatientProgramState && DateUtil.isBeforeDate(startDate, activeStateDate)) {148 messagingService.showMessage("error", "PROGRAM_MANAGEMENT_STATE_CANT_START_BEFORE_KEY"149 + " (" + DateUtil.formatDateWithoutTime(activeStateDate) + ")");150 return;151 }152 patientProgram.states.push({153 state: {154 uuid: patientProgram.selectedState.uuid155 },156 startDate: startDate157 });158 }159 if (isOutcomeSelected(patientProgram)) {160 dateCompleted = DateUtil.getDateWithoutTime(getCurrentDate());161 if (activePatientProgramState && DateUtil.isBeforeDate(dateCompleted, activeStateDate)) {162 messagingService.showMessage("error", "PROGRAM_MANAGEMENT_PROGRAM_CANT_END_BEFORE_KEY" + " (" + DateUtil.formatDateWithoutTime(activeStateDate) + ")");163 return;164 }165 }166 spinner.forPromise(167 programService.updatePatientProgram(patientProgram, $scope.programAttributeTypes, dateCompleted)168 .then(successCallback, failureCallback)169 );170 };171 var voidPatientProgram = function (patientProgram, closeConfirmBox) {172 patientProgram.voided = true;173 var promise = programService.updatePatientProgram(patientProgram, $scope.programAttributeTypes)174 .then(successCallback, failureCallback)175 .then(closeConfirmBox);176 spinner.forPromise(promise);177 };178 var unVoidPatientProgram = function (patientProgram, closeConfirmBox) {179 delete patientProgram.voidReason;180 delete patientProgram.voided;181 patientProgram.deleting = false;182 closeConfirmBox();183 };184 $scope.confirmDeletion = function (patientProgram) {185 var scope = {};186 scope.message = 'Are you sure, you want to delete ' + patientProgram.display + '?';187 scope.cancel = _.partial(unVoidPatientProgram, patientProgram, _);188 scope.delete = _.partial(voidPatientProgram, patientProgram, _);189 confirmBox({190 scope: scope,191 actions: [{name: 'cancel', display: 'cancel'}, {name: 'delete', display: 'delete'}],192 className: "ngdialog-theme-default delete-program-popup"193 });194 };195 $scope.toggleDelete = function (program) {196 program.deleting = !program.deleting;197 };198 $scope.toggleEdit = function (program) {199 $scope.tempProgram = angular.copy(program);200 program.editing = !program.editing;201 };202 $scope.cancelChange = function (program) {203 populateDefaultSelectedState(program);204 program.patientProgramAttributes = $scope.tempProgram.patientProgramAttributes;205 program.editing = !program.editing;206 };207 $scope.setWorkflowStates = function (program) {208 $scope.patientProgramAttributes = {};209 $scope.programWorkflowStates = $scope.getStates(program);210 };211 $scope.getStates = function (program) {212 var states = [];213 if (program && program.allWorkflows && program.allWorkflows.length && program.allWorkflows[0].states.length) {214 states = program.allWorkflows[0].states;215 }216 return states;217 };218 $scope.canRemovePatientState = function (state) {219 return state.endDate == null;220 };221 $scope.removePatientState = function (patientProgram) {222 var currProgramState = getActivePatientProgramState(patientProgram.states);223 var currProgramStateUuid = objectDeepFind(currProgramState, 'uuid');224 spinner.forPromise(225 programService.deletePatientState(patientProgram.uuid, currProgramStateUuid)226 .then(successCallback, failureCallback)227 );228 };229 $scope.hasStates = function (program) {230 return program && !_.isEmpty(program.allWorkflows) && !_.isEmpty($scope.programWorkflowStates);231 };232 $scope.hasProgramWorkflowStates = function (patientProgram) {233 return !_.isEmpty($scope.getStates(patientProgram.program));234 };235 $scope.hasOutcomes = function (program) {236 return program.outcomesConcept && !_.isEmpty(program.outcomesConcept.setMembers);237 };238 $scope.getCurrentStateDisplayName = function (program) {239 var currentState = getActivePatientProgramState(program.states);240 return _.get(currentState, 'state.concept.display');241 };242 $scope.getMaxAllowedDate = function (states) {243 var minStartDate = DateUtil.getDateWithoutTime(new Date());244 if (states && angular.isArray(states)) {245 for (var stateIndex = 0; stateIndex < states.length; stateIndex++) {246 if (states[stateIndex].startDate < minStartDate) {247 minStartDate = states[stateIndex].startDate;248 }249 }250 }251 return minStartDate;252 };253 $scope.isIncluded = function (attribute) {254 return !($scope.programSelected && _.includes(attribute.excludeFrom, $scope.programSelected.name));255 };256 init();257 }...

Full Screen

Full Screen

programService.js

Source:programService.js Github

copy

Full Screen

1'use strict';2angular.module('bahmni.common.domain')3 .factory('programService', ['$http', 'programHelper', 'appService', function ($http, programHelper, appService) {4 var PatientProgramMapper = new Bahmni.Common.Domain.PatientProgramMapper();5 var getAllPrograms = function () {6 return $http.get(Bahmni.Common.Constants.programUrl, {params: {v: 'default'}}).then(function (response) {7 var allPrograms = programHelper.filterRetiredPrograms(response.data.results);8 _.forEach(allPrograms, function (program) {9 program.allWorkflows = programHelper.filterRetiredWorkflowsAndStates(program.allWorkflows);10 if (program.outcomesConcept) {11 program.outcomesConcept.setMembers = programHelper.filterRetiredOutcomes(program.outcomesConcept.setMembers);12 }13 });14 return allPrograms;15 });16 };17 var enrollPatientToAProgram = function (patientUuid, programUuid, dateEnrolled, stateUuid, patientProgramAttributes, programAttributeTypes) {18 var attributeFormatter = new Bahmni.Common.Domain.AttributeFormatter();19 var req = {20 url: Bahmni.Common.Constants.programEnrollPatientUrl,21 content: {22 patient: patientUuid,23 program: programUuid,24 dateEnrolled: moment(dateEnrolled).format(Bahmni.Common.Constants.ServerDateTimeFormat),25 attributes: attributeFormatter.removeUnfilledAttributes(attributeFormatter.getMrsAttributes(patientProgramAttributes, (programAttributeTypes || [])))26 },27 headers: {"Content-Type": "application/json"}28 };29 if (!_.isEmpty(stateUuid)) {30 req.content.states = [31 {32 state: stateUuid,33 startDate: moment(dateEnrolled).format(Bahmni.Common.Constants.ServerDateTimeFormat)34 }35 ];36 }37 return $http.post(req.url, req.content, req.headers);38 };39 var getPatientPrograms = function (patientUuid, filterAttributesForProgramDisplayControl, patientProgramUuid) {40 var params = {41 v: "full",42 patientProgramUuid: patientProgramUuid,43 patient: patientUuid44 };45 return $http.get(Bahmni.Common.Constants.programEnrollPatientUrl, {params: params}).then(function (response) {46 var patientPrograms = response.data.results;47 return getProgramAttributeTypes().then(function (programAttributeTypes) {48 if (filterAttributesForProgramDisplayControl) {49 patientPrograms = programHelper.filterProgramAttributes(response.data.results, programAttributeTypes);50 }51 return programHelper.groupPrograms(patientPrograms);52 });53 });54 };55 var savePatientProgram = function (patientProgramUuid, content) {56 var req = {57 url: Bahmni.Common.Constants.programEnrollPatientUrl + "/" + patientProgramUuid,58 content: content,59 headers: {"Content-Type": "application/json"}60 };61 return $http.post(req.url, req.content, req.headers);62 };63 var deletePatientState = function (patientProgramUuid, patientStateUuid) {64 var req = {65 url: Bahmni.Common.Constants.programStateDeletionUrl + "/" + patientProgramUuid + "/state/" + patientStateUuid,66 content: {67 "!purge": "",68 "reason": "User deleted the state."69 },70 headers: {"Content-Type": "application/json"}71 };72 return $http.delete(req.url, req.content, req.headers);73 };74 var getProgramAttributeTypes = function () {75 return $http.get(Bahmni.Common.Constants.programAttributeTypes, {params: {v: 'custom:(uuid,name,description,datatypeClassname,datatypeConfig,concept)'}}).then(function (response) {76 var programAttributesConfig = appService.getAppDescriptor().getConfigValue("program");77 var mandatoryProgramAttributes = [];78 for (var attributeName in programAttributesConfig) {79 if (programAttributesConfig[attributeName].required) {80 mandatoryProgramAttributes.push(attributeName);81 }82 }83 return new Bahmni.Common.Domain.AttributeTypeMapper().mapFromOpenmrsAttributeTypes(response.data.results, mandatoryProgramAttributes, programAttributesConfig).attributeTypes;84 });85 };86 var updatePatientProgram = function (patientProgram, programAttributeTypes, dateCompleted) {87 return savePatientProgram(patientProgram.uuid, PatientProgramMapper.map(patientProgram, programAttributeTypes, dateCompleted));88 };89 var getProgramStateConfig = function () {90 var config = appService.getAppDescriptor().getConfigValue('programDisplayControl');91 return config ? config.showProgramStateInTimeline : false;92 };93 var getEnrollmentInfoFor = function (patientUuid, representation) {94 var params = {95 patient: patientUuid,96 v: representation97 };98 return $http.get(Bahmni.Common.Constants.programEnrollPatientUrl, { params: params }).then(function (response) {99 return response.data.results;100 });101 };102 return {103 getAllPrograms: getAllPrograms,104 enrollPatientToAProgram: enrollPatientToAProgram,105 getPatientPrograms: getPatientPrograms,106 savePatientProgram: savePatientProgram,107 updatePatientProgram: updatePatientProgram,108 deletePatientState: deletePatientState,109 getProgramAttributeTypes: getProgramAttributeTypes,110 getProgramStateConfig: getProgramStateConfig,111 getEnrollmentInfoFor: getEnrollmentInfoFor112 };...

Full Screen

Full Screen

programAttributes.js

Source:programAttributes.js Github

copy

Full Screen

1'use strict';2angular.module('bahmni.common.uicontrols.programmanagment')3 .controller('ProgramAttributesController', ['$scope', function ($scope) {4 var program = $scope.patientProgram.program;5 $scope.getProgramAttributesMap = function () {6 var programAttributesMap = {};7 var programAttributes = $scope.patientProgram.attributes;8 _.forEach($scope.programAttributeTypes, function (programAttributeType) {9 var programAttribute = getProgramAttributeByType(programAttributes, programAttributeType);10 if (programAttribute != undefined && !programAttribute.voided) {11 programAttributesMap[programAttributeType.name] = programAttribute.value;12 if (isCodedConceptFormat(programAttributeType.format)) {13 programAttributesMap[programAttributeType.name] = programAttribute.value && programAttribute.value.uuid;14 } else if (isDateFormat(programAttributeType.format)) {15 programAttributesMap[programAttributeType.name] = Bahmni.Common.Util.DateUtil.parseServerDateToDate(programAttributesMap[programAttributeType.name]);16 }17 }18 });19 return programAttributesMap;20 };21 $scope.getValueForAttributeType = function (attributeType) {22 var programAttributesMap = $scope.patientProgram.patientProgramAttributes;23 if (isDateFormat(attributeType.format)) {24 return programAttributesMap[attributeType.name] ? Bahmni.Common.Util.DateUtil.formatDateWithoutTime(programAttributesMap[attributeType.name]) : "";25 } else if (isCodedConceptFormat(attributeType.format)) {26 var mrsAnswer = _.find(attributeType.answers, function (answer) {27 return answer.conceptId == programAttributesMap[attributeType.name];28 });29 return mrsAnswer ? mrsAnswer.description : "";30 } else {31 return programAttributesMap[attributeType.name];32 }33 };34 $scope.isIncluded = function (attribute) {35 return !(program && _.includes(attribute.excludeFrom, program.name));36 };37 var getProgramAttributeByType = function (programAttributes, attributeType) {38 return _.find(programAttributes, function (programAttribute) {39 return programAttribute.attributeType.uuid == attributeType.uuid;40 });41 };42 var isDateFormat = function (format) {43 return format == "org.openmrs.util.AttributableDate" || format == "org.openmrs.customdatatype.datatype.DateDatatype";44 };45 var isCodedConceptFormat = function (format) {46 return format == "org.bahmni.module.bahmnicore.customdatatype.datatype.CodedConceptDatatype";47 };48 $scope.patientProgram.patientProgramAttributes = $scope.getProgramAttributesMap();49 }])50 .directive('programAttributes', function () {51 return {52 controller: 'ProgramAttributesController',53 templateUrl: "../common/uicontrols/programmanagement/views/programAttributes.html",54 scope: {55 patientProgram: "=",56 programAttributeTypes: "="57 }58 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var ghost = require('ghostjs');2 ghost.fill('input[name="q"]', 'Hello World', function() {3 ghost.press('Enter', function() {4 ghost.wait(2000, function() {5 ghost.screenshot('google.png', function() {6 ghost.exit();7 });8 });9 });10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var ghost = require('ghostjs');2.then(function() {3 return ghost.fill('input[name="q"]', 'ghostjs');4})5.then(function() {6 return ghost.press('Enter');7})8.then(function() {9 return ghost.wait(2000);10})11.then(function() {12 return ghost.screenshot('google.png');13})14.then(function() {15 return ghost.exit();16})17.catch(function(error) {18 console.log(error);19});20var ghost = require('ghostjs');21ghost.create()22.then(function(ghost) {23 .then(function() {24 return ghost.fill('input[name="q"]', 'ghostjs');25 })26 .then(function() {27 return ghost.press('Enter');28 })29 .then(function() {30 return ghost.wait(2000);31 })32 .then(function() {33 return ghost.screenshot('google.png');34 })35 .then(function() {36 return ghost.exit();37 })38 .catch(function(error) {39 console.log(error);40 });41})42.catch(function(error) {43 console.log(error);44});45### ghost.open(url)46.then(function() {47})48.catch(function(error) {49});50### ghost.fill(selector, value)51ghost.fill('input[name="q"]', 'ghostjs')52.then(function() {53})54.catch(function(error) {55});56### ghost.press(key)57ghost.press('Enter')58.then(function() {59})60.catch(function(error) {61});62### ghost.screenshot(path)63ghost.screenshot('google.png')64.then(function() {65})66.catch(function(error) {67});68### ghost.wait(time)69ghost.wait(2000)70.then(function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var ghost = require('ghostjs');2ghost.create().then(function (g) {3 g.sendKeys('input[name="q"]', 'hello world').then(function () {4 g.click('input[name="btnG"]').then(function () {5 g.wait(3000).then(function () {6 g.screenshot('test.png').then(function () {7 g.exit();8 });9 });10 });11 });12 });13});14### ghost.create([options])15### ghost.exit()16### ghost.open(url)17### ghost.wait(ms)18### ghost.click(selector)19### ghost.sendKeys(selector, keys)20### ghost.screenshot(path)21### ghost.evaluate(fn[, args])22### ghost.injectJs(url)23### ghost.injectCss(url)24### ghost.injectJQuery()

Full Screen

Using AI Code Generation

copy

Full Screen

1 .version('0.0.1')2 .option('-u, --url [url]', 'URL to test')3 .option('-d, --delay [delay]', 'Delay between tests')4 .option('-t, --timeout [timeout]', 'Timeout for tests')5 .parse(process.argv);6if (program.url) {7}8if (program.delay) {9}10if (program.timeout) {11}12MIT © [Gustavo Marques](

Full Screen

Using AI Code Generation

copy

Full Screen

1var ghostjs = require('ghostjs');2var program = ghostjs.program;3var options = { 4};5program.run('test.js', options, function(err, result){6});7var ghostjs = require('ghostjs');8var program = ghostjs.program;9var options = { 10};11program.run('test.js', options, function(err, result){12});13var ghostjs = require('ghostjs');14var program = ghostjs.program;15var options = { 16};17program.run('test.js', options);18var ghostjs = require('ghostjs');19var program = ghostjs.program;20var options = { 21};22program.run('test.js', options, function(err, result){23});24var ghostjs = require('ghostjs');25var program = ghostjs.program;26var options = { 27};28program.run('test.js', options);29var ghostjs = require('ghostjs');30var program = ghostjs.program;31var options = { 32};33program.run('test.js', options, function(err, result){34});35var ghostjs = require('ghostjs');36var program = ghostjs.program;37var options = { 38};39program.run('test.js', options);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ghostjs automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful