コード例 #1
0
ファイル: edit_views.py プロジェクト: FEMR/fEMR-OnChain-Core
def __aux_form_invalid(request, encounter_id, patient, treatment_form,
                       diagnosis_form):
    units = Campaign.objects.get(name=request.user.current_campaign).units
    encounter = PatientEncounter.objects.get(pk=encounter_id)
    form = PatientEncounterForm(instance=encounter, unit=units)
    if units == "i":
        aux_form_imperial(form, encounter)
    suffix = patient.get_suffix_display() if patient.suffix is not None else ""
    return render(
        request,
        "forms/treatment_tab.html",
        {
            "form": form,
            "aux_form": AuxiliaryPatientEncounterForm(instance=encounter),
            "vitals": Vitals.objects.filter(encounter=encounter),
            "treatments": Treatment.objects.filter(encounter=encounter),
            "vitals_form": VitalsForm(unit=units),
            "diagnosis_form": diagnosis_form,
            "treatment_form": treatment_form,
            "page_name":
            f"Edit Encounter for {patient.first_name} {patient.last_name} {suffix}",
            "encounter": encounter,
            "birth_sex": patient.sex_assigned_at_birth,
            "encounter_id": encounter_id,
            "patient_name":
            f"{patient.first_name} {patient.last_name} {suffix}",
            "units": units,
            "patient": patient,
        },
    )
コード例 #2
0
ファイル: edit_views.py プロジェクト: FEMR/fEMR-OnChain-Core
def __aux_form_view_post(request, encounter_id, patient, treatment_form,
                         diagnosis_form):
    encounter = get_object_or_404(PatientEncounter, pk=encounter_id)
    aux_form = AuxiliaryPatientEncounterForm(request.POST)
    if aux_form.is_valid():
        return_response = __aux_form_is_valid(request, encounter,
                                              treatment_form)
    else:
        return_response = __aux_form_invalid(
            request,
            encounter_id,
            patient,
            treatment_form,
            diagnosis_form,
        )
    return return_response
コード例 #3
0
ファイル: edit_views.py プロジェクト: FEMR/fEMR-OnChain-Core
def __encounter_edit_form_get(request, patient_id, encounter_id):
    encounter = get_object_or_404(PatientEncounter, pk=encounter_id)
    patient = get_object_or_404(Patient, pk=patient_id)
    units = Campaign.objects.get(name=request.user.current_campaign).units
    vitals_form = VitalsForm(unit=units)
    DatabaseChangeLog.objects.create(
        action="View",
        model="Patient",
        instance=str(encounter),
        ip=get_client_ip(request),
        username=request.user.username,
        campaign=Campaign.objects.get(name=request.user.current_campaign),
    )
    form = PatientEncounterForm(instance=encounter, unit=units)
    if not encounter.active:
        for field in form:
            try:
                field.widget.attrs["readonly"] = True
            except KeyError:
                pass
            except AttributeError:
                pass
        for field in vitals_form:
            try:
                field.widget.attrs["readonly"] = True
            except KeyError:
                pass
            except AttributeError:
                pass
    if units == "i":
        encounter_update_form_initial_imperial(form, encounter)
    form.initial["timestamp"] = encounter.timestamp
    encounter_active = encounter.active
    suffix = patient.get_suffix_display() if patient.suffix is not None else ""
    return render(
        request,
        "forms/edit_encounter.html",
        {
            "active": encounter_active,
            "aux_form": AuxiliaryPatientEncounterForm(),
            "form": form,
            "vitals": Vitals.objects.filter(encounter=encounter),
            "treatments": Treatment.objects.filter(encounter=encounter),
            "vitals_form": vitals_form,
            "page_name":
            f"Edit Encounter for {patient.first_name} {patient.last_name} {suffix}",
            "encounter": encounter,
            "birth_sex": patient.sex_assigned_at_birth,
            "encounter_id": encounter_id,
            "patient_name":
            f"{patient.first_name} {patient.last_name} {suffix}",
            "units": units,
            "patient": patient,
        },
    )
コード例 #4
0
ファイル: edit_views.py プロジェクト: FEMR/fEMR-OnChain-Core
def __new_diagnosis_view_body(request, patient_id, encounter_id):
    campaign = Campaign.objects.get(name=request.user.current_campaign)
    encounter = get_object_or_404(PatientEncounter, pk=encounter_id)
    patient = get_object_or_404(Patient, pk=patient_id)
    treatment_form = TreatmentForm()
    treatment_form.fields[
        "medication"].queryset = campaign.inventory.entries.all()
    querysets = PatientDiagnosis.objects.filter(encounter=encounter)
    diagnosis_set = PatientDiagnosis.objects.filter(encounter=encounter)
    if len(diagnosis_set) > 0:
        diagnosis_form = PatientDiagnosisForm(instance=diagnosis_set[0])
    else:
        diagnosis_form = PatientDiagnosisForm()
    if request.method == "POST":
        diagnosis_form = new_diagnosis_view_post(request, encounter,
                                                 diagnosis_set)
    form = PatientEncounterForm(instance=encounter, unit=campaign.units)
    if campaign.units == "i":
        new_diagnosis_imperial(form, encounter)
    suffix = patient.get_suffix_display() if patient.suffix is not None else ""
    if len(querysets) > 0:
        item = querysets[0].diagnosis.all()
        for query_item in querysets:
            item.union(query_item.diagnosis.all())
        treatment_form.fields["diagnosis"].queryset = item
        treatment_active = True
    else:
        treatment_form.fields["diagnosis"].queryset = Diagnosis.objects.none()
        treatment_active = False
    return render(
        request,
        "forms/treatment_tab.html",
        {
            "active": encounter.active,
            "aux_form": AuxiliaryPatientEncounterForm(instance=encounter),
            "form": form,
            "vitals": Vitals.objects.filter(encounter=encounter),
            "treatments": Treatment.objects.filter(encounter=encounter),
            "vitals_form": VitalsForm(unit=campaign.units),
            "diagnosis_form": diagnosis_form,
            "treatment_form": treatment_form,
            "page_name":
            f"Edit Encounter for {patient.first_name} {patient.last_name} {suffix}",
            "encounter": encounter,
            "birth_sex": patient.sex_assigned_at_birth,
            "encounter_id": encounter_id,
            "patient_name":
            f"{patient.first_name} {patient.last_name} {suffix}",
            "units": campaign.units,
            "patient": patient,
            "treatment_active": treatment_active,
        },
    )
コード例 #5
0
ファイル: edit_views.py プロジェクト: FEMR/fEMR-OnChain-Core
def __encounter_edit_form_post(request, patient_id, encounter_id):
    encounter = get_object_or_404(PatientEncounter, pk=encounter_id)
    patient = get_object_or_404(Patient, pk=patient_id)
    units = Campaign.objects.get(name=request.user.current_campaign).units
    photos = encounter.photos.all().iterator()
    treatments = Treatment.objects.filter(encounter=encounter)
    form = PatientEncounterForm(request.POST or None,
                                instance=encounter,
                                unit=units)
    if form.is_valid():
        encounter = form.save(commit=False)
        form.save_m2m()
        encounter.patient = patient
        encounter.active = True
        encounter.photos.set(photos)
        encounter.save()
        DatabaseChangeLog.objects.create(
            action="Edit",
            model="PatientEncounter",
            instance=str(encounter),
            ip=get_client_ip(request),
            username=request.user.username,
            campaign=Campaign.objects.get(name=request.user.current_campaign),
        )
        if os.environ.get("QLDB_ENABLED") == "TRUE":
            encounter_data = PatientEncounterSerializer(encounter).data
            update_patient_encounter(encounter_data)
        if "submit_encounter" in request.POST:
            return_response = render(
                request,
                "data/encounter_submitted.html",
                {
                    "patient_id": patient_id,
                    "encounter_id": encounter_id
                },
            )
        elif "submit_refer" in request.POST:
            kwargs = {"patient_id": patient_id}
            return_response = redirect("main:referral_form_view", **kwargs)
        else:
            return_response = render(
                request,
                "data/encounter_submitted.html",
                {
                    "patient_id": patient_id,
                    "encounter_id": encounter_id
                },
            )
    else:
        form.initial["timestamp"] = encounter.timestamp
        encounter_active = encounter.active
        suffix = patient.get_suffix_display(
        ) if patient.suffix is not None else ""
        return_response = render(
            request,
            "forms/edit_encounter.html",
            {
                "active": encounter_active,
                "aux_form": AuxiliaryPatientEncounterForm(),
                "form": form,
                "vitals": Vitals.objects.filter(encounter=encounter),
                "treatments": treatments,
                "vitals_form": VitalsForm(unit=units),
                "page_name":
                f"Edit Encounter for {patient.first_name} {patient.last_name} {suffix}",
                "encounter": encounter,
                "birth_sex": patient.sex_assigned_at_birth,
                "encounter_id": encounter_id,
                "patient_name":
                f"{patient.first_name} {patient.last_name} {suffix}",
                "units": units,
                "patient": patient,
            },
        )
    return return_response