Exemplo n.º 1
0
def create_patient():
  '''
  Creates a new patient
  '''
  form = CreatePatientForm()

  if request.method == 'POST':
    if form.validate_on_submit:
      patient = Patient.query.filter_by(email = form.email.data).first()
      if patient is None:
        patient = Patient(
          firstname = form.firstname.data,
          lastname = form.lastname.data,
          dob = form.dob.data,
          email = form.email.data,
          phone_no = form.phone_no.data,
          id_no = form.id_no.data,
          nhif_no = form.nhif_no.data,
          ward_id = form.ward_id.data.id
        )
        patient.save()
        flash('Successfully created a new patient')
        return redirect(url_for('admin.patients'))
      else:
        flash('Patient exists')
  return render_template('admin/create-patient.html', title='Patients', form=form)
Exemplo n.º 2
0
def create():
  '''
  create a new patient
  '''

  form = CreatePatient()
  if form.validate_on_submit():
    if Patient.query.filter_by(email=form.email.data).first() is None:
      new_patient = Patient(firstname=form.firstname.data, lastname=form.lastname.data, age=form.age.data, phone_no=form.phone_no.data, email=form.email.data, id_no=form.id_no.data, nhif_no=form.nhif_no.data, ward_id=form.ward.data)
      new_patient.save()
      flash('Successfully created a new patient')
    flash('Error, patient already exists')

  return render_template('patient/create.html', title="Patient", form=form)
Exemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     form = SignUpForm(request.POST)
     if form.is_valid():
         user = User()
         user.password = make_password(form.cleaned_data['password'])
         user.username = form.cleaned_data['username']
         user.first_name = form.cleaned_data['first_name']
         user.last_name = form.cleaned_data['last_name']
         user.email = form.cleaned_data['email']
         user.save()
         patient = Patient(user=user)
         patient.save()
         return HttpResponseRedirect(reverse('app:login'))
     else:
         return render(request, 'app/patient/patient_signup.haml',
                       {'form': form})
Exemplo n.º 4
0
def show_positive_cases(request):
    if request.method == 'GET':
        msg = None
        if request.GET.get('msg') == '1':
            msg = 'Patient Created Successfully'
        elif request.GET.get('msg') == '2':
            msg = 'Patient Deleted Successfully'
        organization = Organization.objects.get(user=request.user)
        positive_cases = Patient.objects.filter(creator=request.user)
        c = {
            'organization': organization,
            'positive_cases': positive_cases,
            'msg': msg,
            'active_tab': 'positive_cases'
        }
        return render(request, 'backend/positive_cases.html', c)
    elif request.method == 'POST':
        if request.POST.get('new_case'):
            full_name = request.POST.get('full_name', None)
            covid_id = request.POST.get('covid_id', None)
            if len(covid_id.strip()) < 1:
                covid_id = generate_covid_id()
            else:
                covid_id = 'COVID-' + covid_id
            nationality = request.POST.get('nationality').capitalize()
            state = request.POST.get('state')
            creator = request.user
            patient = Patient(full_name=full_name,
                              covid_id=covid_id,
                              nationality=nationality,
                              state=state,
                              creator=creator)
            patient.save()
            return HttpResponseRedirect('/positive-cases?msg=1')
        elif request.POST.get('delete_case'):
            patient = Patient.objects.get(
                pk=int(request.POST.get('delete_case')))
            patient.delete()
            return HttpResponseRedirect('/positive-cases?msg=2')
Exemplo n.º 5
0
def patients_view(request):
    if request.method == 'GET':
        patients = Patient.objects.filter(creator=request.user)
        serialized = PatientSerializer(patients, many=True)
        return Response(success_msg("Retrieved patients successfully",
                                    serialized.data),
                        status=status.HTTP_200_OK)
    elif request.method == 'POST':
        full_name = request.data.get('full_name', None)
        covid_id = request.data.get('covid_id', generate_covid_id())
        nationality = request.data.get('nationality')
        state = request.data.get('state')
        creator = request.user
        patient = Patient(full_name=full_name,
                          covid_id=covid_id,
                          nationality=nationality,
                          state=state,
                          creator=creator)
        patient.save()
        serialized = PatientSerializer(patient)
        return Response(success_msg("Patient created successfully",
                                    serialized.data),
                        status=status.HTTP_201_CREATED)