Beispiel #1
0
def edit(request, id=0):
    patient = get_object_or_404(Patient, pk=id)
    if request.method == 'GET':
        form = AddPatientForm(instance=patient)
    else:
        form = AddPatientForm(request.POST, instance=patient)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('list_patients'))
    return render(request, 'edit_patient.html', {'form': form})
Beispiel #2
0
def edit(request, id=0):
    patient = get_object_or_404(Patient, pk=id)
    if request.method == 'GET':
        form = AddPatientForm(instance=patient)
    else:
        form = AddPatientForm(request.POST, instance=patient)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('list_patients'))
    return render(request, 'edit_patient.html', {'form':form})
Beispiel #3
0
def add(request, bid):
    if request.method not in ['GET', 'POST']:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])

    if request.method == 'GET':
        form = AddPatientForm()
    else:
        form = AddPatientForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('list_patients'))
    return render(request, 'add_patient.html', {'form': form})
Beispiel #4
0
def add(request, bid):
    if request.method not in ['GET', 'POST']:
        return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
    
    if request.method == 'GET':
        form = AddPatientForm()
    else:
        form = AddPatientForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('list_patients'))
    return render(request, 'add_patient.html', {'form':form})
Beispiel #5
0
def patientEdit(request, nricvalue=None):
    otherVars = {
        'pageType': 'logon',
        'UserInfo': request.user.first_name,
        'edit': 'Y',
        'nric': nricvalue
    }
    patientObj = get_or_none(Patient, nric=nricvalue)
    if request.method == 'POST':
        addPatientForm = AddPatientForm(request.POST)
        if addPatientForm.is_valid():
            patientObj.nric = request.POST['nric']
            patientObj.full_name = request.POST['full_name']
            patientObj.contact_num = request.POST['contact_num']
            patientObj.gender = request.POST['gender']
            patientObj.dob = request.POST['dob']
            patientObj.address = request.POST['address']
            patientObj.postalcode = request.POST['postalcode']
            patientObj.nok = request.POST['nok']
            patientObj.age = date.today().year - int(
                str(patientObj.dob).split('-')[0])
            patientObj.email = request.POST['email']
            patientObj.allergy = request.POST['allergy']
            patientObj.save()
            return HttpResponseRedirect(reverse('patientView'))
    else:
        addPatientForm = AddPatientForm(
            initial={
                'nric': patientObj.nric,
                'full_name': patientObj.full_name,
                'contact_num': patientObj.contact_num,
                'gender': patientObj.gender,
                'dob': patientObj.dob,
                'address': patientObj.address,
                'postalcode': patientObj.postalcode,
                'nok': patientObj.nok,
                'email': patientObj.email,
                'allergy': patientObj.allergy,
            })
        # For first header group
    addPatientForm.fields["nric"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["nric"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["full_name"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["full_name"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["contact_num"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["contact_num"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["gender"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["gender"].widget.attrs['wsize'] = '300'

    # For first header group
    addPatientForm.fields["dob"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["dob"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["address"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["address"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["postalcode"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["postalcode"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["email"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["email"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["allergy"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["allergy"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["nok"].widget.attrs['hgrp'] = '1'
    addPatientForm.fields["nok"].widget.attrs['wsize'] = '300'

    hgrps = (
        {
            'name': 'Patient Information',
            'lblwidth': '160'
        },
        {
            'name': 'Next-of-Kin Information',
            'lblwidth': '160'
        },
    )

    numOfRecords = Patient_Record.objects.filter(nric=nricvalue).count()
    caseObject = Patient_Record.objects.filter(
        nric=nricvalue).order_by('-record_create_datetime')[:10]
    caseList = []
    for caseObj in caseObject:
        caseList.append([
            caseObj.id,
            caseObj.symptoms,
            caseObj.diagnosis,
            str(caseObj.record_create_datetime),
        ])
    tableInfo = {
        'caseList': json.dumps(caseList),
        'numOfRecords': numOfRecords
    }

    if len(caseList) > 0:
        tableInfo['recordStart'] = 1
        tableInfo['recordEnd'] = len(caseList)
    if numOfRecords > 10:
        tableInfo['nextEnabled'] = 'Y'
    # Message to display when table has no records
    tabEmptyMsg = 'Patient has no previous medical case to show'
    return render(
        request, 'main/patientchng.html', {
            'otherVars': otherVars,
            'hgrps': hgrps,
            'addPatientForm': addPatientForm,
            'tableInfo': tableInfo,
            'tabEmptyMsg': tabEmptyMsg,
        })
Beispiel #6
0
def patientAdd(request):
    otherVars = {'pageType': 'logon', 'UserInfo': request.user.first_name}

    # if request method is post
    if request.method == 'POST':
        addPatientForm = AddPatientForm(request.POST)

        # input validation for add user and user profile form
        if addPatientForm.is_valid():
            # save the user and user profile object into database
            patientIns = Patient()
            patientIns.nric = request.POST['nric']
            patientIns.full_name = request.POST['full_name']
            patientIns.contact_num = request.POST['contact_num']
            patientIns.gender = request.POST['gender']
            patientIns.dob = request.POST['dob']
            patientIns.address = request.POST['address']
            patientIns.postalcode = request.POST['postalcode']
            patientIns.nok = request.POST['nok']
            patientIns.age = date.today().year - int(
                str(patientIns.dob).split('-')[0])
            patientIns.email = request.POST['email']
            patientIns.allergy = request.POST['allergy']
            patientIns.visit_time = time()
            patientIns.save()
            return HttpResponseRedirect(reverse('patientView'))
    else:
        addPatientForm = AddPatientForm()

    # Define header groups
    hgrps = (
        {
            'name': 'Patient Information',
            'lblwidth': '160'
        },
        {
            'name': 'Next-of-Kin Information',
            'lblwidth': '160'
        },
    )
    # For first header group
    addPatientForm.fields["nric"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["nric"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["full_name"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["full_name"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["contact_num"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["contact_num"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["gender"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["gender"].widget.attrs['wsize'] = '120'

    # # For first header group
    addPatientForm.fields["dob"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["dob"].widget.attrs['wsize'] = '150'

    addPatientForm.fields["address"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["address"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["postalcode"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["postalcode"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["email"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["email"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["allergy"].widget.attrs['hgrp'] = '0'
    addPatientForm.fields["allergy"].widget.attrs['wsize'] = '300'

    addPatientForm.fields["nok"].widget.attrs['hgrp'] = '1'
    addPatientForm.fields["nok"].widget.attrs['wsize'] = '300'

    return render(request, 'main/patientchng.html', {
        'otherVars': otherVars,
        'addPatientForm': addPatientForm,
        'hgrps': hgrps
    })