Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

patient notes migration #13

Merged
merged 5 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ start.sh

stop.sh

newrelic.js

newrelic_agent.log

newrelic.js
42 changes: 42 additions & 0 deletions utils/patient-notes-mig.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
1 change: 1 addition & 0 deletions utils/pouch-mig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function migrateRecords() {
data: result.doc
};
existingKeys[newDocId] = true;
delete newDoc.data._id;
delete newDoc.data._rev;

switch (parsedId.doctype) {
Expand Down