diff --git a/.gitignore b/.gitignore index aa7a9c39..e51b467b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,6 @@ start.sh stop.sh -newrelic.js - newrelic_agent.log + +newrelic.js diff --git a/utils/patient-notes-mig.js b/utils/patient-notes-mig.js new file mode 100644 index 00000000..1cdf57ef --- /dev/null +++ b/utils/patient-notes-mig.js @@ -0,0 +1,42 @@ +var config = require('../config.js'); +var nano = require('nano')(config.couchAuthDbURL); +var maindb = nano.use('main'); +var uuid = require('node-uuid'); +var recordsToUpdate = []; + +maindb.list({startkey: 'visit_', endkey: 'visit_\uffff', include_docs: true}, function(err, results) { + if (!err) { + results.rows.forEach(function(result) { + var visitDoc = result.doc.data; + if (visitDoc !== null && visitDoc.notes && !visitDoc.patientNotes) { + var noteUuid = uuid.v4(); + var visitId = result.doc._id.substr(8); + var patientNote = { + _id: 'patientNote_2_' + noteUuid, + data: { + content: visitDoc.notes, + createdBy: 'system', + date: new Date(), + noteType: 'General', + patient: visitDoc.patient, + visit: visitId + } + }; + recordsToUpdate.push(patientNote); + result.doc.data.patientNotes = [noteUuid]; + recordsToUpdate.push(result.doc); + } + }); + if (recordsToUpdate.length > 0) { + maindb.bulk({ docs: recordsToUpdate}, function(err, results) { + if (err) { + console.log('Error updating patient notes records.', err); + } else { + console.log('Success updating patient notes records.', JSON.stringify(results, null, 2)); + } + }); + } + } else { + console.log('ERROR fetching visit records', err); + } +}); diff --git a/utils/pouch-mig.js b/utils/pouch-mig.js index 12067c6b..aded4099 100644 --- a/utils/pouch-mig.js +++ b/utils/pouch-mig.js @@ -31,6 +31,7 @@ function migrateRecords() { data: result.doc }; existingKeys[newDocId] = true; + delete newDoc.data._id; delete newDoc.data._rev; switch (parsedId.doctype) {