【发布时间】:2018-08-12 22:30:51
【问题描述】:
我有一个 PatientConsultationView,其中有一个 createview 类创建,一个 AllConsultationView 列出所有咨询。我想将咨询 ID 传递给 PatientObservationView 并使用它来填充 PatientObservationForm 或者,只需将其保存在 PatientObservation 模型中,最终用户无需手动输入 ID,因为它可以从 AllConsultationView 获取
views.py
class PatientConsultationView(CreateView):
model = PatientConsultation
template_name = 'patient/patient_consultation_add.html'
form_class = PatientConsultationForm
context_object_name = 'Patient_Consultation'
success_url = reverse_lazy('patient_list')
class AllConsultationView(ListView):
model = PatientConsultation
template_name = 'patient/all_consultation.html'
context_object_name = 'All_Patient_Consultation'
def get_consult_id(self):
return PatientConsultation.objects.filter(consultation_id=self)
class PatientObservationView(CreateView):
model = PatientObservation
template_name = 'patient/patient_observation_add.html'
form_class = PatientObservationForm
context_object_name = 'Patient_Observation'
success_url = reverse_lazy('patient_list')
forms.py
class PatientConsultationForm(forms.ModelForm):
class Meta:
model = PatientConsultation
fields = ('patient_id', 'weight', 'temperature', 'blood_pressure', 'pulse', 'oxygen_saturation',
'body_mass_index', 'status',)
widgets = {
'patient_id': forms.Select(attrs={'class': 'form-control input-height', 'placeholder': 'Patient ID'}),
'weight': forms.TextInput(attrs={'class': 'form-control input-height', 'placeholder': 'Patient Weight'}),
'temperature': forms.TextInput(attrs={'class': 'form-control input-height', 'placeholder': 'Patient Temperature'}),
'blood_pressure': forms.TextInput(attrs={'class': 'form-control input-height', 'placeholder': 'Patient Blood Pressure'}),
'pulse': forms.TextInput(attrs={'class': 'form-control input-height', 'placeholder': 'Patient Pulse'}),
'oxygen_saturation': forms.TextInput(attrs={'class': 'form-control input-height ', 'placeholder': 'Patient Oxygen Saturation'}),
'body_mass_index': forms.TextInput(attrs={'class': 'form-control input-height', 'placeholder': 'Patient Body Mass Index'}),
'status': forms.Select(attrs={'class': 'form-control input-height', 'placeholder': 'Patient Status',}),
}
class PatientObservationForm(forms.ModelForm):
class Meta:
model = PatientObservation
fields = {'consultation_id','note_to_laboratories','note_to_pharmacist','note_to_physiotherapist',
'note_to_radiologist','medical_advice','medical_report','referral_note'}
widgets = {
'consultation_id': forms.TextInput(attrs={'class': 'form-control input-height', 'placeholder': 'Patient ID'}),
'note_to_laboratories': RichTextFormField(),
'note_to_pharmacist': RichTextFormField(),
'note_to_physiotherapist': RichTextFormField(),
'note_to_radiologist': RichTextFormField(),
'medical_advice': RichTextFormField(),
'medical_report': RichTextFormField(),
'referral_note': RichTextFormField(),
模型.py
class PatientConsultation(models.Model):
"""
Model representing Observation records made by nurses
"""
PATIENT_CONSULTATION_STATUS = (
('1', 'Consulting'),
('0', 'Done')
)
consultation_id = models.AutoField(primary_key=True, editable=False)
patient_id = models.ForeignKey(PatientProfile)
weight = models.CharField(max_length=5)
temperature = models.CharField(max_length=5)
blood_pressure = models.CharField(max_length=5)
pulse = models.CharField(max_length=50)
oxygen_saturation = models.CharField(max_length=50)
body_mass_index = models.CharField(max_length=50)
status = models.CharField(max_length=50, choices=PATIENT_CONSULTATION_STATUS, default='1')
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""
String for representing the model object (in Admin)
"""
return str(self.consultation_id)
class PatientObservation(models.Model):
"""
Model representing doctors report of a particular episode
"""
consultation_id = models.ForeignKey(PatientConsultation)
note_to_pharmacist = RichTextField(blank=True, null=True)
note_to_laboratories = RichTextField(blank=True, null=True)
note_to_physiotherapist = RichTextField(blank=True, null=True)
note_to_radiologist = RichTextField(blank=True, null=True)
referral_note = RichTextField(blank=True, null=True)
medical_report = RichTextField(blank=True, null=True)
medical_advice = RichTextField(blank=True, null=True)
def __str__(self):
"""
String for representing the model object (in Admin)
"""
return self.consultation_id
我的 PatientConsultationAdd.html 模板 formTag
<form method="POST" class="form-horizontal" id="submit_form" action="#" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-wizard">
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-3" for="">Select Consultation ID
<span class="required"> * </span> </label>
<div class="col-md-6">
{{ form.consultation_id }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Note To Laboratories
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.note_to_laboratories }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Note To Pharmacist
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.note_to_pharmacist }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Note To Physiotherapist
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.note_to_physiotherapist }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Note To Radiologist
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.note_to_radiologist }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Medical Advice
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.medical_advice }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Medical Report
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.medical_report }}
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="">Referral Note
<span class="required"> * </span></label>
<div class="col-md-6">
{{ form.referral_note }}
</div>
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>
</form>
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^patient/$', views.PatientList.as_view(), name='patient_list'),
url(r'^patient/new/$', views.PatientCreate.as_view(), name='patient_new'),
url(r'^patient/detail/(?P<patient_id>[0-9A-Fa-f-]+)/$', views.PatientDetails.as_view(), name='patient_details'),
url(r'^patient/update/(?P<patient_id>[0-9A-Fa-f-]+)/$', views.PatientUpdate.as_view(), name='patient_update'),
url(r'^patient/delete/(?P<patient_id>[0-9A-Fa-f-]+)/$', views.PatientDelete.as_view(), name='patient_delete'),
url(r'^patient/family-add/$', views.FamilyMemberAdd.as_view(), name='family_add'),
url(r'^patient/family-update/(?P<patient_id>[0-9A-Fa-f-]+)/(?P<family_member_id>[0-9]+)/$', views.FamilyMemberUpdate.as_view(), name='family_update'),
url(r'^patient/family-delete/(?P<patient_id>[0-9A-Fa-f-]+)/(?P<family_member_id>[0-9]+)/$', views.FamilyMemberDelete.as_view(), name='family_delete'),
url(r'^patient/family-detail/(?P<patient_id>[0-9A-Fa-f-]+)/(?P<family_member_id>[0-9]+)/$', views.FamilyMemberDetails.as_view(), name='family_detail'),
url(r'^patient/new-consultation/(?P<patient_id>[0-9A-Fa-f-]+)/$', views.PatientConsultationView.as_view(), name='patient_consultation'),
url(r'^patient/all-consultation/$', views.AllConsultationView.as_view(), name='all_patient_consultation'),
url(r'^patient/new-observation/(?P<consultation_id>[0-9]+)/(?P<patient_id>[0-9A-Fa-f-]+)/$', views.PatientObservationView.as_view(), name='patient_observation'),
]
【问题讨论】:
-
刚刚更新了网址...谢谢
标签: django python-2.7 django-forms django-templates django-views