def resubmit(request, order_id): if request.user.is_authenticated(): order = Order.objects.get(id=order_id) required, optional = get_fields(hospital_id=order.hospital.id, disease_id=order.disease_id) type_list = [] for document in required + optional: if Document.object.filter(description=document, order=order, type=util.C2E_ORIGIN).count( ) == 0: # find which document is needed type_list.append(document) if request.method == 'POST': for type in type_list: if type in request.FILES is not None: file = request.FILES[type] document = Document(order=order, file=file, type=util.C2E_ORIGIN, descrpition=type) document.save() order.save() order.document_complete = True order.save() return redirect('info_order_detail', {'order_id': order_id}) else: return render(request, 'extra_doc.html') else: request.session['order_status'] = 'resubmit' return render(request, 'login.html', { 'form': LoginForm(), })
def add_doc(request, order_id): order_expire(order_id) customer = Customer.objects.get(user=request.user) order = Order.objects.get(id=order_id) if request.method == 'POST': form = DocAddForm(request.POST, request.FILES, instance=customer) if not form.is_valid(): return render(request, 'add_doc.html', { 'form': form, 'customer': customer, 'order': order, }) required, optional = get_fields(order.hospital.id, order.disease.id) for field in optional: for f in request.FILES.getlist(field): doc = Document(document=f, description=field, order=order, type=0) doc.save() return redirect('info_order_detail', order.id) return render( request, 'add_doc.html', { 'form': create_form(int(order.hospital.id), int(order.disease.id), DocAddForm(), only_optional=True), 'customer': customer, 'order': order, })
def order_document_info(request): order_id = request.session['order_id'] order_expire(order_id) if request.method == 'GET': order = Order.objects.get(id=order_id) customer = Customer.objects.get(user=request.user) appointment_form = AppointmentInfo(instance=order, initial={ 'hospital': order.hospital.name, 'hospital_address': order.hospital.area, 'time': order.submit, 'name': order.disease.name, 'diagnose_hospital': order.patient_order.diagnose_hospital if order.patient_order is not None else '', 'doctor': order.patient_order.doctor if order.patient_order is not None else '', 'contact': order.patient_order.contact if order.patient_order is not None else '', }) form = create_form(int(order.hospital.id), int(order.disease.id), appointment_form) return render(request, 'order_document_info.html', { 'customer': customer, 'form': form, 'time': (datetime.datetime.now(tz=pytz.utc) - order.submit).total_seconds(), 'documents': Document.objects.filter(order=order, type=0) }) else: order = Order.objects.get(id=order_id) customer = Customer.objects.get(user=request.user) form = AppointmentInfo(request.POST, request.FILES, instance=order) form = create_form(int(order.hospital.id), int(order.disease.id), form) if not form.is_valid(): return render(request, 'order_document_info.html', { 'form': form, 'customer': customer, 'time': (datetime.datetime.now(tz=pytz.utc) - order.submit).total_seconds(), 'documents': Document.objects.filter(order=order, type=0), }) required, optional = get_fields(order.hospital.id, order.disease.id) for field in required: for f in request.FILES.getlist(field): doc = Document(document=f, description=field, order=order, type=0) doc.save() for field in optional: for f in request.FILES.getlist(field): doc = Document(document=f, description=field, order=order, type=0) doc.save() all_documents = required + optional if all(Document.objects.filter(description=document, order=order, type=0).count() > 0 for document in all_documents): order.document_complete = True doctor = form.cleaned_data.get('doctor') hospital = form.cleaned_data.get('diagnose_hospital') contact = form.cleaned_data.get('contact') patient = order.patient_order patient.doctor = doctor patient.diagnose_hospital = hospital patient.contact = contact patient.save() order.status = -2 order.save() return redirect('order_review')
def clean(self): super(AppointmentInfo, self).clean() order = self.instance required, optional = get_fields(int(order.hospital.id), int(order.disease.id)) for doc in required: upload = self.cleaned_data[doc] documents = Document.objects.filter(type=0, order=order, description=doc) if upload is None and len(documents) <= 0: self.add_error(doc, '请填写这份必要的文件')
def assignment_summary(request, id, order_id): translator = Staff.objects.get(user_id=id) assignment = Order.objects.get(id=order_id) hospital = Hospital.objects.get(id=assignment.hospital_id) dynamic_form = Dynamic_Form.objects.get(hospital_id=hospital.id, disease_id=assignment.disease_id) types = dynamic_form.form types_list = [] required, optional = get_fields(hospital_id=hospital.id, disease_id=assignment.disease_id) if translator.get_role() == util.TRANS_C2E: origin_documents = Document.objects.filter(order_id=order_id, type=0) pending_documents = Document.objects.filter(order_id=order_id, type=1) types_list = filter(lambda x: x.isalpha(), re.split(r'[ ;|,\s]\s*', str(types))) if Document.objects.filter(order_id=order_id, description='answer').count() > 0: types_list.append('questionnaire') if translator.get_role() == util.TRANS_E2C: origin_documents = Document.objects.filter(order_id=order_id, type=3) pending_documents = Document.objects.filter(order_id=order_id, type=4) types_list = ['feedback'] if (request.POST.get('accept')): if translator.get_role() == 1: assignment.change_status(util.TRANSLATING_ORIGIN) assignment.change_trans_status(util.C2E_ONGOING) if translator.get_role() == 2: assignment.change_status(util.TRANSLATING_FEEDBACK) assignment.change_trans_status(util.E2C_ONGOING) assignment.save() if (request.POST.get('approval')): if translator.get_role() == 1: assignment.change_trans_status(util.C2E_APPROVING) if translator.get_role() == 2: assignment.change_trans_status(util.E2C_APPROVING) assignment.save() if (request.POST.get('finish')): if translator.get_role() == 1: assignment.change_trans_status(util.C2E_FINISHED) if translator.get_role() == 2: assignment.change_trans_status(util.E2C_FINISHED) assignment.save() if (request.POST.get('redo')): if translator.get_role() == 1: assignment.change_trans_status(util.C2E_ONGOING) if translator.get_role() == 2: assignment.change_trans_status(util.E2C_ONGOING) assignment.save() if (request.POST.get('upload')): for type in types_list: #print 'trans_files_' + type if 'trans_files_' + type in request.FILES is not None: file = request.FILES['trans_files_' + type] if translator.get_role() == util.TRANS_C2E: document = Document(order=assignment, document=file, type=util.C2E_PENDING, description='trans_files_' + type) # upload to pending documents if all( Document.objects.filter(description=document, order=assignment, type=0).count() > 0 for document in required + optional): assignment.document_complete = True assignment.save() assignment.document_complete = True if translator.get_role() == util.TRANS_E2C: document = Document(order=assignment, document=file, type=util.E2C_PENDING, description='trans_files_' + type) document.save() assignment.save() return render( request, 'assignment_summary.html', { 'origin_documents': origin_documents, 'pending_documents': pending_documents, 'translator': translator, 'assignment': assignment, 'types': types_list })