Skip to content

Instantly share code, notes, and snippets.

View petmongrels's full-sized avatar

Vivek Singh petmongrels

View GitHub Profile
@petmongrels
petmongrels / pedagogy-of-the-oppressed-1
Created May 31, 2014 17:22
Pedagogy of the oppressed (slightly edited)
Because it is a distortion of being more fully human, sooner or later being less human leads the oppressed to struggle against those who made them so. In order for this struggle to have meaning, the oppressed must not, in seeking to regain their humanity, become in turn oppressors of the oppressors, but rather restorers of the humanity of both.
This, then, is the great humanistic and historical task of the oppressed: to liberate themselves and their oppressors as well. The oppressors, who oppress, exploit, and rape by virtue of their power, cannot find in this power the strength to liberate either the oppressed or themselves. Only power that springs from the weakness of the oppressed will be sufficiently strong to free both. Any attempt to "soften" the power of the oppressor in deference to the weakness of the oppressed almost always manifests itself in the form of false generosity; indeed, the attempt never goes beyond this. In order to have the continued opportunity to express their "generosity," the oppre
@petmongrels
petmongrels / gist:f3f367b1b9c4b1959a998af6769a0c91
Created January 6, 2021 14:11
Further optimising Vinay's approach of using concept map
Apparently STABLE and IMMUTABLE only if Postgres decides that calling the function is more expensive than using the cache. See this link (https://stackoverflow.com/questions/8529690/why-is-postgresql-calling-my-stable-immutable-function-multiple-times), where the “may” keyword is mentioned. We have to test this further and what determines postgres’ decision.
In the solution where we are passing the concept map, the size of the map matters. If the size is too big it would take very long for the lookup to resolve. So in the concept map creation if you provide the uuid, the response is way faster - 2.5 seconds compared to 20 seconds.
The key change in is concepts with clause, right below. We should follow this pattern, to keep the size of map small and faster lookup.
with concepts AS (
SELECT hstore((array_agg(c2.uuid))::text[], (array_agg(c2.name))::text[]) AS map
FROM concept
join concept_answer a on concept.id = a.concept_id
@petmongrels
petmongrels / gist:8ec5e82bfcb00c8c785e4876ad4f74e9
Created January 11, 2021 11:48
Multiple concept maps for a form
WITH concepts_24 AS (
SELECT hstore((array_agg(c2.uuid))::text[], (array_agg(c2.name))::text[]) AS map
FROM ((concept
JOIN concept_answer a ON ((concept.id = a.concept_id)))
JOIN concept c2 ON ((a.answer_concept_id = c2.id)))
WHERE ((concept.uuid)::text = ANY ((ARRAY['1a260251-1fcd-4f6c-b2e7-a0eb534d2cc2'::character varying, 'f1eb8ffc-f6b0-4089-9713-041041ea2c37'::character varying, '031ce79b-dc20-4137-b9e1-b5a7a7b97042'::character varying, 'd0f257d4-87a2-426d-b418-9403a23302c0'::character varying, '263938d1-822d-4f1e-9361-84032b2c9155'::character varying, '45beb4d7-7074-433c-8786-f9d6a19a5b34'::character varying])::text[]))
), concepts_23 AS (
SELECT hstore((array_agg(c2.uuid))::text[], (array_agg(c2.name))::text[]) AS map
FROM ((concept
JOIN concept_answer a ON ((concept.id = a.concept_id)))
@petmongrels
petmongrels / gist:211cd482ad908265a0fd80c9a4f2a9c6
Last active February 8, 2021 05:48
Sync performance analysis
Increasing device memory from 2GB to 3 GB has no effect on the performance.
The time taken for a page can be divided into following sections.
1. Database query
2. Server converting the jdbc result-set to JSON
3. Client receiving the data from server
4. Client deserialising the JSON on getting the response
5. Client saving the data onto the offline database
@petmongrels
petmongrels / openmrs-production-dump-for-testing.sh
Created July 20, 2021 09:03
Taking production database dump can slow down production server, take long time to transfer, and one needs to anonymise data. This all is quite cumbersome, if all I want is one patient record which I want to test something against. The following shell script will allow you to take the dump of with only one patient record.
mysqldump -u root -ppassword --no-data openmrs > /tmp/schema.sql
mysqldump -u root -ppassword openmrs address_hierarchy_address_to_entry_map address_hierarchy_entry address_hierarchy_level allergy allergy_reaction appframework_component_state appframework_user_app appointment_service appointment_service_type appointment_service_weekly_availability appointment_speciality appointmentscheduling_appointment appointmentscheduling_appointment_block appointmentscheduling_appointment_request appointmentscheduling_appointment_status_history appointmentscheduling_appointment_type appointmentscheduling_block_type_map appointmentscheduling_time_slot aqs_task bahmni_config bahmni_config_version bed bed_location_map bed_location_map_removal_list bed_tag bed_tag_map bed_type calculation_registration care_setting chunking_history clob_datatype_storage cohort cohort_member concept concept_answer concept_attribute concept_attribute_type concept_class concept_complex concept_datatype concept_description concept_map_type concept
@petmongrels
petmongrels / Current_Query.sql
Last active June 23, 2022 09:43
Longitudinal export with db cursor
select individual0_.id as id1_36_, individual0_.is_voided as is_voide2_36_, individual0_.uuid as uuid3_36_, individual0_.created_by_id as created19_36_, individual0_.created_date_time as created_4_36_, individual0_.last_modified_by_id as last_mo20_36_, individual0_.last_modified_date_time as last_mod5_36_, individual0_.version as version6_36_, individual0_.organisation_id as organisa7_36_, individual0_.sync_concept_1_value as sync_con8_36_, individual0_.sync_concept_2_value as sync_con9_36_, individual0_.address_id as address21_36_, individual0_.date_of_birth as date_of10_36_, individual0_.date_of_birth_verified as date_of11_36_, individual0_.first_name as first_n12_36_, individual0_.gender_id as gender_22_36_, individual0_.last_name as last_na13_36_, individual0_.legacy_id as legacy_14_36_, individual0_.observations as observa15_36_, individual0_.profile_picture as profile16_36_, individual0_.registration_date as registr17_36_, individual0_.registration_location as registr18_36_, individual0_.subject_type_id
@petmongrels
petmongrels / gist:d9e7cd0c81394a7c114542858f67906a
Last active November 17, 2022 09:00
React Native Upgrade
Merging
-------
- Remove REACT_NATIVE_VERSION and configuration.all from android/build.gradle and keep the solution is newer version of RN
- There are patches in master which should be applied only if it is required. remaining patches should be removed
More notes
----------
- ListViewHelper
- spread is broken in realm and spread cannot be used on model classes
- Radio/Checkbox value cannot be array as native-base doesn't support it correctly (it gets confused)
DEBUG [6:29:08:633] [SelectFormElement::AC][Debug] Dispatching action: "EA.TOGGLE_SINGLESELECT_ANSWER"
DEBUG [6:29:08:645] [RuleService][Debug] Getting Rules of Type ViewFilter for Form - Observation Encounter ed2c239a-00ca-439c-8f2b-76543fdc55cf
DEBUG [6:29:08:685] [SelectFormElement::AC][Debug] Dispatched action completed: "EA.TOGGLE_SINGLESELECT_ANSWER"
DEBUG [6:29:08:691] [SyncComponent][Debug] SHOULD UPDATE
DEBUG [6:29:08:721] [ProgressBarView][Debug] SHOULD UPDATE
DEBUG [6:29:08:727] [IndividualEncounterView][Debug] render with IndividualUUID=undefined and EncounterTypeUUID=7664eab2-446e-4fc8-ac52-a77c4306893e
DEBUG [6:29:08:738] [AppHeader][Debug] SHOULD UPDATE
DEBUG [6:29:08:744] [PreviousEncounterPullDownView][Debug] SHOULD UPDATE
DEBUG [6:29:08:744] [PreviousEncounterPullDownView][Debug] render
DEBUG [6:29:08:745] [IndividualProfile][Debug] SHOULD UPDATE
-- create groups
begin transaction;
insert into groups (uuid, name, version, organisation_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time)
(select uuid_generate_v4(), 'Administrators', 1, id, 1, 1, current_timestamp, current_timestamp from organisation where id <> 1 and organisation.is_voided = false); -- 193
-- Without entity specific fields
insert into group_privilege (uuid, group_id, privilege_id, subject_type_id, program_id, program_encounter_type_id, encounter_type_id, checklist_detail_id, version, organisation_id, created_by_id, last_modified_by_id, created_date_time, last_modified_date_time)
select uuid_generate_v4(), groups.id, privilege.id, null, null, null, null, null, 1, groups.organisation_id, 1, 1, current_timestamp, current_timestamp
from privilege join groups on groups.name = 'Administrators'
where privilege.entity_type in ('Report', 'NonTransaction', 'Task'); -- 29*193
@petmongrels
petmongrels / gist:58d51d1192dc9b92b61b91ea2876f492
Created September 4, 2023 15:33
Open files in react native stack trace from emulator
FILE="`echo $1 | cut -d':' -f 1`"
LINE_NUMBER="`echo $1 | cut -d':' -f 2`"
open -na "IntelliJ IDEA.app" --args --line $LINE_NUMBER $FILE
## Also set REACT_EDITOR env variable to this file
## if you call this file idea then
## export REACT_EDITOR=idea