def reset_all_clinics(): # delete all Clinics user_clinics.delete().where( user_clinics.columns.clinic_id.in_(Clinic.all())) with transaction.manager: for cs in Clinic.all(): DBSession.delete(cs)
def manage_clinics(self): user = self.request.user if self.request.has_permission(perms.SUPER_USER, self.request.context): clinics = Clinic.all() else: clinics = user.location.clinics period = get_period_from_request(self.request) return {'clinics': clinics, 'period': period}
def national_report(self, period): clinics = Clinic.all() clinics = [ c for c in clinics if c.has_clinic_submissions_for_period(period.form_xpath) ] national_report = ClinicReport.get_clinic_reports(clinics, period) return national_report
def import_health_data(): file_name = os.path.relpath('whoahqa/data/clinics.csv') with open(file_name, 'rU') as source: rdr = UnicodeDictReader(source) existing_states = [ normalizeString(state.name) for state in State.all() ] existing_municipalities = [ normalizeString(municipality.name) for municipality in Municipality.all() ] existing_clinics = [clinic.code for clinic in Clinic.all()] with transaction.manager: for row in rdr: state = None municipality = None normalized_state = normalizeString(row['state']) normalized_municipality = normalizeString(row['municipality']) if normalized_state not in existing_states: existing_states.append(normalized_state) state = State(name=normalized_state) DBSession.add(state) if normalized_municipality not in existing_municipalities: existing_municipalities.append(normalized_municipality) if state is None: state = State.get(State.name == normalized_state) municipality = Municipality(name=normalized_municipality, parent=state) DBSession.add(municipality) if row['CNES'] not in existing_clinics: # import ipdb; ipdb.set_trace() existing_clinics.append(row['CNES']) if municipality is None: municipality = Municipality.get( Municipality.name == normalized_municipality) clinic = Clinic(name=row['facility_name'], code=row['CNES'], municipality=municipality) DBSession.add(clinic)
def update(self, values): group_name = values['group'] # check if new group is the same as previous group # add new location selected to location table # if group is clinic manager, add clinics selected to clinics list if self.user.group is None or self.user.group.name != group_name: group_criteria = Group.name == group_name group_params = {'name': group_name} group = Group.get_or_create(group_criteria, **group_params) self.user.group = group if group_name == groups.SUPER_USER or\ group_name == groups.NATIONAL_OFFICIAL: # remove any location/clinic references if self.user.location: delete_user_locations(self.user, self.user.location) if self.user.clinics: delete_user_clinics([c.id for c in self.user.clinics]) elif group_name == groups.CLINIC_MANAGER: # Remove existing location mapping if self.user.location: delete_user_locations(self.user, self.user.location) from whoahqa.models import Clinic clinic_id_list = values['clinics'] clinics = Clinic.all(Clinic.id.in_(clinic_id_list)) self.user.clinics = clinics # add clinics to user else: # Remove existing clinic mapping if self.user.clinics: delete_user_clinics([c.id for c in self.user.clinics]) location_id = values.get(LOCATION_MAP[group_name], '') if location_id != '': self.user.location = Location.get(Location.id == location_id) self.save()
def test_all_returns_multiple_matches_filtered_by_criterion(self): self.setup_test_data() clinics = Clinic.all(Clinic.id.in_([1, 2])) self.assertEqual(len(clinics), 2)
def clinic_selection_widget(node, kw): return SelectWidget(values=[(c.id, key_to_label(c.name + " - " + c.code)) for c in Clinic.all()], multiple=True)