Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v8.6.0 #4936

Merged
merged 177 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
27e2791
Add a button to save changes
kat-ms May 5, 2022
5aaec81
Merge branch 'Release/8.5.0' into #4691-Edit-PCD-via-VaccinationEvent…
kat-ms May 12, 2022
22875d6
Add a function to update the linked survey name note
kat-ms May 16, 2022
74b44ad
Add a toast :bread:
kat-ms May 17, 2022
46d7fe5
Undo package.json version bump (not for develop)
kat-ms May 17, 2022
3b3151b
Simplify button press logic
kat-ms May 18, 2022
e8fd8df
Add an audit name note when updating historical PCDs :scream_cat:
kat-ms May 19, 2022
feffb79
Add isDeceased toggle to patient form
kat-ms May 19, 2022
eb122db
Further updates to read/save isDeceased flag
kat-ms May 20, 2022
b54fccc
🙈
kat-ms May 24, 2022
0913d22
Merge pull request #4719 from openmsupply/#4672-Record-patient-as-dec…
kat-ms May 30, 2022
7c959fc
Merge pull request #4713 from openmsupply/#4691-Edit-PCD-via-Vaccinat…
kat-ms May 30, 2022
8e4bc74
Fix broken name note duplicate filter
kat-ms Jun 1, 2022
4e4a4e0
Dispatch reloadItems action to store
kat-ms Jun 2, 2022
3cc66f9
Merge pull request #4748 from openmsupply/#4743-Duplicate-vaccination…
kat-ms Jun 2, 2022
67648c7
Merge pull request #4750 from openmsupply/#4394-Items-not-showing-whe…
kat-ms Jun 2, 2022
7999304
Style updates to Checkbox/Togglebar
kat-ms Jun 13, 2022
bc5d7e8
Merge pull request #4756 from openmsupply/#4755-Updated-togglebar-com…
kat-ms Jun 13, 2022
d6ee943
Add ability to edit supplemental data form
kat-ms Jun 15, 2022
5c28263
String localisation
kat-ms Jun 15, 2022
9adf69e
Allow length of > 3 for email TLD
kat-ms Jun 16, 2022
d89246c
Less restrictive regex
kat-ms Jun 17, 2022
b1e7004
Merge pull request #4762 from openmsupply/#4759-Demo-store-email-vali…
kat-ms Jun 17, 2022
e209168
Make the buttons match
kat-ms Jun 20, 2022
174618b
Merge branch 'develop' into #4715-Edit-vaccination-transact-data-via-…
kat-ms Jun 20, 2022
3bd6ac3
Merge branch '#4714-Edit-supplemental-data-via-vaccination-event-moda…
kat-ms Jun 20, 2022
fae0f70
For future - save the storeId/name into the NameNote
kat-ms Jun 22, 2022
5caf2e4
Merge pull request #4758 from openmsupply/#4714-Edit-supplemental-dat…
kat-ms Jun 22, 2022
3f09aaa
Merge branch 'develop' into #4715-Edit-vaccination-transact-data-via-…
kat-ms Jun 22, 2022
a735e7c
Update Modal to not render cancel button if no cancel button text is …
kat-ms Jun 22, 2022
959a983
Extract VaccinatorDropDown into separate file
kat-ms Jun 23, 2022
f06d38f
Updates to allow creation of customer credit and refund lines
kat-ms Jun 23, 2022
b4b4964
UI changes to trigger credit when editing of vaccine transaction. Doe…
kat-ms Jun 27, 2022
8a48d66
Add stock instead of subtracting stock when creating credit
kat-ms Jun 28, 2022
aae73df
Correct dodgy stock maths and fix customer invoice display for credits
kat-ms Jun 29, 2022
8084d06
More fixes (total refers to $ not quantity)
kat-ms Jun 29, 2022
50c4f6f
Update mobile schema
kat-ms Jun 29, 2022
d1dc44e
Sync updates for isDeleted
kat-ms Jun 29, 2022
018cf2f
Hide soft deleted patients
kat-ms Jun 30, 2022
4191a9a
Add defaults for isDeleted
kat-ms Jun 30, 2022
d852abf
Fix the isDeleted filter, prescribers don't have it
kat-ms Jun 30, 2022
5475090
Match the desktop field name correctly
kat-ms Jun 30, 2022
106c620
Merge pull request #4777 from openmsupply/#4775-Soft-deletion-of-name…
kat-ms Jul 1, 2022
b9a5d47
Merge branch 'develop' into #4715-Edit-vaccination-transact-data-via-…
kat-ms Jul 1, 2022
4637ebd
Create new name note and soft delete old one when vaccine is edited
kat-ms Jul 1, 2022
0a032da
Update date-picker to properly set initialValue
sworup Jul 5, 2022
b991467
Update datepicker date value logic
sworup Jul 5, 2022
394ad12
Merge pull request #4778 from openmsupply/#4715-Edit-vaccination-tran…
mark-prins Jul 11, 2022
80e93c6
added localization string
FlorenceChashchina Jul 12, 2022
1c76c67
check that patient is not deceased
FlorenceChashchina Jul 12, 2022
b8616ba
fixed styling fro disabled toggle
FlorenceChashchina Jul 12, 2022
1e6a051
fixed bug with disable toggle showing incorrectly
FlorenceChashchina Jul 12, 2022
8634d79
changed variable name
FlorenceChashchina Jul 12, 2022
ed2f882
Add an alert if user creates new Deceased patient or changes current …
FlorenceChashchina Jul 12, 2022
996b21e
just small cosmetic bug fixed
FlorenceChashchina Jul 12, 2022
ad85126
Date comes in as different format so make it compatible
sworup Jul 12, 2022
7cc1233
refactor code
FlorenceChashchina Jul 13, 2022
45f396c
code refactoring 2
FlorenceChashchina Jul 13, 2022
af95de7
refactor code 3
FlorenceChashchina Jul 13, 2022
5419752
Edited the localization string as per Adam's comment
FlorenceChashchina Jul 13, 2022
b6dd3ad
adjustments to NameNote toObject structure (to include isDelete)
FlorenceChashchina Jul 13, 2022
123753c
localizations for deletion of vaccination event
FlorenceChashchina Jul 13, 2022
0176635
use isDeleted field, added deleteNameNote action to nameNoteActions
FlorenceChashchina Jul 13, 2022
fd17755
isDeleted is populated for the new name note (just in case)
FlorenceChashchina Jul 13, 2022
2378b88
add delete button to the vaccination event
FlorenceChashchina Jul 13, 2022
169d934
oops wrong old code
FlorenceChashchina Jul 13, 2022
7755008
Disable the form after the data was edited
FlorenceChashchina Jul 13, 2022
72b8c5b
removed debugging code
FlorenceChashchina Jul 13, 2022
533c4a0
toggle edit Transaction after deletion as well
FlorenceChashchina Jul 13, 2022
029e14f
removing debug code
FlorenceChashchina Jul 13, 2022
728e8b0
Merge pull request #4798 from openmsupply/#4796-soft-deletion-of-vacc…
FlorenceChashchina Jul 13, 2022
c2433a5
show store name if set
FlorenceChashchina Jul 17, 2022
330c55e
Merge pull request #4794 from openmsupply/#4792-prevent-giving-vaccin…
FlorenceChashchina Jul 18, 2022
010d7a0
Merge pull request #4804 from openmsupply/#4801-show-store-name-of-va…
FlorenceChashchina Jul 18, 2022
465d1c1
fixed bug
FlorenceChashchina Jul 18, 2022
696a59c
added isDeleted field to lookupApiUtils for NameNote
FlorenceChashchina Jul 19, 2022
ab33ca6
Update patient history on click
FlorenceChashchina Jul 19, 2022
5ba9056
Merge pull request #4806 from openmsupply/#4792-Bug-in-code-for-preve…
FlorenceChashchina Jul 19, 2022
5f811f8
Merge branch 'develop' into #4805-editing-vaccination-event-bugs
FlorenceChashchina Jul 19, 2022
c1be518
lineHeight bug fixed
FlorenceChashchina Jul 19, 2022
636e11b
Enable manual date input in Datepicker
sworup Jul 19, 2022
ef2812f
Bug fixed when wrong vaccine shown on editing
FlorenceChashchina Jul 19, 2022
10cfc79
Tidied up the icons
FlorenceChashchina Jul 19, 2022
e9afe90
Update variable name typo fix
sworup Jul 19, 2022
a73b3e7
The PCD form and SupplemantalData forms were validated before, so it …
FlorenceChashchina Jul 20, 2022
1b24b4c
bug fixed with deceased patients
FlorenceChashchina Jul 20, 2022
4e89216
Add delete patient record feature
sworup Jul 20, 2022
f5b867c
remove debug code
FlorenceChashchina Jul 20, 2022
f3a2374
Merge pull request #4807 from openmsupply/#4805-editing-vaccination-e…
sworup Jul 21, 2022
1c31843
Update query to exclude deleted records
sworup Jul 21, 2022
41e2aab
Update delete patient logic
sworup Jul 21, 2022
a6ada7b
Add logics to disable delete button if the patient has active vaccine…
sworup Jul 21, 2022
f841dd3
Update fix
sworup Jul 21, 2022
d08f3ad
Add are you sure confimation to delete patient
sworup Jul 21, 2022
b705574
Add cancel as button text instead of Go back
sworup Jul 22, 2022
983e600
Please make sure that the vaccine events has been deleted if you want…
sworup Jul 22, 2022
b0d9bf6
Update datepicker default value
sworup Jul 22, 2022
e5a2860
Merge pull request #4786 from openmsupply/#4785-Date-picker-and-date-…
FlorenceChashchina Jul 24, 2022
bc81d43
Rename cannot delete modal state variables
sworup Jul 25, 2022
6bd1c7a
Disable deletion of patient from other stores
sworup Jul 25, 2022
6f61b10
Clean up
sworup Jul 26, 2022
0b6b4bb
If there is no transactions return empty array
sworup Jul 26, 2022
8e32b74
Do not show delete button in New patient form
sworup Jul 27, 2022
af0abf7
Merge pull request #4812 from openmsupply/#4802-Kiribati-Delete-patie…
sworup Jul 27, 2022
369dcae
Fix PatientSelectComponent bugs out when closed
sworup Aug 2, 2022
3e6236d
filter vaccines so it doesn't show vaccines out of stock
FlorenceChashchina Aug 2, 2022
3dd6c55
Merge pull request #4848 from openmsupply/#4823-changing-vaccine-to-o…
sworup Aug 3, 2022
79bc1f3
Merge pull request #4846 from openmsupply/#4838-Fix-PatientSelectComp…
sworup Aug 3, 2022
f8703af
Fix Save and delete button was still showing for remote patients
sworup Aug 3, 2022
52f5253
disable button after clicking
FlorenceChashchina Aug 4, 2022
a149439
Merge pull request #4850 from openmsupply/#4849-Save-and-delete-butto…
sworup Aug 5, 2022
358b363
Disabled next button during submission enable it afterwards
sworup Aug 8, 2022
f4be3f3
Make sure all steps of vaccine event creation flow would not trigger …
sworup Aug 8, 2022
187fb14
Merge pull request #4851 from openmsupply/#4844-double-clicking-save-…
sworup Aug 8, 2022
b510222
Merge pull request #4859 from openmsupply/#4820-Vaccination-event-can…
FlorenceChashchina Aug 9, 2022
e12c626
#4647 added toggle to hide zero stock
sah-arjun Aug 9, 2022
ad01b19
added toggle button resources
sah-arjun Aug 9, 2022
a0362dc
#4847 Fixed chopping of label Done
sah-arjun Aug 9, 2022
533a576
Merge pull request #4865 from openmsupply/#4847-Done-label-chopped
sworup Aug 11, 2022
3fe783b
disable confirm button after click
FlorenceChashchina Aug 15, 2022
e5698d9
Merge pull request #4880 from openmsupply/#4871-App-hangs/keeps-on-lo…
sworup Aug 15, 2022
cacbcaf
Fix Deleted patients again shows up
sworup Aug 15, 2022
019fae0
Code cleanup
sworup Aug 15, 2022
b338d92
button resources improved
sah-arjun Aug 15, 2022
d78b9a6
Fix lookup patient overriding current changes
sworup Aug 15, 2022
3befa57
Merge branch '#4842-Deleted-patients-again-shows-up' into #4841-Stop-…
sworup Aug 15, 2022
0002932
Remove typo
sworup Aug 16, 2022
e84ca90
Merge pull request #4881 from openmsupply/#4842-Deleted-patients-agai…
sworup Aug 16, 2022
117d384
Merge pull request #4882 from openmsupply/#4841-Stop-lookup-patient-o…
sworup Aug 16, 2022
be6d543
#4647 added toggle to hide zero stock
sah-arjun Aug 9, 2022
ebc159b
added toggle button resources
sah-arjun Aug 9, 2022
be96fb0
button resources improved
sah-arjun Aug 15, 2022
adab080
Merge branch '#4647-Current-Stock-add-toggle-to-hide-zero-stock' of h…
sworup Aug 16, 2022
52f364c
Refactor toggleStockOut reducer
sworup Aug 16, 2022
484ff67
Merge pull request #4864 from openmsupply/#4647-Current-Stock-add-tog…
sworup Aug 16, 2022
2858184
Disable deleted patient from being given vaccine
sworup Aug 16, 2022
2e90610
New Patient button should only go to tab 2
sworup Aug 16, 2022
2606619
Merge pull request #4893 from openmsupply/#4885-Disable-deleted-patie…
FlorenceChashchina Aug 16, 2022
a845fe2
Merge pull request #4895 from openmsupply/#4887-New-Patient-button-sh…
FlorenceChashchina Aug 16, 2022
f9c11f3
disable ok and repeat after clicking
FlorenceChashchina Aug 17, 2022
5e785f1
#4894 fixed toggle failure
sah-arjun Aug 17, 2022
d60fea6
Merge pull request #4896 from openmsupply/#4886-App-hangs/keeps-on-lo…
sworup Aug 17, 2022
9be4aed
Fix App crashes on tapping Save changes button multiple times
sworup Aug 19, 2022
4aebf03
Fix vaccination event edit logic
sworup Aug 19, 2022
8e7d7cb
Minor refactor
sworup Aug 19, 2022
9f370b8
Fix bug where vaccine selection during edit was having indexing discr…
sworup Aug 19, 2022
ca05931
Fix vaccinator dropdown's actual data was not updating
sworup Aug 19, 2022
e82adf2
UPdate disabled logic
sworup Aug 22, 2022
a7e3183
Update useeffects to cut down load time
sworup Aug 22, 2022
e2580eb
Add loading indicator
sworup Aug 23, 2022
af8a885
Merge pull request #4899 from openmsupply/4888-Fix-App-crashes-on-tap…
sworup Aug 26, 2022
1397945
Lock vaccination event details to home store
sworup Aug 26, 2022
3d10ce7
Update transaction check with a boolean
sworup Aug 29, 2022
6ae34e3
Merge pull request #4906 from openmsupply/#4905-Lock-vaccination-even…
sworup Aug 29, 2022
d6aab91
Fix the issue where a blank NameNote is created on every edit and it …
sworup Sep 1, 2022
823b939
Fix all nameNotes of Patient being updated every time VaccineEvent is…
sworup Sep 1, 2022
a6ce058
Move is object empty check to a separate utility function
sworup Sep 2, 2022
564a263
Update patient create
sworup Sep 2, 2022
e30778b
Merge pull request #4912 from openmsupply/#4911-When-new-vaccine-even…
sworup Sep 5, 2022
d4e46ce
#4913 Vax event creation and editing should not trigger patient updat…
sworup Sep 5, 2022
991483c
Merge pull request #4914 from openmsupply/#4913-Vax-event-creation-an…
sworup Sep 6, 2022
dbe9029
Fix Subpage 2 Additional details' changes are overridden by Subpage 3…
sworup Sep 7, 2022
ca92dab
Fix patient homes store vax event reupdate error
sworup Sep 7, 2022
a2cbf4c
Merge pull request #4919 from openmsupply/#4909-Subpage-2-is-override…
sworup Sep 8, 2022
5a25373
Merge pull request #4921 from openmsupply/#4920-Patient-homes-store-v…
sworup Sep 8, 2022
5565998
Make form controls color gray when disabled
sworup Sep 13, 2022
bbc6ed4
Make uneditable form's button gray background
sworup Sep 13, 2022
afc5744
Rename saveButtonCantEdit to saveButtonCannotEdit
sworup Sep 14, 2022
1412a45
Make styles better
sworup Sep 14, 2022
7e9353a
Merge pull request #4926 from openmsupply/#4925-Event-details-subform…
sworup Sep 14, 2022
493a52f
Merge pull request #4897 from openmsupply/#4894-toggle-failure-curren…
sworup Sep 14, 2022
ed35ca4
Bump version up
sworup Sep 15, 2022
6224577
Fix datepicker issues
sworup Sep 15, 2022
e1fdd29
Need date as type not moment
sworup Sep 15, 2022
3924ad6
Disallow non DD/MM/YYYY format for DOB
sworup Sep 15, 2022
4f1c303
Fix #4892 DOB field of Patient edit is showing invalid if we let dob …
sworup Sep 15, 2022
04d4c0b
Merge pull request #4933 from openmsupply/#4892-Fix-DOB-field-issues
sworup Sep 16, 2022
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 android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);

def getAppVersion() {
def inputFile = new File("../package.json")
def inputFile = new File("${project.projectDir}/../../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}

def getAppName() {
def inputFile = new File("../package.json")
def inputFile = new File("${project.projectDir}/../../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["name"]
}
Expand Down
5 changes: 3 additions & 2 deletions 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": "8.5.0",
"version": "8.6.0",
"private": false,
"license": "MIT",
"description": "Mobile app for use with the mSupply medical inventory control software",
Expand All @@ -16,7 +16,8 @@
"url": "http://github.com/sussol/mobile",
"homepage": "http://msupply.org.nz",
"scripts": {
"start": "react-native run-android",
"start": "react-native start",
"android": "react-native run-android",
"log": "react-native log-android",
"shake": "adb shell input keyevent KEYCODE_MENU",
"rr": "adb shell input text \"RR\"",
Expand Down
6 changes: 3 additions & 3 deletions src/actions/Entities/NameActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const select = name => async dispatch => {
const result = await createPatientVisibility(name);
if (result) {
UIDatabase.write(() => {
selectedName = createRecord(UIDatabase, 'Patient', name);
selectedName = createRecord(UIDatabase, 'Patient', name, true);
});
} else {
ToastAndroid.show(generalStrings.problem_connecting_please_try_again, ToastAndroid.LONG);
Expand All @@ -96,15 +96,15 @@ const filter = (key, value) => ({ type: NAME_ACTIONS.FILTER, payload: { key, val

const sort = sortKey => ({ type: NAME_ACTIONS.SORT, payload: { sortKey } });

const saveEditing = () => (dispatch, getState) => {
const saveEditing = (shouldCreateNameNames = true) => (dispatch, getState) => {
const currentPatient = selectEditingName(getState());
const createdDate = currentPatient?.createdDate ? new Date(currentPatient.createdDate) : null;
const dateOfBirth = new Date(currentPatient.dateOfBirth);
const name = `${currentPatient.lastName}, ${currentPatient.firstName}`;

const patientRecord = { ...currentPatient, dateOfBirth, createdDate, name };

UIDatabase.write(() => createRecord(UIDatabase, 'Patient', patientRecord));
UIDatabase.write(() => createRecord(UIDatabase, 'Patient', patientRecord, shouldCreateNameNames));
dispatch(reset());
};

Expand Down
69 changes: 68 additions & 1 deletion src/actions/Entities/NameNoteActions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { generateUUID } from 'react-native-database';
import merge from 'lodash.merge';
import { ToastAndroid } from 'react-native';
import { createRecord, UIDatabase } from '../../database/index';
import {
selectCreatingNameNote,
selectMostRecentNameNote,
} from '../../selectors/Entities/nameNote';
import { selectSurveySchemas } from '../../selectors/formSchema';
import { validateJsonSchemaData } from '../../utilities/ajvValidator';
import { vaccineStrings } from '../../localization';
import { checkIsObjectEmpty } from '../../utilities';

export const NAME_NOTE_ACTIONS = {
SELECT: 'NAME_NOTE/select',
Expand All @@ -22,6 +25,7 @@ const createDefaultNameNote = (nameID = '') => {
entryDate: new Date(),
patientEventID: pcd?.id ?? '',
nameID,
isDeleted: false,
};
};

Expand Down Expand Up @@ -60,13 +64,73 @@ const updateForm = (data, validator) => ({
const saveEditing = () => (dispatch, getState) => {
const nameNote = selectCreatingNameNote(getState()) ?? {};
const patient = UIDatabase.get('Name', nameNote?.nameID);
const isDirty = JSON.stringify(patient?.mostRecentPCD?.data) !== JSON.stringify(nameNote?.data);
const isDirty =
!checkIsObjectEmpty(nameNote?.data) &&
JSON.stringify(patient?.mostRecentPCD?.data) !== JSON.stringify(nameNote?.data);
if (isDirty) {
UIDatabase.write(() => createRecord(UIDatabase, 'NameNote', nameNote));
}
dispatch(reset());
};

const updateNameNote = (originalNote, updatedData) => () => {
const { id, patientEvent, name, entryDate, _data, isDeleted } = originalNote;

// Quick & dirty check if the object was updated, trims out some un-needed updates
const isDirty = _data !== JSON.stringify(updatedData);

if (isDirty) {
const updatedNote = {
id,
patientEvent,
name,
entryDate: new Date(entryDate),
_data: JSON.stringify(updatedData),
isDeleted,
};

UIDatabase.write(() => {
UIDatabase.update('NameNote', updatedNote);
UIDatabase.create('NameNote', createNameNoteAudit(originalNote, updatedData));
});
ToastAndroid.show(vaccineStrings.vaccination_updated, ToastAndroid.LONG);
} else {
ToastAndroid.show(vaccineStrings.vaccination_not_updated, ToastAndroid.LONG);
}
};

const deleteNameNote = NameNote => () => {
UIDatabase.write(() => {
UIDatabase.update('NameNote', { id: NameNote.id, isDeleted: true });
});
};

const createNameNoteAudit = (originalNote, updatedData) => {
const { patientEvent, name, entryDate, isDeleted } = originalNote;
const [auditEvent] = UIDatabase.objects('PatientEvent').filtered('code == "NameNoteModified"');

const auditNameNote = {
id: generateUUID(),
name,
auditEvent,
entryDate: new Date(),
_data: JSON.stringify({
patientEvent,
old: {
entryDate,
data: originalNote.data,
},
new: {
entryDate: new Date(),
data: updatedData,
},
}),
isDeleted,
};

return auditNameNote;
};

const createNotes = (nameNotes = []) => {
UIDatabase.write(() => {
nameNotes.forEach(nameNote => {
Expand All @@ -80,6 +144,7 @@ const createNotes = (nameNotes = []) => {
name,
_data: JSON.stringify(nameNote?.data),
entryDate: new Date(nameNote?.entryDate),
isDeleted: nameNote.isDeleted,
};

UIDatabase.update('NameNote', toSave);
Expand All @@ -99,5 +164,7 @@ export const NameNoteActions = {
reset,
createSurveyNameNote,
updateForm,
updateNameNote,
deleteNameNote,
saveEditing,
};
44 changes: 36 additions & 8 deletions src/actions/Entities/VaccinePrescriptionActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
selectSelectedSupplementalData,
selectSelectedVaccinator,
} from '../../selectors/Entities/vaccinePrescription';
import { selectEditingNameId } from '../../selectors/Entities/name';
import { selectEditingNameId, selectEditingName } from '../../selectors/Entities/name';
import { NameActions } from './NameActions';
import { NameNoteActions } from './NameNoteActions';
import { goBack, gotoVaccineDispensingPage } from '../../navigation/actions';
import { selectSupplementalDataSchemas } from '../../selectors/formSchema';
import { validateJsonSchemaData } from '../../utilities/ajvValidator';
import { SETTINGS_KEYS } from '../../settings';

export const VACCINE_PRESCRIPTION_ACTIONS = {
CREATE: 'VACCINE_PRESCRIPTION/create',
Expand All @@ -29,7 +30,6 @@ export const VACCINE_PRESCRIPTION_ACTIONS = {
SELECT_BATCH: 'VACCINE_PRESCRIPTION/selectBatch',
SELECT_VACCINATOR: 'VACCINE_PRESCRIPTION/selectVaccinator',
SET_BONUS_DOSE: 'VACCINE_PRESCRIPTION/setBonusDose',
TOGGLE_HISTORY: 'VACCINE_PRESCRIPTION/toggleHistory',
SELECT_DEFAULT_VACCINE: 'VACCINE_PRESCRIPTION/selectDefaultVaccine',
};

Expand Down Expand Up @@ -191,6 +191,8 @@ const createVaccinationNameNote = (

// Extract name notes from the patient before saving as this can get huuuge(!)
const { nameNotes, ...patientObject } = patient.toJSON();
const storeId = UIDatabase.getSetting(SETTINGS_KEYS.THIS_STORE_ID);
const storeNameId = UIDatabase.getSetting(SETTINGS_KEYS.THIS_STORE_NAME_ID);

const data = {
refused,
Expand All @@ -208,13 +210,16 @@ const createVaccinationNameNote = (
patient: patientObject,
},
pcdNameNoteId: getPcdNameNoteID(patient.id),
storeId,
storeName: UIDatabase.objects('Name').filtered('id == $0', storeNameId)[0]?.name,
};
const newNameNote = {
id,
name: patient,
patientEvent,
entryDate: new Date(),
_data: JSON.stringify(data),
isDeleted: false,
};
UIDatabase.write(() => UIDatabase.create('NameNote', newNameNote));
};
Expand All @@ -225,6 +230,7 @@ const getPcdNameNoteID = patientId => {
.sorted('entryDate', true);
return patientNameNotes.length > 0 ? patientNameNotes[0].id : '';
};

const createSupplementaryData = () => (dispatch, getState) => {
// Create a supplementaryData object which is seeded with the data that was last
// entered against a prescription
Expand Down Expand Up @@ -276,7 +282,14 @@ const confirm = () => (dispatch, getState) => {
});
}
batch(() => {
dispatch(NameActions.saveEditing());
const { isEditable = true } = selectEditingName(getState());

// We are already not allowing patient update for patient that do not belong
// to the current store. This check will stop unnecessary updates.
if (isEditable) {
dispatch(NameActions.saveEditing(false));
}

dispatch(NameNoteActions.saveEditing());
dispatch(reset());
});
Expand Down Expand Up @@ -315,17 +328,33 @@ const confirmAndRepeat = () => dispatch =>
dispatch(gotoVaccineDispensingPage());
});

const toggleHistory = toggle => ({
type: VACCINE_PRESCRIPTION_ACTIONS.TOGGLE_HISTORY,
payload: { toggle },
});
const returnVaccineToStock = (patientID, transactionBatch) => (dispatch, getState) => {
const { user } = getState();
const { currentUser } = user;
const { totalQuantity } = transactionBatch;
const patient = UIDatabase.get('Name', patientID);

UIDatabase.write(() => {
const customerCredit = createRecord(
UIDatabase,
'CustomerCredit',
currentUser,
patient,
-totalQuantity,
'dispensary'
);
createRecord(UIDatabase, 'RefundLine', customerCredit, transactionBatch);
customerCredit.finalise(UIDatabase);
});
};

export const VaccinePrescriptionActions = {
cancel,
confirm,
create,
createSupplementaryData,
reset,
returnVaccineToStock,
selectBatch,
selectSupplementalData,
selectVaccine,
Expand All @@ -334,7 +363,6 @@ export const VaccinePrescriptionActions = {
selectVaccinator,
confirmAndRepeat,
setBonusDose,
toggleHistory,
selectDefaultVaccine,
updateSupplementalData,
};
22 changes: 21 additions & 1 deletion src/actions/PatientActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import { batch } from 'react-redux';

import { ToastAndroid } from 'react-native';
import { createRecord, UIDatabase } from '../database';
import { selectCurrentUser } from '../selectors/user';

import { createPatientVisibility } from '../sync/lookupApiUtils';
import { DispensaryActions } from './DispensaryActions';
import { dispensingStrings } from '../localization';

export const PATIENT_ACTIONS = {
PATIENT_EDIT: 'Patient/patientEdit',
Expand All @@ -22,6 +24,7 @@ export const PATIENT_ACTIONS = {
SAVE_ADR: 'Patient/saveADR',
CANCEL_ADR: 'Patient/cancelADR',
REFRESH: 'Patient/refresh',
PATIENT_DELETE: 'Patient/delete',
};

const closeModal = () => ({ type: PATIENT_ACTIONS.COMPLETE });
Expand All @@ -34,6 +37,18 @@ const makePatientVisibility = async name => {
return response;
};

const patientDelete = () => (dispatch, getState) => {
const { patient } = getState();
const { currentPatient } = patient;
UIDatabase.write(() => {
UIDatabase.update('Name', { id: currentPatient.id, isDeleted: true });
});

ToastAndroid.show(dispensingStrings.patient_deleted, ToastAndroid.LONG);
dispatch(closeModal());
return { type: PATIENT_ACTIONS.PATIENT_DELETE, payload: { patient } };
};

const patientUpdate = patientDetails => async (dispatch, getState) => {
const { patient } = getState();
const { currentPatient } = patient;
Expand All @@ -53,6 +68,7 @@ const patientUpdate = patientDetails => async (dispatch, getState) => {
country: currentCountry,
supplyingStoreId: currentSupplyingStoreId,
isActive: currentIsActive,
isDeceased: currentIsDeceased,
female: currentFemale,
ethnicity: currentEthnicity,
nationality: currentNationality,
Expand Down Expand Up @@ -82,6 +98,7 @@ const patientUpdate = patientDetails => async (dispatch, getState) => {
country: patientCountry,
supplyingStoreId: patientSupplyingStoreId,
female: patientFemale,
isDeceased: patientIsDeceased,
ethnicity: patientEthnicity,
nationality: patientNationality,
} = patientDetails ?? {};
Expand All @@ -102,6 +119,7 @@ const patientUpdate = patientDetails => async (dispatch, getState) => {
const billPostalZipCode = patientPostalZipCode ?? currentZipCode;
const country = patientCountry ?? currentCountry;
const female = patientFemale ?? currentFemale;
const isDeceased = patientIsDeceased ?? currentIsDeceased;
const supplyingStoreId = patientSupplyingStoreId ?? currentSupplyingStoreId;
const isActive = currentIsActive;
const ethnicity = patientEthnicity ?? currentEthnicity;
Expand All @@ -124,14 +142,15 @@ const patientUpdate = patientDetails => async (dispatch, getState) => {
billPostalZipCode,
country,
female,
isDeceased,
supplyingStoreId,
isActive,
ethnicity,
nationality,
createdDate,
};

UIDatabase.write(() => createRecord(UIDatabase, 'Patient', patientRecord));
UIDatabase.write(() => createRecord(UIDatabase, 'Patient', patientRecord, false));

batch(() => {
dispatch(closeModal());
Expand Down Expand Up @@ -176,6 +195,7 @@ export const PatientActions = {
closeADRModal,
createPatient,
patientUpdate,
patientDelete,
editPatient,
closeModal,
sortPatientHistory,
Expand Down
2 changes: 1 addition & 1 deletion src/authentication/DemoSiteRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class DemoSiteRequest {
// TODO: Could be extracted to a helper file to be used elsewhere.
// eslint-disable-next-line class-methods-use-this
validateEmail(text) {
const reg = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
const reg = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
return reg.test(text);
}

Expand Down
Loading