Skip to content

Commit

Permalink
Merge pull request #10 from olivier5741/feature/add-room-to-wardround
Browse files Browse the repository at this point in the history
Feature/add room to wardround
  • Loading branch information
olivier5741 committed Jan 24, 2021
2 parents d6e6e5d + db79c8e commit ce3d2d8
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 250 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# Suivi patient

Suivi des patients covid en maison de repos

# Demo

La démo est disponible via https://docs.google.com/spreadsheets/d/1gLKt9QdUTm8rfAfmakQrcFn3-iwV48R8FAn3bHEzM2I.
Il faut en créer une copie (via le menu `Fichier > Créer une copie`) pour pouvoir l'utiliser.
Il est conseillé de créer le fichier dans un dossier dédié : un dossier `Archives` va s'ajouter pour la partie archivage de l'application.

Les actions se situe dans le menu `SUIVI PATIENT`. Lors du lancement de la première action, des autorisations vont être demandées.
Une fois celles-ci acceptées, l'action doit être lancée à nouveau pour être effective.
117 changes: 7 additions & 110 deletions src/App.gs
Original file line number Diff line number Diff line change
@@ -1,79 +1,9 @@
// TODO USERS

// * delete rule for TA diast
// * add rule for pouls <50
// * push new version for param column width in ward round
// * group param in patient sheet -> to discuss

// TODO google sheet not performing action when asking rights -> could not find a way to solve this
// TODO improve user experience : defense coding
// TODO add link to mode d emploi in menu
// TODO set developer mode false in every user (otherwise version not working)
// TODO set templates as local cache

// TODO URGENT in wardround, lookup for patient sheet link expects the list to be sorted

// https://leanpub.com/understandinges6/read/
// template literals with `
// let name = "Nicholas", message = `Hello, ${name}.`;

// use const or let
// use regex with "pattern".exec()

// default parameters
// function add(first, second = getValue()) {
// return first + second;
//}

// function pick(object, ...keys) {

// 2 sec per sheet when generating patients
// 0.5 sec per sheet when transfering parameters
function setProperty()
{
PropertiesService.getScriptProperties().setProperty("templateSpreadsheetUrl","https://docs.google.com/spreadsheets/d/1jaGvPITO4F-7gfh7x_QkmRI_wyLkahj14UsJkHUNlt0/edit");
}


function deletePatientSheets(){
const regExp = new RegExp("^[_z]+.*$")
const names = patientSheetNames();
const currentSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();

for (let key in names)
{
const sheet = currentSpreadSheet.getSheetByName(names[key]);
currentSpreadSheet.deleteSheet(sheet);
}
}

function onOpen() {
initialize();
}

var localScriptProperties;

function initialize(libraryName = "", localScriptProperties = PropertiesService.getScriptProperties()){

if(localScriptProperties.getProperty("patientSheetTemplateSpreadsheetUrl") == null){
localScriptProperties.setProperty("patientSheetTemplateSpreadsheetUrl", "https://docs.google.com/spreadsheets/d/11IcFYz3_zF-6VdUTA-UZJMmH2Q1-M-LJGDUtz3zoKvI/edit");
}

if(localScriptProperties.getProperty("templateSpreadsheetUrl") == null){
localScriptProperties.setProperty("templateSpreadsheetUrl", "https://docs.google.com/spreadsheets/d/11IcFYz3_zF-6VdUTA-UZJMmH2Q1-M-LJGDUtz3zoKvI/edit");
}

if(localScriptProperties.getProperty("patientSheetTemplateSheetName") == null){
localScriptProperties.setProperty("patientSheetTemplateSheetName", "zzz_template_patient_1.5.0");
}

if(localScriptProperties.getProperty("wardRoundTemplateSheetName") == null){
localScriptProperties.setProperty("wardRoundTemplateSheetName", "zzz_template_tour_1.5.0");
}
function initialize(libraryName = "", localScriptProperties = PropertiesService.getScriptProperties()){

PropertiesService.getDocumentProperties().deleteAllProperties();
PropertiesService.getDocumentProperties().setProperties(localScriptProperties.getProperties());

let prefix = libraryName;
if(libraryName){
prefix = prefix + ".";
Expand All @@ -83,14 +13,14 @@ function initialize(libraryName = "", localScriptProperties = PropertiesService.
const ui = SpreadsheetApp.getUi();

ui.createMenu('SUIVI PATIENT')
.addItem('Envoyer la fiche au médecin traitant',prefix + 'sendMRSPatientSheetByMailToGP')
.addItem('Créer une fiche vierge',prefix + 'createEmptyMRSPatientSheet')
.addItem('Envoyer la fiche au médecin traitant',prefix + 'sendMRSPatientSheetByMailToGP')
.addItem('Créer une fiche vierge',prefix + 'createEmptyMRSPatientSheet')
.addItem('Archiver la fiche',prefix + 'archivePatientSheet')
.addItem('Générer les fiches correspondantes',prefix + 'createMRSPatientSheet')
.addItem('Générer les fiches correspondantes',prefix + 'createMRSPatientSheet')
.addSeparator()
.addItem("Créer une tournée", prefix + "createWardRoundSheet")
.addItem("Démarrer la tournée",prefix + "startWardRoundSheet")
.addItem('Archiver la tournée',prefix + 'archiveWardRoundSheet')
.addItem("Créer une tournée", prefix + "createWardRoundSheet")
.addItem("Démarrer la tournée",prefix + "startWardRoundSheet")
.addItem('Archiver la tournée',prefix + 'archiveWardRoundSheet')
.addSeparator()
.addItem('Trier les onglets alph.',prefix + 'sortSheetsByName')
.addToUi();
Expand All @@ -99,36 +29,3 @@ function initialize(libraryName = "", localScriptProperties = PropertiesService.
refreshWardRoundInSystem();

}

// proxy for sheet buttons

function function1(){
sendMRSPatientSheetByMailToGP();
}

function function2(){
}

function function3(){
}

function function4(){
}

function function5(){
}

function function6(){
}

function function7(){
}

function function8(){
}

function function9(){
}

function function10(){
}
57 changes: 0 additions & 57 deletions src/PatientParameters.gs

This file was deleted.

69 changes: 40 additions & 29 deletions src/PatientSheets.gs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,40 @@ function patientSheetIdAndNameArray() {
const regExp = new RegExp("^[_z]+.*$")
return SpreadsheetApp.getActiveSpreadsheet()
.getSheets()
.map(s => [s.getSheetId(),s.getName()] )
.filter(n => !regExp.exec(n[1]) );
}

// @deprecated
function patientSheetNames() {
const regExp = new RegExp("^[_z]+.*$")
return SpreadsheetApp.getActiveSpreadsheet()
.getSheets()
.map(s => s.getName())
.filter(n => !regExp.exec(n) );
.map(s => [s.getSheetId(),s.getName(),s.getRange("D1").getValue(),s.getRange("B2").getValue()] )
.filter(n => !regExp.exec(n[1]) )
.sort(function(a, b) {
return a[0] - b[0];
});
}

function refreshPatientSheetNames(){
const systemSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("zzz_system");
const patientViewSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("zzz_system_patient_view");
const patientIdxNameSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("zzz_system_patient_idx_name");

const a = patientSheetIdAndNameArray();
systemSheet.getRange(3,1,1000,2).clearContent();
patientViewSheet.getRange(2,1,1000,4).clearContent();
patientIdxNameSheet.getRange(2,1,1000,2).clearContent();

if(a.length > 0)
systemSheet.getRange(3,1,a.length,2).setValues(a);
if(a.length > 0){
systemSheet.getRange(3,1,a.length,2).setValues(a.map(r => [r[0],r[1]]));
patientViewSheet.getRange(2,1,a.length,4).setValues(a.map(r => [r[0],r[1],r[2]=="oui",r[3]])); // TODO translation harcoded, should be true?false in patient sheet

const patientIdxName = a.map(r => [r[1],r[0]]).sort(function(a, b) {
return a[0] > b[0] ? 1 : -1;
});

patientIdxNameSheet.getRange(2,1,a.length,2).setValues(patientIdxName);
}
}

function importPatientSheetTemplate(destination){

// TODO change way of coding to call PropertiesService earlier
const documentProperties = PropertiesService.getDocumentProperties();
const source = SpreadsheetApp.openByUrl(documentProperties.getProperty("patientSheetTemplateSpreadsheetUrl"))
const source = SpreadsheetApp.openByUrl(documentProperties.getProperty("templateSpreadsheetUrl"))
const template = source.getSheetByName(documentProperties.getProperty("patientSheetTemplateSheetName"));
const sheet = template.copyTo(destination);
copySheetRangeProtectionWarnings(template,sheet);
Expand All @@ -50,7 +57,7 @@ function importPatientSheetTemplate(destination){
function createEmptyMRSPatientSheet(){

const ui = SpreadsheetApp.getUi();
const response = ui.prompt('Créer une nouvelle fiche patient', 'Entrer le nom de la fiche', ui.ButtonSet.OK_CANCEL);
const response = ui.prompt('Créer une nouvelle fiche patient', 'Entrer le nom de la fiche', ui.ButtonSet.OK_CANCEL);

if (response.getSelectedButton() == ui.Button.CANCEL){
return;
Expand All @@ -67,6 +74,8 @@ function createEmptyMRSPatientSheet(){

// copySheetRangeProtectionWarnings(template,sheet);
// rename to generate
// 2 sec per sheet when generating patients
// 0.5 sec per sheet when transfering parameters
function createMRSPatientSheet(){

const currentSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
Expand All @@ -78,8 +87,8 @@ function createMRSPatientSheet(){
// Demande de confirmation
const ui = SpreadsheetApp.getUi();
const result = ui.alert(
"Générer fiche(s) patient(s)",
`Voulez-vous générer ${sheetsAmount} fiche(s) patient(s).`,
"Générer fiche(s) patient(s)",
`Voulez-vous générer ${sheetsAmount} fiche(s) patient(s).`,
ui.ButtonSet.YES_NO);

// Process the user's response.
Expand All @@ -90,7 +99,7 @@ function createMRSPatientSheet(){
const localTemplate = importPatientSheetTemplate(currentSpreadSheet);
localTemplate.setName(Utilities.formatDate(new Date(), "GMT+1", "yyyy-MM-dd") + "-temporary-template");

const rangeToUpdate = "B4:B12";
const rangeToUpdate = "B2:B12";
const templateValues = localTemplate.getRange(rangeToUpdate).getValues();

for (let key in currentRange)
Expand All @@ -105,16 +114,17 @@ function createMRSPatientSheet(){
const templateValuesCopy = Array.from(templateValues);

templateValuesCopy[0][0] = row[1];
templateValuesCopy[1][0] = row[2];
templateValuesCopy[2][0] = row[2];
templateValuesCopy[3][0] = row[3];
templateValuesCopy[4][0] = row[4];
templateValuesCopy[5][0] = row[5];
templateValuesCopy[5][0] = row[4];
templateValuesCopy[6][0] = row[5];
templateValuesCopy[7][0] = row[6];
templateValuesCopy[8][0] = row[7];
templateValuesCopy[9][0] = row[7];
templateValuesCopy[10][0] = row[8];

newSheet.getRange(rangeToUpdate).setValues(templateValuesCopy)

currentSpreadSheet.toast(`La fiche patient ${sheetName} a été générée`,"Fiche générée");
currentSpreadSheet.toast(`La fiche patient ${sheetName} a été générée`,"Fiche générée");
}

currentSpreadSheet.deleteSheet(localTemplate)
Expand Down Expand Up @@ -142,8 +152,8 @@ function sendMRSPatientSheetByMailToGP() {
// Demande de confirmation
const ui = SpreadsheetApp.getUi();
const result = ui.alert(
"Envoi de la fiche au médecin traitant",
`Voulez-vous envoyer la fiche de ${patientName} à l'adresse ${practitionerEmail}.`,
"Envoi de la fiche au médecin traitant",
`Voulez-vous envoyer la fiche de ${patientName} à l'adresse ${practitionerEmail}.`,
ui.ButtonSet.YES_NO); // TODO change to YES_CANCEL

// Process the user's response.
Expand All @@ -155,8 +165,8 @@ function sendMRSPatientSheetByMailToGP() {
const message =
`Docteur ${practitionerFullName},
Vous trouverez en attaché le compte rendu journalier de votre patient ${patientName} hébergé ds notre MR(S).
Nous vous invitons à en prendre connaissance et nous transmettre vos remarques éventuelles.
Vous trouverez en attaché le compte rendu journalier de votre patient ${patientName} hébergé ds notre MR(S).
Nous vous invitons à en prendre connaissance et nous transmettre vos remarques éventuelles.
Pour la MRS,
${nurseName}`;
Expand All @@ -166,7 +176,7 @@ ${nurseName}`;
const pdf = convertSheetToPdf(currentSpreadSheet,currentSheet,"Fiche MRS de " + patientName);
MailApp.sendEmail(practitionerEmail, subject, message, {attachments:pdf});

currentSpreadSheet.toast('Mail envoyé', 'Mail envoyé');
currentSpreadSheet.toast('Mail envoyé', 'Mail envoyé');
}

function archivePatientSheet(){
Expand All @@ -186,7 +196,8 @@ function archivePatientSheet(){
}

const folder = DriveApp.getFileById(currentSpreadSheet.getId()).getParents().next();
const archiveFolder = folder.getFoldersByName("Archives").next().getFoldersByName("Patients").next();

const archiveFolder = getFoldersByNameOrCreate(getFoldersByNameOrCreate(folder,"Archives"),"Patients");

const pdf = convertSheetToPdf(currentSpreadSheet,sheet,Utilities.formatDate(new Date(), "GMT+1", "yyyy_MM") + "_" + sheetName);
archiveFolder.createFile(pdf);
Expand Down
6 changes: 6 additions & 0 deletions src/SheetUtilities.gs
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ function convertSheetToPdf(spreadsheet, sheet, pdfName, lastColumn = columnToLet
return response.getBlob().setName(pdfName + '.pdf');
}

function getFoldersByNameOrCreate(mainFolder, name){
var path = mainFolder.getFoldersByName(name);
return path.hasNext() ?
path.next() : mainFolder.createFolder(name);
}

Loading

0 comments on commit ce3d2d8

Please sign in to comment.