Skip to content

Commit

Permalink
Merge pull request #3010 from openmsupply/release/v5.1.1
Browse files Browse the repository at this point in the history
Release/v5.1.1
  • Loading branch information
wlthomson authored Jul 6, 2020
2 parents 5369ed7 + 4ffb6f1 commit f97a074
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"name": "mSupplyMobile",
"//": "version must be in the format ${majorNumber}.${minorNumber}.${patchNumber}-rc${releaseCandidateNumber}",
"version": "5.1.0",
"version": "5.1.1",
"private": false,
"license": "MIT",
"description": "Mobile app for use with the mSupply medical inventory control software",
Expand Down
6 changes: 6 additions & 0 deletions src/database/DataTypes/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,13 @@ export class Transaction extends Realm.Object {
}

this.status = 'finalised';

database.save('Transaction', this);

// Trigger update on linked transaction batches to ensure they are pushed to sync out queue.
this.items.forEach(item =>
item.batches.forEach(batch => database.save('TransactionBatch', batch))
);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/database/utilities/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

/**
* Returns the boolean string as a boolean (false if none passed)
* @param {string} numberString The string to convert to a boolean
*
* @param {string} numberString The string to convert to a boolean
* @return {boolean} The boolean representation of the string
*/
export const parseBoolean = booleanString => {
const trueStrings = ['true', 'True', 'TRUE'];
return trueStrings.includes(booleanString);
};
export const parseBoolean = booleanString => booleanString?.toString()?.toLowerCase() === 'true';

/**
* Return a Date object representing the given date, time.
Expand Down
4 changes: 4 additions & 0 deletions src/sync/SyncDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class SyncDatabase {
return this.database.create(...args, 'sync');
}

get(type, primaryKey, primaryKeyField = 'id') {
return this.database.get(type, primaryKey, primaryKeyField);
}

getOrCreate(type, primaryKey, primaryKeyField = 'id') {
return this.database.getOrCreate(type, primaryKey, primaryKeyField, 'sync');
}
Expand Down
55 changes: 38 additions & 17 deletions src/sync/SyncQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ export class SyncQueue {
this.database.removeListener(this.databaseListenerId);
}

isValidSyncOutRecord(syncOutRecord) {
const { recordType, recordId } = syncOutRecord;

if (!recordId) return false;
const record = this.database.get(recordType, recordId);
if (!record) return false;

switch (recordType) {
// Only sync prescriptions which are finalised.
case 'Transaction':
return !(record.isPrescription && !record.isFinalised);
case 'TransactionBatch':
return !(record.transaction.isPrescription && !record.transaction.isFinalised);
// Only sync out prescribers from this store.
case 'Prescriber':
return record.fromThisStore;
default:
return true;
}
}

/**
* Respond to a database change event. Must be called from within a database
* write transaction.
Expand All @@ -72,24 +93,24 @@ export class SyncQueue {
case CREATE:
case UPDATE:
case DELETE: {
if (!record.id) return;
const existingSyncOutRecord = this.database
.objects('SyncOut')
.filtered('recordId == $0', record.id)[0];
if (!existingSyncOutRecord) {
this.database.create('SyncOut', {
id: generateUUID(),
changeTime: new Date().getTime(),
changeType,
recordType,
recordId: record.id,
});
} else {
existingSyncOutRecord.changeTime = new Date().getTime();
existingSyncOutRecord.changeType = changeType;
existingSyncOutRecord.recordType = recordType;
this.database.save('SyncOut', existingSyncOutRecord);
const { id: recordId } = record;

const syncOutRecord = {
changeTime: new Date().getTime(),
changeType,
recordType,
recordId,
};

if (this.isValidSyncOutRecord(syncOutRecord)) {
const existingSyncOutRecord = this.database.get('SyncOut', recordId);
if (existingSyncOutRecord) {
this.database.save('SyncOut', { ...existingSyncOutRecord, ...syncOutRecord });
} else {
this.database.create('SyncOut', { id: generateUUID(), ...syncOutRecord });
}
}

break;
}
default:
Expand Down
12 changes: 4 additions & 8 deletions src/sync/lookupApiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ const processInsuranceResponse = response =>
})
);

export const processPatientResponse = response => {
const patientData = response.map(
export const processPatientResponse = response =>
response.map(
({
ID: id,
name,
Expand Down Expand Up @@ -156,11 +156,9 @@ export const processPatientResponse = response => {
policies: processInsuranceResponse(nameInsuranceJoin),
})
);
return patientData;
};

export const processPrescriberResponse = response => {
const prescriberData = response.map(
export const processPrescriberResponse = response =>
response.map(
({
ID,
first_name,
Expand All @@ -185,5 +183,3 @@ export const processPrescriberResponse = response => {
storeId: store_ID,
})
);
return prescriberData;
};
9 changes: 0 additions & 9 deletions src/sync/outgoingSyncUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ const generateSyncData = (settings, recordType, record) => {
};
}
case 'Transaction': {
// Only sync prescriptions which are finalised.
if (record.isPrescription && !record.isFinalised) return null;

const defaultCurrency = UIDatabase.objects('Currency').filtered(
'isDefaultCurrency == $0',
true
Expand Down Expand Up @@ -236,9 +233,6 @@ const generateSyncData = (settings, recordType, record) => {
case 'TransactionBatch': {
const { transaction } = record;

// Only sync prescription lines if prescription is finalised.
if (transaction.isPrescription && !transaction.isFinalised) return null;

return {
ID: record.id,
transaction_ID: record.transaction.id,
Expand Down Expand Up @@ -289,9 +283,6 @@ const generateSyncData = (settings, recordType, record) => {
};
}
case 'Prescriber': {
// Only sync out prescribers from this store.
if (!record.fromThisStore) return null;

const initials = `${record.firstName?.[0] ?? ''}${record.lastName?.[0] ?? ''}`;

return {
Expand Down

0 comments on commit f97a074

Please sign in to comment.