Skip to content
Open
22 changes: 22 additions & 0 deletions deletePatientData/deletePatientCrater.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crater
set foreign_key_checks=0;
TRUNCATE table addresses;
TRUNCATE table expenses;
TRUNCATE table expense_categories;
TRUNCATE table taxes;
TRUNCATE table tax_types;
TRUNCATE table invoice_items;
TRUNCATE table invoices;
TRUNCATE table recurring_invoices;
TRUNCATE table estimate_items;
TRUNCATE table estimates;
TRUNCATE table items;
TRUNCATE table notes;
TRUNCATE table email_logs;
TRUNCATE table exchange_rate_logs;
TRUNCATE table exchange_rate_providers;
TRUNCATE table payments;
TRUNCATE table payment_methods;

delete from customers where id >0;
set foreign_key_checks=1;
118 changes: 36 additions & 82 deletions deletePatientData/deletePatientData.sh
Original file line number Diff line number Diff line change
@@ -1,96 +1,50 @@

GITHUB_URL="https://raw.githubusercontent.com/Bahmni/bahmni-scripts/master/deletePatientData"
#!/bin/sh
# Importing variable value from .env file in docker
. ./.env
OMRS_DB_ContainerName=bahmni-lite-openmrsdb-1
OPENELIS_DB_ContainerName=bahmni-standard-openelisdb-1
ODOO_DB_ContainerName=bahmni-standard-odoodb-1
CRATER_DB_ContainerName=bahmni-lite-craterdb-1

OPENMRS_SQL_FILE="deletePatientDataForOpenMRS.sql"
OPENELIS_SQL_FILE="deletePatientDataForOpenElis.sql"
OPENERP_SQL_FILE="deletePatientDataForOpenERP.sql"
CURDIR=$(pwd)


RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NOCOLOR='\033[0m'

stop_all_bahmni_services()
{

echo -e "${CYAN}Stopping all bahmni related services${NOCOLOR}"
bahmni -i $INVENTORY_FILE stop

}

ODOO_SQL_FILE="deletePatientDataForOdoo.sql"
CRATER_SQL_FILE="deletePatientDataForCrater.sql"
# When running on Docker runOnDocker=1, else another value
runOnDocker=1
download_and_delete_openmrs_patient_data(){
if [ -f $CURDIR/$OPENMRS_SQL_FILE ]; then
echo -e "${CYAN}deleting the existing file${NOCOLOR}"
rm -rf $CURDIR/$OPENMRS_SQL_FILE
fi
echo -e "${CYAN}downloading openmrs delete patient data sql file${NOCOLOR}"
wget $GITHUB_URL/$OPENMRS_SQL_FILE
if [ -z $OPENMRS_DB_USER ];then
echo -e "${RED}OPENMRS_DB_USER is unset.Please set the ENVIRONMENT VARIABLE OPENMRS_DB_USER ${NOCOLOR}"
else
echo -e "${CYAN} deleting openmrs patient data${NOCOLOR}"
mysql -u$OPENMRS_DB_USER -p$PASSWORD openmrs < $OPENMRS_SQL_FILE
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo -e "${RED}Failed to delete the openmrs patient data${NOCOLOR}"
else
echo -e "${GREEN} Successfully deleted the openmrs patient data${NOCOLOR}"
fi
fi
if [ "$runOnDocker" -eq 1 ]; then
docker exec -i $OMRS_DB_ContainerName mysql -u$OPENMRS_DB_USERNAME -p$OPENMRS_DB_PASSWORD openmrs < $OPENMRS_SQL_FILE
else
mysql -u$OPENMRS_DB_USERNAME -p$OPENMRS_DB_PASSWORD < $OPENMRS_SQL_FILE
fi

}

download_and_delete_openelis_patient_data(){
if [ -f $CURDIR/$OPENELIS_SQL_FILE ]; then
echo -e "${CYAN}deleting the existing file${NOCOLOR}"
rm -rf $CURDIR/$OPENELIS_SQL_FILE
fi
echo -e "${CYAN}downloading openelis delete patient data sql file${NOCOLOR}"
wget $GITHUB_URL/$OPENELIS_SQL_FILE
if [ -z "$OPENELIS_DB_USER" ];
then echo -e "${RED}OPENELIS_DB_USER is unset. Please set the ENVIRONMENT VARIABLE OPENELIS_DB_USER${NOCOLOR}"
else
echo -e "${CYAN}deleting openelis patient data ${NOCOLOR}"
psql -U$OPENELIS_DB_USER clinlims < $OPENELIS_SQL_FILE
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo -e "${RED}Failed to delete the openelis patient data${NOCOLOR}"
else
echo -e "${GREEN} Successfully deleted the openelis patient data${NOCOLOR}"
fi
fi
}
if [ "$runOnDocker" -eq 1 ]
then
docker exec -i $OPENELIS_DB_ContainerName psql -U postgres < $OPENELIS_SQL_FILE
else
psql -U postgres clinlims < $OPENELIS_SQL_FILE
fi

download_and_delete_openerp_patient_data(){
if [ -f $CURDIR/$OPENERP_SQL_FILE ]; then
echo -e "${CYAN}deleting the existing file${NOCOLOR}"
rm -rf $CURDIR/$OPENERP_SQL_FILE
fi
echo -e "${CYAN}downloading openerp delete patient data sql file${NOCOLOR}"
wget $GITHUB_URL/$OPENERP_SQL_FILE
if [ -z "$OPENERP_DB_USER" ];
then echo -e "${RED}OPENERP_DB_USER is unset. Please set the ENVIRONMENT VARIABLE OPENERP_DB_USER${NOCOLOR}"
else
echo -e "${CYAN}deleting openerp patient data${NOCOLOR}"
psql -U$OPENERP_DB_USER openerp < $OPENERP_SQL_FILE
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo -e "${RED}Failed to delete the openerp patient data${NOCOLOR}"
else
echo -e "${GREEN} Successfully deleted the openerp patient data${NOCOLOR}"
fi
fi
}

start_all_bahmni_services()
{
echo -e "${CYAN}Starting all bahmni related services${NOCOLOR}"
bahmni -i $INVENTORY_FILE start
download_and_delete_odoo_patient_data(){
if [ "$runOnDocker" -eq 1 ]
then
docker exec -i $ODOO_DB_ContainerName psql -U $ODOO_DB_USER < $ODOO_SQL_FILE
else
psql -U $ODOO_DB_USER odoo< $ODOO_SQL_FILE
fi
}

stop_all_bahmni_services
download_and_delete_crater_patient_data(){
docker exec -i $CRATER_DB_ContainerName mysql -u$CRATER_DB_USERNAME -p$CRATER_DB_PASSWORD crater < $CRATER_SQL_FILE
}
# When running bahmni-lite uncomment download_and_delete_crater_patient_data and Comment download_and_delete_openelis_patient_data and download_and_delete_odoo_patient_data
download_and_delete_openmrs_patient_data
download_and_delete_openelis_patient_data
download_and_delete_openerp_patient_data
start_all_bahmni_services
download_and_delete_odoo_patient_data
download_and_delete_crater_patient_data
21 changes: 21 additions & 0 deletions deletePatientData/deletePatientDataForOdoo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Truncate table "sale_order_line",
"sale_order",
"account_analytic_line",
"account_analytic_tag_sale_order_line_rel",
"account_tax_sale_order_line_rel",
"procurement_order",
"sale_order_line_invoice_rel",
"account_analytic_line_tag_rel",
"stock_move",
"stock_location_route_procurement",
"stock_quant",
"stock_quant_move_rel",
"stock_location_route_move",
"stock_move_operation_link",
"stock_pack_operation_lot",
"stock_return_picking_line",
"stock_scrap";

delete from res_partner where not exists (select ru.partner_id from res_users ru where ru.partner_id = res_partner.id) and id != 1;
delete from markers where feed_uri like '%atomfeed/encounter/recent%' OR feed_uri like '%atomfeed/patient/recent%';
delete from event_records where category = 'product';
64 changes: 0 additions & 64 deletions deletePatientData/deletePatientDataForOpenERP.sql

This file was deleted.

65 changes: 33 additions & 32 deletions deletePatientData/deletePatientDataForOpenElis.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
truncate table result_signature,
referral_result,
referral,
result_inventory,
result,
worksheet_analyte,
note,
report_external_export,
report_external_import,
analysis_qaevent,
analysis_storages,
analysis_users,
analysis,
sample_qaevent,
sample_requester,
sample_human,
sample_newborn,
sample_animal,
sample_environmental,
sample_item,
sample_organization,
sample_projects,
sample,
observation_history,
patient,
patient_identity,
patient_occupation,
person_address,
patient_patient_type,
patient_relations,
organization_contact;
\c clinlims;
SET search_path TO clinlims;
truncate result_signature,
referral_result,
referral,
result_inventory,
result,
worksheet_analyte,
note,
report_external_export,
report_external_import,
analysis_qaevent,
analysis_storages,
analysis_users,
analysis,
sample_qaevent,
sample_requester,
sample_human,
sample_newborn,
sample_animal,
sample_environmental,
sample_item,
sample_organization,
sample_projects,
sample,
observation_history,
patient,
patient_identity,
patient_occupation,
person_address,
patient_patient_type,
patient_relations,
organization_contact;

delete from person where not exists (select p.person_id from provider p where p.person_id = person.id);
delete from markers where feed_uri like '%atomfeed/encounter/recent%' OR feed_uri like '%atomfeed/patient/recent%';
delete from event_records where category = 'patient';

truncate table event_records_offset_marker;
25 changes: 12 additions & 13 deletions deletePatientData/deletePatientDataForOpenMRS.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use openmrs;
set foreign_key_checks=0;

truncate table test_order;
truncate table drug_order;
truncate table note;
truncate table obs_relationship;
truncate table concept_proposal;
truncate table note;
truncate table obs_relationship;
truncate table concept_proposal;
truncate table concept_proposal_tag_map;
truncate table obs;
truncate table orders;
Expand All @@ -16,13 +17,10 @@ truncate table bed_patient_assignment_map;
truncate table encounter_provider;
truncate table episode_encounter;
truncate table order_group;
truncate table encounter;
truncate table appointmentscheduling_appointment;
truncate table appointmentscheduling_appointment_status_history;
truncate table encounter;
truncate table visit_attribute;
truncate table visit;
truncate table patient_identifier;
truncate table appointmentscheduling_appointment_request;
truncate table conditions;
truncate table cohort_member;
truncate table patient_program;
Expand All @@ -35,14 +33,15 @@ truncate table audit_log;
delete from person_address where person_id <> 1;
delete from person_attribute where person_id <> 1;
delete from person_name where not exists
(select u.person_id from users u where person_name.person_id = u.person_id or person_name.person_id = 1)
and not exists (select p.person_id from provider p where person_name.person_id = p.person_id or person_name.person_id = 1);
(select u.person_id from users u where person_name.person_id = u.person_id or person_name.person_id = 1)
and not exists (select p.person_id from provider p where person_name.person_id = p.person_id or person_name.person_id = 1);
delete from person where not exists
(select u.person_id from users u where person.person_id = u.person_id or person.person_id = 1)
and not exists (select p.person_id from provider p where person.person_id = p.person_id or person.person_id = 1);

(select u.person_id from users u where person.person_id = u.person_id or person.person_id = 1)
and not exists (select p.person_id from provider p where person.person_id = p.person_id or person.person_id = 1);
delete from person_address where person_id <> 1;
delete from person_attribute where person_id <> 1;
delete from event_records where category = 'patient' OR category = 'Encounter';
delete from markers where feed_uri like '%feed/patient/recent%' ;
delete from markers where feed_uri like '%feed/patient/recent%' ;

truncate table event_records_offset_marker;

Expand Down