File: /var/www/vhost/disk-apps/demo-telemedicina.teky.com.co/public/js/requests_old/covid19/analysis.js
$("#add-analysis").click(function() {
var lastField = $("#tab-analysis tr:last");
var intId = (lastField && lastField.length && lastField.data("idx") + 1) || 1;
var td = $("<tr></tr>");
var sel =
'<td><input class="form-control codigo-diagnostics" data-id="text' +
intId +
'" id="codigo' +
intId +
'" name="codigo" ></td> <td><input class="form-control text-diagnostics" id="text' +
intId +
'" data-id="codigo' +
intId +
'" name="text"></td><td><a href="#" onclick="deleteAnexo(this)"><i class="fa fa-trash iconMini a-icon analysis-trash" style="cursor:pointer;" ></i></a></td>';
td.data("idx", intId);
td.append(sel);
$("#tab-analysis").append(td);
autocomplete();
});
/*
* Variables for Record.
*/
var gumStream;
//stream from getUserMedia()
var recorder;
//WebAudioRecorder object
var input;
//MediaStreamAudioSourceNode we'll be recording var encodingType;
//holds selected encoding for resulting audio (file)
var encodeAfterRecord = true;
// when to encode
var audioContext = new AudioContext();
//new audio context to help us record
// var encodingTypeSelect = document.getElementById("encodingTypeSelect");
var recordButton = document.getElementById("bt_record_session");
var stopButton = document.getElementById("bt_record_session");
var recordingsList = document.getElementById("recording_lists");
var isRecording = true;
var constraints = {
audio: true,
video: false
};
function letsRecord() {
isRecording = !isRecording;
if (isRecording) {
stopRecord();
} else {
startRecording();
}
}
function startRecording() {
console.log("startRecording() called");
/*
Simple constraints object, for more advanced features see
https://addpipe.com/blog/audio-constraints-getusermedia/
*/
var constraints = { audio: true, video: false };
/*
We're using the standard promise based getUserMedia()
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
*/
navigator.mediaDevices
.getUserMedia(constraints)
.then(function(stream) {
console.log("getUserMedia() success, stream created, initializing WebAudioRecorder...");
/*
create an audio context after getUserMedia is called
sampleRate might change after getUserMedia is called, like it does on macOS when recording through AirPods
the sampleRate defaults to the one set in your OS for your playback device
*/
audioContext = new AudioContext();
//update the format
// document.getElementById("formats").innerHTML =
// "Format: 2 channel " +
// encodingTypeSelect.options[encodingTypeSelect.selectedIndex].value +
// " @ " +
// audioContext.sampleRate / 1000 +
// "kHz";
//assign to gumStream for later use
gumStream = stream;
/* use the stream */
input = audioContext.createMediaStreamSource(stream);
//stop the input from playing back through the speakers
//input.connect(audioContext.destination)
//get the encoding
// encodingType = encodingTypeSelect.options[encodingTypeSelect.selectedIndex].value;
//disable the encoding selector
// encodingTypeSelect.disabled = true;
recorder = new WebAudioRecorder(input, {
workerDir: "/js/record/", // must end with slash
encoding: "mp3",
numChannels: 2, //2 is the default, mp3 encoding supports only 2
onEncoderLoading: function(recorder, encoding) {
// show "loading encoder..." display
console.log("Loading " + encoding + " encoder...");
},
onEncoderLoaded: function(recorder, encoding) {
// hide "loading encoder..." display
console.log(encoding + " encoder loaded");
}
});
recorder.onComplete = function(recorder, blob) {
console.log("Encoding complete");
createDownloadLink(blob, recorder.encoding);
};
recorder.setOptions({
// timeLimit: 120,
encodeAfterRecord: encodeAfterRecord,
ogg: { quality: 0.5 },
mp3: { bitRate: 128 }
});
//start the recording process
recorder.startRecording();
console.log("Recording started");
})
.catch(function(err) {
//enable the record button if getUSerMedia() fails
recordButton.disabled = false;
});
recordButton.innerHTML = Lang.get('messages.gineco.analysis.recording_clic');
}
function stopRecord() {
console.log("stopRecording() called");
//stop microphone access
gumStream.getAudioTracks()[0].stop();
//tell the recorder to finish the recording (stop recording + encode the recorded audio)
recorder.finishRecording();
console.log("Recording stopped");
}
function createDownloadLink(blob, encoding) {
var url = URL.createObjectURL(blob);
var au = document.createElement("audio");
var li = document.createElement("li");
var link = document.createElement("a");
var documento = $("#documento").val();
//add controls to the "audio" element
au.controls = true;
au.src = url; //link the a element to the blob
link.href = url;
link.download = documento + "-" + new Date().toISOString() + "." + encoding;
link.innerHTML = link.download;
//add the new audio and a elements to the li element
li.appendChild(au);
li.appendChild(link); //add the li element to the ordered list
recordingsList.appendChild(li);
recordButton.innerHTML =
'<i class="fa fa-microphone" style="color:white; margin-rigth:5px;"> </i>' + Lang.get('messages.gineco.analysis.record_session');
}
function deleteAnexo(evt) {
// TODO: Ajax para eliminar desde la BD y luego visualmente eliminar.
$(evt)
.closest("tr")
.remove();
// swal("Se ha eliminado correctamente!", "", "success");
}
$("#btn_analisis_conducta").click(function() {
var r = JSON.parse(window.localStorage.getItem("user")).rol_id;
console.log(r);
if (r == 3) {
$("#btn-modal-text").prop("disabled", false);
$("#text-area-modal").prop("disabled", false);
} else {
$("#btn-modal-text").prop("disabled", true);
$("#text-area-modal").prop("disabled", true);
}
valor = $(this).attr("data-id");
$("#btn-modal-text").attr("data-id", valor);
valor2 = $("#analisis_conducta").val();
$("#text-area-modal").val(valor2);
});
$("#btn_fin_tratamiento").click(function() {
id = window.localStorage.getItem("current_id");
rol = JSON.parse(window.localStorage.getItem("rol")).id;
if (!id) {
swal(Lang.get('messages.gineco.analysis.error_please_save'), "Error", "error");
return;
}
if (!(rol == 3 || rol == 6)) {
swal("Error", Lang.get('messages.gineco.analysis.only_role_medic'), "error");
return;
}
var user = JSON.parse(window.localStorage.getItem("user"));
saveDocument(true); // True indica guardado silencioso.
swal({
title: Lang.get('messages.gineco.analysis.finish_treatment'),
text: Lang.get('messages.gineco.analysis.finish_treatment_confirm'),
icon: "warning",
buttons: true,
dangerMode: false
}).then(function(gofn) {
if (gofn) {
var data = {
id: id,
rol: rol,
medico: user.name + " " + user.last_name,
medico_especialista_doc: user.document
};
$.ajax({
url: "/request/end_treatment",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json"
},
data: JSON.stringify(data),
success: function(res) {
swal(res.message, "", "success");
$("#medico_especialista").val(user.name + " " + user.last_name);
setEndTreatment();
$("#estado").val("Fin de tratamiento");
$("#estado").css("background-color", "#pf42c1");
},
error: function(err) {
swal("Error al guardar \n Message: " + err, "Error", "error");
}
});
}
});
});
function autocomplete() {
$(function() {
$(".codigo-diagnostics").autocomplete({
source: "/request/codigo/autocomplete/",
minLength: 2,
select: function(event, ui) {
$(this).val(ui.item.id);
$(this).attr("readOnly", true);
id = $(this).attr("data-id");
$("#" + id).val(ui.item.description);
$("#" + id).attr("readOnly", true);
}
});
$(".text-diagnostics").autocomplete({
source: "/request/description/autocomplete/",
minLength: 3,
select: function(event, ui) {
$(this).val(ui.item.id);
$(this).attr("readOnly", true);
id = $(this).attr("data-id");
$("#" + id).val(ui.item.codigo);
$("#" + id).attr("readOnly", true);
}
});
});
}