/**
 * Created by soheil on 02/08/2016.
 */

WebService = Class.create({

	initialize: function () {
		this._settings = new Settings();
		this._baseURL = this._settings.getSetting('codingDefinitionServiceEndpoint');
	},

	getOmimLookupPath: function(){
		var endpoint = this._baseURL ? this._baseURL : this._settings.getSetting('codingDefinitionServiceEndpoint');
		return endpoint + "/lookupServices/OMIMLookupService?";
	},

	getIcd10LookupPath: function(){
		var endpoint = this._baseURL ? this._baseURL : this._settings.getSetting('codingDefinitionServiceEndpoint');
		return endpoint + "/lookupServices/ICDLookupService?";
	},

	getSnomedCTLookupPath: function(){
		var endpoint = this._baseURL ? this._baseURL : this._settings.getSetting('codingDefinitionServiceEndpoint');
		return endpoint + "/lookupServices/SNOMEDCTLookupService?";
	},

	getGELLookupPath: function(){
		var endpoint = this._baseURL ? this._baseURL : this._settings.getSetting('codingDefinitionServiceEndpoint');
		return endpoint + "/lookupServices/DiseaseList?";
	},

	getEthnicityLookupPath: function(){
		var endpoint = this._baseURL ? this._baseURL : this._settings.getSetting('codingDefinitionServiceEndpoint');
		return endpoint + "/lookupServices/Ethnicity?";
	},

	getHPOLookupPath: function(){
		var endpoint = this._baseURL ? this._baseURL : this._settings.getSetting('codingDefinitionServiceEndpoint');
		return endpoint + "/OntologyService/LookupService?";
	},

	getDiagramEndpointPath: function(){
		var config = this._settings.getSetting('diagramEndpoint');
		switch(config.service){
			case "mercury":
				var _this = this;
				var accessPath =  _this.getUrlParameter("accessPath", true);
				return accessPath;
				break;
			case "openclinica":
				var eventCRFId = this.getUrlParameter("eventCRFId");
				var status = this.getUrlParameter("status");
				var participantId = this.getUrlParameter("participantId");
				return "/openclinica/pedigree/get?eventCRFId=" + eventCRFId + "&status=" + status + "&participantId=" + participantId;
			case "local":
				return null;
		}
	},

	getPathToEditorFiles: function(){
		var config = this._settings.getSetting('diagramEndpoint');
		switch(config.service){
			case "mercury":
				return "";
				break;
			case "openclinica":
				//get path to pedigree directory like :
				//"http://localhost:8083/openclinica/includes/pedigreeEditor/" or
				//"https://gmc.genomicsengland.nhs.uk/rarediseases/demo/includes/pedigreeEditor/"
				return Helpers.getSiteURL() + "/includes/pedigreeEditor/";
			case "local":
				return Helpers.getSiteURL() + "/";
		}
	},

	saveDiagramEndpointPath: function(){
		var config = this._settings.getSetting('diagramEndpoint');
		switch(config.service){
			case "mercury":
				var _this = this;
				var returnUrl =  _this.getUrlParameter("returnUrl", true);
				var participantId = this.getUrlParameter("participantId");
				var mercuryGetEndpoint =  config.mercuryHost + "/" + participantId + "?accessPath=" + returnUrl;
				return mercuryGetEndpoint;
				break;
			case "openclinica":
				var _this = this;
				var eventCRFId = _this.getUrlParameter("eventCRFId");
				var status = _this.getUrlParameter("status");
				var participantId = _this.getUrlParameter("participantId");
				return "/openclinica/pedigree/update?eventCRFId=" + eventCRFId + "&status=" + status + "&participantId=" + participantId;
			case "local":
				return null;
		}
	},

	getUrlParameter: function getUrlParameter(sParam, doNotDecode) {

		var sPageURL = decodeURIComponent(window.location.search.substring(1));
		if(doNotDecode && doNotDecode == true){
			sPageURL = window.location.search.substring(1);
		}

		var	sURLVariables = sPageURL.split('&')
		var	sParameterName;
		var	i;

		for (i = 0; i < sURLVariables.length; i++) {
			sParameterName = sURLVariables[i].split('=');

			if (sParameterName[0].toLowerCase() === sParam.toLowerCase()) {
				return sParameterName[1] === undefined ? true : sParameterName[1];
			}
		}
	},

	getParticipantId: function(){
		var _this = this;
		var config = this._settings.getSetting('diagramEndpoint');
		switch(config.service){
			case "mercury":
			case "openclinica":
				var participantId = _this.getUrlParameter("participantId");
				return participantId;
				break;
			case "local":
				return null;
		}
	}
});
@@ -1617,26 +1617,25 @@
 %09%09%09%09var 
-accessPath
+returnUrl
  =  _thi
@@ -1653,26 +1653,25 @@
 ameter(%22
-accessPath
+returnUrl
 %22, true)
@@ -1680,25 +1680,197 @@
 %09%09%09%09
-return accessPath
+var participantId = this.getUrlParameter(%22participantId%22);%0A%09%09%09%09var mercuryGetEndpoint =  config.mercuryHost + %22/%22 + participantId + %22?accessPath=%22 + returnUrl;%0A%09%09%09%09return mercuryGetEndpoint
 ;%0A%09%09

Add mercury get endpoint