'use strict'; angular.module('bahmni.common.domain') .factory('locationService', ['$http', '$bahmniCookieStore', function ($http, $bahmniCookieStore) { var getAllByTag = function (tags, operator) { return $http.get(Bahmni.Common.Constants.locationUrl, { params: {s: "byTags", tags: tags || "", v: "default", operator: operator || "ALL"}, cache: true }); }; var getByUuid = function (locationUuid) { return $http.get(Bahmni.Common.Constants.locationUrl + "/" + locationUuid, { cache: true }).then(function (response) { return response.data; }); }; var getLoggedInLocation = function () { var cookie = $bahmniCookieStore.get(Bahmni.Common.Constants.locationCookieName); return getByUuid(cookie.uuid); }; var getVisitLocation = function (locationUuid) { return $http.get(Bahmni.Common.Constants.bahmniVisitLocationUrl + "/" + locationUuid, { headers: {"Accept": "application/json"} }); }; return { getAllByTag: getAllByTag, getLoggedInLocation: getLoggedInLocation, getByUuid: getByUuid, getVisitLocation: getVisitLocation }; }]); 'use strict'; angular.module('bahmni.registration') .service('patientServiceStrategy', ['$http', '$q', '$rootScope', function ($http, $q, $rootScope) { var openmrsUrl = Bahmni.Registration.Constants.openmrsUrl; var baseOpenMRSRESTURL = Bahmni.Registration.Constants.baseOpenMRSRESTURL; var search = function (config) { var defer = $q.defer(); var patientSearchUrl = Bahmni.Common.Constants.bahmniSearchUrl + "/patient"; if (config && config.params.identifier) { patientSearchUrl = Bahmni.Common.Constants.bahmniSearchUrl + "/patient/lucene"; } var onResults = function (result) { defer.resolve(result); }; $http.get(patientSearchUrl, config).success(onResults) .error(function (error) { defer.reject(error); }); return defer.promise; }; var getByUuid = function (uuid) { var url = openmrsUrl + "/ws/rest/v1/patientprofile/" + uuid; var config = { method: "GET", params: {v: "full"}, withCredentials: true }; var defer = $q.defer(); $http.get(url, config).success(function (result) { defer.resolve(result); }); return defer.promise; }; var create = function (patient, jumpAccepted) { var data = new Bahmni.Registration.CreatePatientRequestMapper(moment()).mapFromPatient($rootScope.patientConfiguration.attributeTypes, patient); var url = baseOpenMRSRESTURL + "/bahmnicore/patientprofile"; return $http.post(url, data, { withCredentials: true, headers: {"Accept": "application/json", "Content-Type": "application/json", "Jump-Accepted": jumpAccepted} }); }; var update = function (patient, openMRSPatient, attributeTypes) { var deferred = $q.defer(); var data = new Bahmni.Registration.UpdatePatientRequestMapper(moment()).mapFromPatient(attributeTypes, openMRSPatient, patient); var url = baseOpenMRSRESTURL + "/bahmnicore/patientprofile/" + openMRSPatient.uuid; var config = { withCredentials: true, headers: {"Accept": "application/json", "Content-Type": "application/json"} }; $http.post(url, data, config).then(function (result) { deferred.resolve(result); }, function (reason) { deferred.resolve(reason); }); return deferred.promise; }; var generateIdentifier = function (patient) { var data = {"identifierSourceName": patient.identifierPrefix ? patient.identifierPrefix.prefix : ""}; var url = openmrsUrl + "/ws/rest/v1/idgen"; var config = { withCredentials: true, headers: {"Accept": "text/plain", "Content-Type": "application/json"} }; return $http.post(url, data, config); }; return { search: search, get: getByUuid, create: create, update: update, generateIdentifier: generateIdentifier }; }]); 'use strict'; angular.module('bahmni.common.domain') .factory('configurationService', ['$http', '$q', function ($http, $q) { var configurationFunctions = {}; configurationFunctions.encounterConfig = function () { return $http.get(Bahmni.Common.Constants.encounterConfigurationUrl, { params: {"callerContext": "REGISTRATION_CONCEPTS"}, withCredentials: true }); }; configurationFunctions.patientConfig = function () { var patientConfig = $http.get(Bahmni.Common.Constants.patientConfigurationUrl, { withCredentials: true }); return patientConfig; }; configurationFunctions.patientAttributesConfig = function () { return $http.get(Bahmni.Common.Constants.personAttributeTypeUrl, { params: {v: 'custom:(uuid,name,sortWeight,description,format,concept)'}, withCredentials: true }); }; configurationFunctions.dosageFrequencyConfig = function () { var dosageFrequencyConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.dosageFrequencyConceptName}, withCredentials: true }); return dosageFrequencyConfig; }; configurationFunctions.dosageInstructionConfig = function () { var dosageInstructionConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.dosageInstructionConceptName}, withCredentials: true }); return dosageInstructionConfig; }; configurationFunctions.stoppedOrderReasonConfig = function () { var stoppedOrderReasonConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.stoppedOrderReasonConceptName}, withCredentials: true }); return stoppedOrderReasonConfig; }; configurationFunctions.consultationNoteConfig = function () { var consultationNoteConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name,answers)', name: Bahmni.Common.Constants.consultationNoteConceptName}, withCredentials: true }); return consultationNoteConfig; }; configurationFunctions.radiologyObservationConfig = function () { var radiologyObservationConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: { v: 'custom:(uuid,name)', name: Bahmni.Common.Constants.radiologyResultConceptName }, withCredentials: true }); return radiologyObservationConfig; }; configurationFunctions.labOrderNotesConfig = function () { var labOrderNotesConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name)', name: Bahmni.Common.Constants.labOrderNotesConcept}, withCredentials: true }); return labOrderNotesConfig; }; configurationFunctions.defaultEncounterType = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { params: { property: 'bahmni.encounterType.default' }, withCredentials: true, transformResponse: [function (data) { return data; }] }); }; configurationFunctions.radiologyImpressionConfig = function () { var radiologyImpressionConfig = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: {v: 'custom:(uuid,name)', name: Bahmni.Common.Constants.impressionConcept}, withCredentials: true }); return radiologyImpressionConfig; }; configurationFunctions.addressLevels = function () { return $http.get(Bahmni.Common.Constants.openmrsUrl + "/module/addresshierarchy/ajax/getOrderedAddressHierarchyLevels.form", { withCredentials: true }); }; configurationFunctions.allTestsAndPanelsConcept = function () { var allTestsAndPanelsConcept = $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { method: "GET", params: { v: 'custom:(uuid,name:(uuid,name),setMembers:(uuid,name:(uuid,name)))', name: Bahmni.Common.Constants.allTestsAndPanelsConceptName }, withCredentials: true }); return allTestsAndPanelsConcept; }; configurationFunctions.identifierTypesConfig = function () { return $http.get(Bahmni.Common.Constants.idgenConfigurationURL, { withCredentials: true }); }; configurationFunctions.genderMap = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'mrs.genders' }, withCredentials: true }); }; configurationFunctions.relationshipTypeMap = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'bahmni.relationshipTypeMap' }, withCredentials: true }); }; configurationFunctions.relationshipTypeConfig = function () { return $http.get(Bahmni.Common.Constants.relationshipTypesUrl, { withCredentials: true, params: {v: "custom:(aIsToB,bIsToA,uuid)"} }); }; configurationFunctions.loginLocationToVisitTypeMapping = function () { var url = Bahmni.Common.Constants.entityMappingUrl; return $http.get(url, { params: { mappingType: 'loginlocation_visittype', s: 'byEntityAndMappingType' } }); }; configurationFunctions.enableAuditLog = function () { return $http.get(Bahmni.Common.Constants.globalPropertyUrl, { method: "GET", params: { property: 'bahmni.enableAuditLog' }, withCredentials: true }); }; var existingPromises = {}; var configurations = {}; var getConfigurations = function (configurationNames) { var configurationsPromiseDefer = $q.defer(); var promises = []; configurationNames.forEach(function (configurationName) { if (!existingPromises[configurationName]) { existingPromises[configurationName] = configurationFunctions[configurationName]().then(function (response) { configurations[configurationName] = response.data; }); promises.push(existingPromises[configurationName]); } }); $q.all(promises).then(function () { configurationsPromiseDefer.resolve(configurations); }); return configurationsPromiseDefer.promise; }; return { getConfigurations: getConfigurations }; }]); 'use strict'; angular.module('bahmni.common.appFramework') .service('loadConfigService', ['$http', function ($http) { this.loadConfig = function (url) { return $http.get(url, {withCredentials: true}); }; }]); 'use strict'; angular.module('bahmni.common.domain') .service('visitService', ['$http', function ($http) { this.getVisit = function (uuid, params) { var parameters = params ? params : "custom:(uuid,visitId,visitType,patient,encounters:(uuid,encounterType,voided,orders:(uuid,orderType,voided,concept:(uuid,set,name),),obs:(uuid,value,concept,obsDatetime,groupMembers:(uuid,concept:(uuid,name),obsDatetime,value:(uuid,name),groupMembers:(uuid,concept:(uuid,name),value:(uuid,name),groupMembers:(uuid,concept:(uuid,name),value:(uuid,name)))))))"; return $http.get(Bahmni.Common.Constants.visitUrl + '/' + uuid, { params: { v: parameters } } ); }; this.endVisit = function (visitUuid) { return $http.post(Bahmni.Common.Constants.endVisitUrl + '?visitUuid=' + visitUuid, { withCredentials: true }); }; this.endVisitAndCreateEncounter = function (visitUuid, bahmniEncounterTransaction) { return $http.post(Bahmni.Common.Constants.endVisitAndCreateEncounterUrl + '?visitUuid=' + visitUuid, bahmniEncounterTransaction, { withCredentials: true }); }; this.updateVisit = function (visitUuid, attributes) { return $http.post(Bahmni.Common.Constants.visitUrl + '/' + visitUuid, attributes, { withCredentials: true }); }; this.createVisit = function (visitDetails) { return $http.post(Bahmni.Common.Constants.visitUrl, visitDetails, { withCredentials: true }); }; this.getVisitSummary = function (visitUuid) { return $http.get(Bahmni.Common.Constants.visitSummaryUrl, { params: { visitUuid: visitUuid }, withCredentials: true } ); }; this.search = function (parameters) { return $http.get(Bahmni.Common.Constants.visitUrl, { params: parameters, withCredentials: true }); }; this.getVisitType = function () { return $http.get(Bahmni.Common.Constants.visitTypeUrl, { withCredentials: true }); }; }]); 'use strict'; Bahmni.Common.Util.DateTimeFormatter = { getDateWithoutTime: function (datetime) { return datetime ? moment(datetime).format("YYYY-MM-DD") : null; } }; 'use strict'; angular.module('bahmni.common.logging') .service('loggingService', function () { var log = function (errorDetails) { $.ajax({ type: "POST", url: "/log", contentType: "application/json", data: angular.toJson(errorDetails) }); }; return { log: log }; }); 'use strict'; angular.module('bahmni.common.domain') .service('observationsService', ['$http', function ($http) { this.fetch = function (patientUuid, conceptNames, scope, numberOfVisits, visitUuid, obsIgnoreList, filterObsWithOrders, patientProgramUuid) { var params = {concept: conceptNames}; if (obsIgnoreList) { params.obsIgnoreList = obsIgnoreList; } if (filterObsWithOrders != null) { params.filterObsWithOrders = filterObsWithOrders; } if (visitUuid) { params.visitUuid = visitUuid; params.scope = scope; } else { params.patientUuid = patientUuid; params.numberOfVisits = numberOfVisits; params.scope = scope; params.patientProgramUuid = patientProgramUuid; } return $http.get(Bahmni.Common.Constants.observationsUrl, { params: params, withCredentials: true }); }; this.getByUuid = function (observationUuid) { return $http.get(Bahmni.Common.Constants.observationsUrl, { params: {observationUuid: observationUuid}, withCredentials: true }); }; this.getRevisedObsByUuid = function (observationUuid) { return $http.get(Bahmni.Common.Constants.observationsUrl, { params: {observationUuid: observationUuid, revision: "latest"}, withCredentials: true }); }; this.fetchForEncounter = function (encounterUuid, conceptNames) { return $http.get(Bahmni.Common.Constants.observationsUrl, { params: {encounterUuid: encounterUuid, concept: conceptNames}, withCredentials: true }); }; this.fetchForPatientProgram = function (patientProgramUuid, conceptNames, scope, obsIgnoreList) { return $http.get(Bahmni.Common.Constants.observationsUrl, { params: {patientProgramUuid: patientProgramUuid, concept: conceptNames, scope: scope, obsIgnoreList: obsIgnoreList}, withCredentials: true }); }; this.getObsRelationship = function (targetObsUuid) { return $http.get(Bahmni.Common.Constants.obsRelationshipUrl, { params: { targetObsUuid: targetObsUuid }, withCredentials: true }); }; this.getObsInFlowSheet = function (patientUuid, conceptSet, groupByConcept, orderByConcept, conceptNames, numberOfVisits, initialCount, latestCount, groovyExtension, startDate, endDate, patientProgramUuid) { var params = { patientUuid: patientUuid, conceptSet: conceptSet, groupByConcept: groupByConcept, orderByConcept: orderByConcept, conceptNames: conceptNames, numberOfVisits: numberOfVisits, initialCount: initialCount, latestCount: latestCount, name: groovyExtension, startDate: Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(startDate), endDate: Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(endDate), enrollment: patientProgramUuid }; return $http.get(Bahmni.Common.Constants.observationsUrl + "/flowSheet", { params: params, withCredentials: true }); }; }]); 'use strict'; angular.module('bahmni.common.domain') .service('encounterService', ['$http', '$q', '$rootScope', 'configurations', '$bahmniCookieStore', function ($http, $q, $rootScope, configurations, $bahmniCookieStore) { this.buildEncounter = function (encounter) { encounter.observations = encounter.observations || []; encounter.observations.forEach(function (obs) { stripExtraConceptInfo(obs); }); encounter.providers = encounter.providers || []; var providerData = $bahmniCookieStore.get(Bahmni.Common.Constants.grantProviderAccessDataCookieName); if (_.isEmpty(encounter.providers)) { if (providerData && providerData.uuid) { encounter.providers.push({"uuid": providerData.uuid}); } else if ($rootScope.currentProvider && $rootScope.currentProvider.uuid) { encounter.providers.push({"uuid": $rootScope.currentProvider.uuid}); } } return encounter; }; var getDefaultEncounterType = function () { var url = Bahmni.Common.Constants.encounterTypeUrl; return $http.get(url + '/' + configurations.defaultEncounterType()).then(function (response) { return response.data; }); }; var getEncounterTypeBasedOnLoginLocation = function (loginLocationUuid) { return $http.get(Bahmni.Common.Constants.entityMappingUrl, { params: { entityUuid: loginLocationUuid, mappingType: 'location_encountertype', s: 'byEntityAndMappingType' }, withCredentials: true }); }; var getEncounterTypeBasedOnProgramUuid = function (programUuid) { return $http.get(Bahmni.Common.Constants.entityMappingUrl, { params: { entityUuid: programUuid, mappingType: 'program_encountertype', s: 'byEntityAndMappingType' }, withCredentials: true }); }; var getDefaultEncounterTypeIfMappingNotFound = function (entityMappings) { var encounterType = entityMappings.data.results[0] && entityMappings.data.results[0].mappings[0]; if (!encounterType) { encounterType = getDefaultEncounterType(); } return encounterType; }; this.getEncounterType = function (programUuid, loginLocationUuid) { if (programUuid) { return getEncounterTypeBasedOnProgramUuid(programUuid).then(function (response) { return getDefaultEncounterTypeIfMappingNotFound(response); }); } else if (loginLocationUuid) { return getEncounterTypeBasedOnLoginLocation(loginLocationUuid).then(function (response) { return getDefaultEncounterTypeIfMappingNotFound(response); }); } else { return getDefaultEncounterType(); } }; this.create = function (encounter) { encounter = this.buildEncounter(encounter); return $http.post(Bahmni.Common.Constants.bahmniEncounterUrl, encounter, { withCredentials: true }); }; this.delete = function (encounterUuid, reason) { return $http.delete(Bahmni.Common.Constants.bahmniEncounterUrl + "/" + encounterUuid, { params: {reason: reason} }); }; function isObsConceptClassVideoOrImage (obs) { return (obs.concept.conceptClass === 'Video' || obs.concept.conceptClass === 'Image'); } var deleteIfImageOrVideoObsIsVoided = function (obs) { if (obs.voided && obs.groupMembers && !obs.groupMembers.length && obs.value && isObsConceptClassVideoOrImage(obs)) { var url = Bahmni.Common.Constants.RESTWS_V1 + "/bahmnicore/visitDocument?filename=" + obs.value; $http.delete(url, {withCredentials: true}); } }; var stripExtraConceptInfo = function (obs) { deleteIfImageOrVideoObsIsVoided(obs); obs.concept = {uuid: obs.concept.uuid, name: obs.concept.name, dataType: obs.concept.dataType}; obs.groupMembers = obs.groupMembers || []; obs.groupMembers.forEach(function (groupMember) { stripExtraConceptInfo(groupMember); }); }; var searchWithoutEncounterDate = function (visitUuid) { return $http.post(Bahmni.Common.Constants.bahmniEncounterUrl + '/find', { visitUuids: [visitUuid], includeAll: Bahmni.Common.Constants.includeAllObservations }, { withCredentials: true }); }; this.search = function (visitUuid, encounterDate) { if (!encounterDate) { return searchWithoutEncounterDate(visitUuid); } return $http.get(Bahmni.Common.Constants.emrEncounterUrl, { params: { visitUuid: visitUuid, encounterDate: encounterDate, includeAll: Bahmni.Common.Constants.includeAllObservations }, withCredentials: true }); }; this.find = function (params) { return $http.post(Bahmni.Common.Constants.bahmniEncounterUrl + '/find', params, { withCredentials: true }); }; this.findByEncounterUuid = function (encounterUuid) { return $http.get(Bahmni.Common.Constants.bahmniEncounterUrl + '/' + encounterUuid, { params: {includeAll: true}, withCredentials: true }); }; this.getEncountersForEncounterType = function (patientUuid, encounterTypeUuid) { return $http.get(Bahmni.Common.Constants.encounterUrl, { params: { patient: patientUuid, encounterType: encounterTypeUuid, v: "custom:(uuid,provider,visit:(uuid,startDatetime,stopDatetime),obs:(uuid,concept:(uuid,name),groupMembers:(id,uuid,obsDatetime,value,comment)))" }, withCredentials: true }); }; this.getDigitized = function (patientUuid) { var patientDocumentEncounterTypeUuid = configurations.encounterConfig().getPatientDocumentEncounterTypeUuid(); return $http.get(Bahmni.Common.Constants.encounterUrl, { params: { patient: patientUuid, encounterType: patientDocumentEncounterTypeUuid, v: "custom:(uuid,obs:(uuid))" }, withCredentials: true }); }; this.discharge = function (encounterData) { var encounter = this.buildEncounter(encounterData); return $http.post(Bahmni.Common.Constants.dischargeUrl, encounter, { withCredentials: true }); }; }]); 'use strict'; angular.module('bahmni.common.conceptSet') .factory('conceptSetService', ['$http', '$q', '$bahmniTranslate', function ($http, $q, $bahmniTranslate) { var getConcept = function (params, cache) { params['locale'] = params['locale'] || $bahmniTranslate.use(); return $http.get(Bahmni.Common.Constants.conceptSearchByFullNameUrl, { params: params, cache: cache }); }; var getComputedValue = function (encounterData) { var url = Bahmni.Common.Constants.encounterModifierUrl; return $http.post(url, encounterData, { withCredentials: true, headers: {"Accept": "application/json", "Content-Type": "application/json"} }); }; var getObsTemplatesForProgram = function (programUuid) { var url = Bahmni.Common.Constants.entityMappingUrl; return $http.get(url, { params: { entityUuid: programUuid, mappingType: 'program_obstemplate', s: 'byEntityAndMappingType' } }); }; return { getConcept: getConcept, getComputedValue: getComputedValue, getObsTemplatesForProgram: getObsTemplatesForProgram }; }]); Bahmni.Registration.StateNameEvenTypeMap = { "search": "VIEWED_REGISTRATION_PATIENT_SEARCH", "newpatient": "VIEWED_NEW_PATIENT_PAGE", "newpatient.save": "REGISTER_NEW_PATIENT", "patient.edit": "EDIT_PATIENT_DETAILS", "patient.visit": "ACCESSED_REGISTRATION_SECOND_PAGE", "patient.view": "VIEWED_PATIENT_DETAILS", "patient.printSticker": "PRINT_PATIENT_STICKER" }; 'use strict'; angular.module('bahmni.common.logging') .service('auditLogService', ['$http', '$translate', 'configurationService', function ($http, $translate, configurationService) { var DateUtil = Bahmni.Common.Util.DateUtil; var convertToLocalDate = function (date) { var localDate = DateUtil.parseLongDateToServerFormat(date); return DateUtil.getDateTimeInSpecifiedFormat(localDate, 'MMMM Do, YYYY [at] h:mm:ss A'); }; this.getLogs = function (params) { params = params || {}; return $http.get(Bahmni.Common.Constants.auditLogUrl, {params: params}).then(function (response) { return response.data.map(function (log) { log.dateCreated = convertToLocalDate(log.dateCreated); var entity = log.message ? log.message.split("~")[1] : undefined; log.params = entity ? JSON.parse(entity) : entity; log.message = log.message.split("~")[0]; log.displayMessage = $translate.instant(log.message, log); return log; }); }); }; this.log = function (patientUuid, eventType, messageParams, module) { return configurationService.getConfigurations(['enableAuditLog']).then(function (result) { if (result.enableAuditLog) { var params = {}; params.patientUuid = patientUuid; params.eventType = Bahmni.Common.AuditLogEventDetails[eventType].eventType; params.message = Bahmni.Common.AuditLogEventDetails[eventType].message; params.message = messageParams ? params.message + '~' + JSON.stringify(messageParams) : params.message; params.module = module; return $http.post(Bahmni.Common.Constants.auditLogUrl, params, {withCredentials: true}); } }); }; }]);