bahmniapps-commons
Version:
Common Modules carved out from bahmniapps.
473 lines (397 loc) • 15.5 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 56);
/******/ })
/************************************************************************/
/******/ ({
/***/ 10:
/***/ (function(module, exports, __webpack_require__) {
;
Bahmni.PatientMapper = function (patientConfig, $rootScope, $translate) {
this.patientConfig = patientConfig;
this.map = function (openmrsPatient) {
var patient = this.mapBasic(openmrsPatient);
this.mapAttributes(patient, openmrsPatient.person.attributes);
return patient;
};
this.mapBasic = function (openmrsPatient) {
var patient = {};
patient.uuid = openmrsPatient.uuid;
patient.givenName = openmrsPatient.person.preferredName.givenName;
patient.familyName = openmrsPatient.person.preferredName.familyName === null ? '' : openmrsPatient.person.preferredName.familyName;
patient.name = patient.givenName + ' ' + patient.familyName;
patient.age = openmrsPatient.person.age;
patient.ageText = calculateAge(Bahmni.Common.Util.DateUtil.parseServerDateToDate(openmrsPatient.person.birthdate));
patient.gender = openmrsPatient.person.gender;
patient.genderText = mapGenderText(patient.gender);
patient.address = mapAddress(openmrsPatient.person.preferredAddress);
patient.birthdateEstimated = openmrsPatient.person.birthdateEstimated;
patient.birthtime = Bahmni.Common.Util.DateUtil.parseServerDateToDate(openmrsPatient.person.birthtime);
patient.bloodGroupText = getPatientBloodGroupText(openmrsPatient);
if (openmrsPatient.identifiers) {
var primaryIdentifier = openmrsPatient.identifiers[0].primaryIdentifier;
patient.identifier = primaryIdentifier ? primaryIdentifier : openmrsPatient.identifiers[0].identifier;
}
if (openmrsPatient.person.birthdate) {
patient.birthdate = parseDate(openmrsPatient.person.birthdate);
}
if (openmrsPatient.person.personDateCreated) {
patient.registrationDate = parseDate(openmrsPatient.person.personDateCreated);
}
patient.image = Bahmni.Common.Constants.patientImageUrlByPatientUuid + openmrsPatient.uuid;
return patient;
};
this.getPatientConfigByUuid = function (patientConfig, attributeUuid) {
if (this.patientConfig.personAttributeTypes) {
return patientConfig.personAttributeTypes.filter(function (item) {
return item.uuid === attributeUuid;
})[0];
}
return {};
};
this.mapAttributes = function (patient, attributes) {
var self = this;
if (this.patientConfig) {
attributes.forEach(function (attribute) {
var x = self.getPatientConfigByUuid(patientConfig, attribute.attributeType.uuid);
patient[x.name] = { label: x.description, value: attribute.value, isDateField: checkIfDateField(x) };
});
}
};
var calculateAge = function (birthDate) {
var DateUtil = Bahmni.Common.Util.DateUtil;
var age = DateUtil.diffInYearsMonthsDays(birthDate, DateUtil.now());
var ageInString = "";
if (age.years) {
ageInString += age.years + " <span> " + $translate.instant("CLINICAL_YEARS_TRANSLATION_KEY") + " </span>";
}
if (age.months) {
ageInString += age.months + "<span> " + $translate.instant("CLINICAL_MONTHS_TRANSLATION_KEY") + " </span>";
}
if (age.days) {
ageInString += age.days + "<span> " + $translate.instant("CLINICAL_DAYS_TRANSLATION_KEY") + " </span>";
}
return ageInString;
};
var mapAddress = function (preferredAddress) {
return preferredAddress ? {
"address1": preferredAddress.address1,
"address2": preferredAddress.address2,
"address3": preferredAddress.address3,
"cityVillage": preferredAddress.cityVillage,
"countyDistrict": preferredAddress.countyDistrict === null ? '' : preferredAddress.countyDistrict,
"stateProvince": preferredAddress.stateProvince
} : {};
};
var parseDate = function (dateStr) {
if (dateStr) {
return Bahmni.Common.Util.DateUtil.parse(dateStr.substr(0, 10));
}
return dateStr;
};
var mapGenderText = function (genderChar) {
if (genderChar == null) {
return null;
}
return "<span>" + $rootScope.genderMap[angular.uppercase(genderChar)] + "</span>";
};
var getPatientBloodGroupText = function (openmrsPatient) {
if (openmrsPatient.person.bloodGroup) {
return "<span>" + openmrsPatient.person.bloodGroup + "</span>";
}
if (openmrsPatient.person.attributes && openmrsPatient.person.attributes.length > 0) {
var bloodGroup;
_.forEach(openmrsPatient.person.attributes, function (attribute) {
if (attribute.attributeType.display == "bloodGroup") {
bloodGroup = attribute.display;
}
});
if (bloodGroup) {
return "<span>" + bloodGroup + "</span>";
}
}
};
var checkIfDateField = function (x) {
return x.format === Bahmni.Common.Constants.patientAttributeDateFieldFormat;
};
};
/***/ }),
/***/ 11:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').service('patientService', ['$http', 'sessionService', function ($http, sessionService) {
this.getPatient = function (uuid) {
var patient = $http.get(Bahmni.Common.Constants.openmrsUrl + "/ws/rest/v1/patient/" + uuid, {
method: "GET",
params: { v: "full" },
withCredentials: true
});
return patient;
};
this.getRelationships = function (patientUuid) {
return $http.get(Bahmni.Common.Constants.openmrsUrl + "/ws/rest/v1/relationship", {
method: "GET",
params: { person: patientUuid, v: "full" },
withCredentials: true
});
};
this.findPatients = function (params) {
return $http.get(Bahmni.Common.Constants.sqlUrl, {
method: "GET",
params: params,
withCredentials: true
});
};
this.search = function (query, offset, identifier) {
offset = offset || 0;
return $http.get(Bahmni.Common.Constants.bahmniSearchUrl + "/patient", {
method: "GET",
params: {
q: query,
startIndex: offset,
identifier: identifier,
loginLocationUuid: sessionService.getLoginLocationUuid()
},
withCredentials: true
});
};
this.getPatientContext = function (patientUuid, programUuid, personAttributes, programAttributes, patientIdentifiers) {
return $http.get('/openmrs/ws/rest/v1/bahmnicore/patientcontext', {
params: {
patientUuid: patientUuid,
programUuid: programUuid,
personAttributes: personAttributes,
programAttributes: programAttributes,
patientIdentifiers: patientIdentifiers
},
withCredentials: true
});
};
}]);
/***/ }),
/***/ 3:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').directive('stopEventPropagation', function () {
return {
link: function (scope, elem, attrs) {
elem.on(attrs.stopEventPropagation, function (e) {
e.stopPropagation();
});
}
};
});
/***/ }),
/***/ 4:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').directive('patientSummary', function () {
var link = function ($scope) {
$scope.showPatientDetails = false;
$scope.togglePatientDetails = function () {
$scope.showPatientDetails = !$scope.showPatientDetails;
};
$scope.onImageClick = function () {
if ($scope.onImageClickHandler) {
$scope.onImageClickHandler();
}
};
};
return {
restrict: 'E',
template: __webpack_require__(62),
link: link,
required: 'patient',
scope: {
patient: "=",
bedDetails: "=",
onImageClickHandler: "&"
}
};
});
/***/ }),
/***/ 5:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').filter('age', function () {
return function (age) {
if (age.years) {
return age.years + " y";
}
if (age.months) {
return age.months + " m";
}
return age.days + " d";
};
});
/***/ }),
/***/ 56:
/***/ (function(module, exports, __webpack_require__) {
angular.module('bahmni.common.patient', []);
__webpack_require__(3);
__webpack_require__(4);
__webpack_require__(5);
__webpack_require__(6);
__webpack_require__(7);
__webpack_require__(8);
__webpack_require__(9);
__webpack_require__(10);
__webpack_require__(11);
/***/ }),
/***/ 6:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').filter('birthDateToAgeText', ['$filter', '$translate', function ($filter, $translate) {
return function (birthDate) {
var DateUtil = Bahmni.Common.Util.DateUtil;
if (birthDate) {
var age = DateUtil.diffInYearsMonthsDays(birthDate, DateUtil.now());
var ageInString = "";
if (age.years) {
ageInString += age.years + " " + $translate.instant("CLINICAL_YEARS_TRANSLATION_KEY") + " ";
}
if (age.months) {
ageInString += age.months + " " + $translate.instant("CLINICAL_MONTHS_TRANSLATION_KEY") + " ";
}
if (age.days) {
ageInString += age.days + " " + $translate.instant("CLINICAL_DAYS_TRANSLATION_KEY") + " ";
}
return ageInString;
} else {
return "";
}
};
}]);
/***/ }),
/***/ 62:
/***/ (function(module, exports) {
module.exports = "<div class=\"patient-details\">\n <i class=\"fa fa-user\"></i>\n <span>{{patient.name}}</span>\n <span>({{patient.identifier}},</span>\n <span>{{patient.gender | gender }},</span>\n <span>{{patient.age}} {{ 'YEARS_LABEL'|translate }})</span>\n</div>\n";
/***/ }),
/***/ 7:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').filter('dateToAge', ['$filter', function ($filter) {
return function (birthDate, referenceDate) {
var DateUtil = Bahmni.Common.Util.DateUtil;
referenceDate = referenceDate || DateUtil.now();
var age = DateUtil.diffInYearsMonthsDays(birthDate, referenceDate);
return $filter('age')(age);
};
}]);
/***/ }),
/***/ 8:
/***/ (function(module, exports, __webpack_require__) {
;
angular.module('bahmni.common.patient').filter('gender', ['$rootScope', function ($rootScope) {
return function (genderChar) {
if (genderChar == null) {
return "Unknown";
}
return $rootScope.genderMap[angular.uppercase(genderChar)];
};
}]);
/***/ }),
/***/ 9:
/***/ (function(module, exports, __webpack_require__) {
;
Bahmni.PatientContextMapper = function () {
this.map = function (patient) {
var patientContext = {};
patientContext.uuid = patient.uuid;
patientContext.givenName = patient.person.names[0].givenName;
var familyName = patient.person.names[0].familyName;
patientContext.familyName = familyName ? familyName : "";
patientContext.middleName = patient.person.names[0].middleName;
patientContext.gender = patient.person.gender;
if (patient.identifiers) {
var primaryIdentifier = patient.identifiers[0].primaryIdentifier;
patientContext.identifier = primaryIdentifier ? primaryIdentifier : patient.identifiers[0].identifier;
}
if (patient.person.birthdate) {
patientContext.birthdate = parseDate(patient.person.birthdate);
}
return patientContext;
};
var parseDate = function (dateStr) {
if (dateStr) {
return Bahmni.Common.Util.DateUtil.parse(dateStr.substr(0, 10));
}
return dateStr;
};
};
/***/ })
/******/ });
});