Ejemplo n.º 1
0
    def save(self, send_email=True):
        user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
                                                                    password=self.cleaned_data['password1'],
                                                                    email=self.cleaned_data['email'],
                                                                    site=None,
                                                                    send_email=send_email
                                                                    )
        user.username = user.username.strip().lower()
        user.save()         # remove spaces from username and change all to lowercase
        profile = Profile(user=user)
        profile.save()
        organization = Organization.objects.create( #create organization
            name = self.cleaned_data['organization'],
            trade_name = self.cleaned_data['organization'],
            short_name = slugify(self.cleaned_data['shortname']),
        )
        default_place = Place.objects.create(         #create default place
            label = organization.name,                # use same name as label
            active = True,
            place_type = PlaceType.objects.get(description='Matriz'), # mandatory field
            organization = organization,              # link place to this organization
        )
        default_room = Room.objects.create(
            description = 'Sala 1',
            place = default_place,
            room_type=RoomType.objects.all()[0],
        )

        person = Person.objects.create(name=self.cleaned_data['name'], user=user) #, organization=organization)
        person.organization.add(organization)
        profile.org_active = organization                  #set org as active
        profile.temp = self.cleaned_data['password1']      # temporary field (LDAP)
        profile.person = person
        profile.save()
        
        try:
            admin_role = Group.objects.get(name='administrator')
            Role.objects.create(profile=profile, organization=organization, group=admin_role)
            profile.user.groups.add(admin_role)
        except:
            pass
        try:
            professional_role = Group.objects.get(name='professional')
            Role.objects.create(profile=profile, organization=organization, group=professional_role)
            profile.user.groups.add(professional_role)
        except:
            pass

        careprof = CareProfessional()
        careprof.person = person
        pp = ProfessionalProfile()
        pi = ProfessionalIdentification()
        pp.save()
        pi.save()
        careprof.professionalProfile = pp
        careprof.professionalIdentification = pi
        careprof.save()

        return organization
Ejemplo n.º 2
0
def save_mini_professional(request):
    object = CareProfessional()
    person = Person()
    person.name = request.POST.get('label')
    person.save()
    person.organization.add(Organization.objects.get(pk=request.POST.get('organization')))
    object.person = person
    object.save()

    return HttpResponse("%s" % (object.id))
Ejemplo n.º 3
0
def save_mini_professional(request):
    object = CareProfessional()
    person = Person()
    person.name = request.POST.get('label')
    person.save()
    person.organization.add(
        Organization.objects.get(pk=request.POST.get('organization')))
    object.person = person
    object.save()

    return HttpResponse("%s" % (object.id))
Ejemplo n.º 4
0
def contact_professional_save(request, object_id=None):

    try:
        object = get_object_or_404(CareProfessional, pk=object_id)
        identification = object.professionalIdentification
        person = object.person
    except:
        object = CareProfessional()
        person = Person()

    if object.id and not have_careprofessional_perms_save(request, object):
        return render_to_response('403.html', {
            'object': _("Access Denied"),
        },
                                  context_instance=RequestContext(request))

    if not request.POST.get('name'):
        return HttpResponseRedirect(
            ('/contact/form/professional/' if not object.id else
             ('/contact/form/professional/%s/') % object.id))

    if not object.professionalIdentification:
        if request.POST.get('symbol'):
            identification = ProfessionalIdentification()
            identification.profession = Profession.objects.get(
                id=request.POST.get('service_profession'))
            identification.registerNumber = request.POST.get(
                'professional_subscription')
            identification.save()
            object.professionalIdentification = identification
        else:
            object.professionalIdentification = None

    person.name = request.POST.get('name')
    person.save()

    person.organization.remove()
    person.organization.add(
        Organization.objects.get(pk=request.POST.get('organization')))

    person = extra_data_save(request, person)

    object.comments = request.POST.get('comments')
    object.person = person
    object.save()

    messages.success(request, _('Professional contact saved successfully'))
    return HttpResponseRedirect('/contact/form/professional/%s/' % (object.id))
Ejemplo n.º 5
0
def contact_professional_save(request, object_id=None):

    try:
        object = get_object_or_404(CareProfessional, pk=object_id)
        identification = object.professionalIdentification
        person = object.person
    except:
        object = CareProfessional()
        person = Person()

    if object.id and not have_careprofessional_perms_save(request, object):
        return render_to_response('403.html', {'object': _("Access Denied"), }, context_instance=RequestContext(request))

    if not request.POST.get('name'):
        return HttpResponseRedirect(('/contact/form/professional/' if not object.id else ('/contact/form/professional/%s/') % object.id))

    if not object.professionalIdentification:
        if request.POST.get('symbol'):
            identification = ProfessionalIdentification()
            identification.profession = Profession.objects.get(
                id=request.POST.get('service_profession'))
            identification.registerNumber = request.POST.get(
                'professional_subscription')
            identification.save()
            object.professionalIdentification = identification
        else:
            object.professionalIdentification = None

    person.name = request.POST.get('name')
    person.save()

    person.organization.remove()
    person.organization.add(Organization.objects.get(
        pk=request.POST.get('organization')))

    person = extra_data_save(request, person)

    object.comments = request.POST.get('comments')
    object.person = person
    object.save()

    messages.success(request, _('Professional contact saved successfully'))
    return HttpResponseRedirect('/contact/form/professional/%s/' % (object.id))
Ejemplo n.º 6
0
def save_careprof(request, object_id, save_person, is_student=False):
    """
    This view function returns the informations about CareProfessional 
    @param request: this is a request sent by the browser.
    @type request: a instance of the class C{HttpRequest} created by the framework Django
    @param object: it is the tyoe of CareProfessional that must be filled.
    @type object: an instance of the built-in type C{CareProfessional}.            
    """

    if object_id:
        object = get_object_or_404(CareProfessional, pk=object_id, person__organization=request.user.get_profile().org_active)
    else:
        object = CareProfessional()

    if save_person:
        object.person = person_save(request, get_object_or_None(Person, pk=object.person_id) or Person())

    object.save()

    '''
        remove service before add
        check if service have referral before remove.
        cannot be removed if have referral.
    '''
    # all service that are in list_service cannot be removed because it have referral. Create a error message for service and show to user.
    list_to_remove = []

    # remove service, compare from form and db.
    for x in object.prof_services.all(): # professional
        if not x.id in request.POST.getlist('professional_service'):
            # check referral
            if Referral.objects.charged().filter( professional=object, service=x, status='01'):
                list_to_remove.append(x) # add to msg
            else:
                object.prof_services.remove(x) # remove from professional

    # add new service to professional
    for x in request.POST.getlist('professional_service'):
        object.prof_services.add(x) # no problem to replace


    profile = get_object_or_None(ProfessionalProfile, pk=object.professionalProfile_id) or ProfessionalProfile()
    profile.initialProfessionalActivities = request.POST.get('professional_initialActivitiesDate')
    profile.save()
    object.professionalProfile = profile

    # remove all workplace
    profile.workplace.clear()
    # update workplace
    for x in request.POST.getlist('professional_workplace'):
        profile.workplace.add( Place.objects.get( pk=x, organization=request.user.get_profile().org_active ) )

    if not is_student:

        if request.POST.get('professional_registerNumber') or request.POST.get('professional_area'):
            if not object.professionalIdentification:
                identification = ProfessionalIdentification()
            else:
                identification = object.professionalIdentification

            if request.POST.get('professional_registerNumber'):
                identification.registerNumber = request.POST.get('professional_registerNumber')

            if request.POST.get('professional_area'):
                identification.profession = get_object_or_None(Profession, id=request.POST.get('professional_area'))

            identification.save()
            object.professionalIdentification = identification

    object.save()
    return object, list_to_remove
Ejemplo n.º 7
0
def save_careprof(request, object_id, save_person, is_student=False):
    """
    This view function returns the informations about CareProfessional 
    @param request: this is a request sent by the browser.
    @type request: a instance of the class C{HttpRequest} created by the framework Django
    @param object: it is the tyoe of CareProfessional that must be filled.
    @type object: an instance of the built-in type C{CareProfessional}.            
    """

    if object_id:
        object = get_object_or_404(
            CareProfessional,
            pk=object_id,
            person__organization=request.user.get_profile().org_active)
    else:
        object = CareProfessional()

    if save_person:
        object.person = person_save(
            request,
            get_object_or_None(Person, pk=object.person_id) or Person())

    object.save()
    '''
        remove service before add
        check if service have referral before remove.
        cannot be removed if have referral.
    '''
    # all service that are in list_service cannot be removed because it have referral. Create a error message for service and show to user.
    list_to_remove = []

    # remove service, compare from form and db.
    for x in object.prof_services.all():  # professional
        if not x.id in request.POST.getlist('professional_service'):
            # check referral
            if Referral.objects.charged().filter(professional=object,
                                                 service=x,
                                                 status='01'):
                list_to_remove.append(x)  # add to msg
            else:
                object.prof_services.remove(x)  # remove from professional

    # add new service to professional
    for x in request.POST.getlist('professional_service'):
        object.prof_services.add(x)  # no problem to replace

    profile = get_object_or_None(
        ProfessionalProfile,
        pk=object.professionalProfile_id) or ProfessionalProfile()
    profile.initialProfessionalActivities = request.POST.get(
        'professional_initialActivitiesDate')
    profile.save()
    object.professionalProfile = profile

    # remove all workplace
    profile.workplace.clear()
    # update workplace
    for x in request.POST.getlist('professional_workplace'):
        profile.workplace.add(
            Place.objects.get(
                pk=x, organization=request.user.get_profile().org_active))

    if not is_student:

        if request.POST.get('professional_registerNumber') or request.POST.get(
                'professional_area'):
            if not object.professionalIdentification:
                identification = ProfessionalIdentification()
            else:
                identification = object.professionalIdentification

            if request.POST.get('professional_registerNumber'):
                identification.registerNumber = request.POST.get(
                    'professional_registerNumber')

            if request.POST.get('professional_area'):
                identification.profession = get_object_or_None(
                    Profession, id=request.POST.get('professional_area'))

            identification.save()
            object.professionalIdentification = identification

    object.save()
    return object, list_to_remove
Ejemplo n.º 8
0
def save_careprof(request, object_id, save_person, is_student=False):
    """
    This view function returns the informations about CareProfessional 
    @param request: this is a request sent by the browser.
    @type request: a instance of the class C{HttpRequest} created by the framework Django
    @param object: it is the tyoe of CareProfessional that must be filled.
    @type object: an instance of the built-in type C{CareProfessional}.            
    """
    if object_id:
        object = get_object_or_404(CareProfessional, pk=object_id, person__organization=request.user.get_profile().org_active)
    else:
        object = CareProfessional()

    if save_person:
        object.person = person_save(request, get_object_or_None(Person, pk=object.person_id) or Person())
    object.save()

    #exist_referral="False"
    list_from_form = request.POST.getlist('professional_service')

    # MAKE A LIST WHIT ID SERVICE
    list_db = []
    for y in object.prof_services.filter(organization=request.user.get_profile().org_active):
        list_db.append(y.id)

    # IF LIST_FROM_FORM > 0 THEN ADDED SERVICE 
    if len(list_from_form) > 0:
        for ps_id in list_from_form:
            ps = Service.objects.get(pk=ps_id)
            object.prof_services.add(ps)

    # COMPARES THE LIST_DB AND LIST_FORM, THE RESULT WILL BE SERVICES THAT WILL BE REMOVED
    if len(list_from_form) > 0:
        for x in list_from_form:
            try:
                indice = list_db.remove(x)
            except:
                pass

    ## REMOVE SERVICE 
    #if len(list_db) > 0:
        #for o in list_db:
            #if Referral.objects.charged().filter(professional = object, service = o, status = '01').count() > 0:
                #exist_referral="True"
            #else:
                #object.prof_services.remove(o)

    profile = get_object_or_None(ProfessionalProfile, pk=object.professionalProfile_id) or ProfessionalProfile()
    profile.initialProfessionalActivities = request.POST.get('professional_initialActivitiesDate')
    profile.save()
    object.professionalProfile = profile

    if (len(request.POST.getlist('professional_workplace'))):
        for o in profile.workplace.filter(organization=request.user.get_profile().org_active):
            profile.workplace.remove(o)
        for wplace_id in request.POST.getlist('professional_workplace'):
            profile.workplace.add(Place.objects.get(pk=wplace_id))

    if not is_student:
        if (len(request.POST.getlist('professional_agreement'))):
            profile.agreement.clear()
            for agreemt_id in request.POST.getlist('professional_agreement'):
                profile.agreement.add(Agreement.objects.get(pk=agreemt_id))

        if request.POST.get('professional_registerNumber') or request.POST.get('professional_area'):
            if not object.professionalIdentification:
                identification = ProfessionalIdentification()
            else:
                identification = object.professionalIdentification

            if request.POST.get('professional_registerNumber'):
                identification.registerNumber = request.POST.get('professional_registerNumber')

            if request.POST.get('professional_area'):
                identification.profession = get_object_or_None(Profession, id=request.POST.get('professional_area'))

            identification.save()
            object.professionalIdentification = identification

    object.save()
    return object