Best JavaScript code snippet using storybook-root
manageProgramController.js
Source:manageProgramController.js
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 }...
programService.js
Source:programService.js
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 };...
programAttributes.js
Source:programAttributes.js
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 };...
Using AI Code Generation
1const { program } = require('storybook-root');2 .command('test')3 .description('test command')4 .action(() => {5 console.log('test');6 });7program.parse(process.argv);8{9 "scripts": {10 },11 "devDependencies": {12 }13}
Using AI Code Generation
1const path = require('path');2const root = require('storybook-root');3const program = root.program;4const test = program({5 {6 }7});8test.command({9 {10 }11 action: function (args, options, logger) {12 console.log('test');13 }14});15test.command({16 {17 }18 action: function (args, options, logger) {19 console.log('test2');20 }21});22module.exports = test;23const test = require('./test');24test.exec();25const path = require('path');26const root = require('storybook-root');27const program = root.program;28const test = program({29 {30 }31});32test.command({33 {34 }35 action: function (args, options, logger) {36 console.log('test');37 }38});39test.command({40 {41 }42 action: function (args, options, logger)
Using AI Code Generation
1import storybookRoot from 'storybook-root'2import { program } from 'commander'3storybookRoot.program(program)4program.parse(process.argv)5import storybookRoot from 'storybook-root'6import { version } from '../package.json'7storybookRoot.packageJson(version)8import storybookRoot from 'storybook-root'9storybookRoot.mainJs()10import storybookRoot from 'storybook-root'11storybookRoot.config({12 storybookRoot: path.resolve(__dirname, '../storybook'),13 storybookConfig: path.resolve(__dirname, '../storybook/.storybook'),14 projectRoot: path.resolve(__dirname, '../'),15})
Using AI Code Generation
1console.log('test.js');2console.log(program);3console.log('src/test.js');4console.log(program);5{ _name: 'storybook-root',6 _events: { newListener: [Function: newListener] },7 { _: [ 'test' ],
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!