fix: Patient History (Patient Medical Record) (#17972)

* Page - Patient History

* Healthcare Utils - get patient vitals

* Healthcare Utils - render doc as html for patient history page

* Page - Patient History -  prcatitioner image in time line

* Page - Patient History in menu

* fix - page medical history

* fix: page patient_history broken img, minor fixes

* fix: patient_history page, add pagination, show doc if fetched

* fix: Patient Medical Record to Patient History

* fix: patient history page - set route options

* fix: update to code standards

* fix: remove Eidt button form patient history

* fix: css update to code standards

* fix: Remove page medical_record
diff --git a/erpnext/healthcare/utils.py b/erpnext/healthcare/utils.py
index 6a226d9..97bb98f 100644
--- a/erpnext/healthcare/utils.py
+++ b/erpnext/healthcare/utils.py
@@ -429,3 +429,116 @@
 					occupancy_msg = str(occupied) + " Occupied out of " + str(occupancy_total)
 			each["occupied_out_of_vacant"] = occupancy_msg
 	return hc_service_units
+
+@frappe.whitelist()
+def get_patient_vitals(patient, from_date=None, to_date=None):
+	if not patient: return
+	vitals = frappe.db.sql("""select * from `tabVital Signs` where \
+	docstatus=1 and patient=%s order by signs_date, signs_time""", \
+	(patient), as_dict=1)
+	if vitals and vitals[0]:
+		return vitals
+	else:
+		return False
+
+@frappe.whitelist()
+def render_docs_as_html(docs):
+	# docs key value pair {doctype: docname}
+	docs_html = "<div class='col-md-12 col-sm-12 text-muted'>"
+	for doc in docs:
+		docs_html += render_doc_as_html(doc['doctype'], doc['docname'])['html'] + "<br/>"
+		return {'html': docs_html}
+
+@frappe.whitelist()
+def render_doc_as_html(doctype, docname, exclude_fields = []):
+	#render document as html, three column layout will break
+	doc = frappe.get_doc(doctype, docname)
+	meta = frappe.get_meta(doctype)
+	doc_html = "<div class='col-md-12 col-sm-12'>"
+	section_html = ""
+	section_label = ""
+	html = ""
+	sec_on = False
+	col_on = 0
+	has_data = False
+	for df in meta.fields:
+		#on section break append append previous section and html to doc html
+		if df.fieldtype == "Section Break":
+			if has_data and col_on and sec_on:
+				doc_html += section_html + html + "</div>"
+			elif has_data and not col_on and sec_on:
+				doc_html += "<div class='col-md-12 col-sm-12'\
+				><div class='col-md-12 col-sm-12'>" \
+				+ section_html + html +"</div></div>"
+			while col_on:
+				doc_html += "</div>"
+				col_on -= 1
+			sec_on = True
+			has_data= False
+			col_on = 0
+			section_html = ""
+			html = ""
+			if df.label:
+				section_label = df.label
+			continue
+		#on column break append html to section html or doc html
+		if df.fieldtype == "Column Break":
+			if sec_on and has_data:
+				section_html += "<div class='col-md-12 col-sm-12'\
+				><div class='col-md-6 col\
+				-sm-6'><b>" + section_label + "</b>" + html + "</div><div \
+				class='col-md-6 col-sm-6'>"
+			elif has_data:
+				doc_html += "<div class='col-md-12 col-sm-12'><div class='col-m\
+				d-6 col-sm-6'>" + html + "</div><div class='col-md-6 col-sm-6'>"
+			elif sec_on and not col_on:
+				section_html += "<div class='col-md-6 col-sm-6'>"
+			html = ""
+			col_on += 1
+			if df.label:
+				html += '<br>' + df.label
+			continue
+		#on table iterate in items and create table based on in_list_view, append to section html or doc html
+		if df.fieldtype == "Table":
+			items = doc.get(df.fieldname)
+			if not items: continue
+			child_meta = frappe.get_meta(df.options)
+			if not has_data : has_data = True
+			table_head = ""
+			table_row = ""
+			create_head = True
+			for item in items:
+				table_row += '<tr>'
+				for cdf in child_meta.fields:
+					if cdf.in_list_view:
+						if create_head:
+							table_head += '<th>' + cdf.label + '</th>'
+						if item.get(cdf.fieldname):
+							table_row += '<td>' + str(item.get(cdf.fieldname)) \
+							+ '</td>'
+						else:
+							table_row += '<td></td>'
+				create_head = False
+				table_row += '</tr>'
+			if sec_on:
+				section_html += '<table class="table table-condensed \
+				bordered">' + table_head +  table_row + '</table>'
+			else:
+				html += '<table class="table table-condensed table-bordered">' \
+				+ table_head +  table_row + '</table>'
+			continue
+		#on other field types add label and value to html
+		if not df.hidden and not df.print_hide and doc.get(df.fieldname) and df.fieldname not in exclude_fields:
+			html +=  "<br>{0} : {1}".format(df.label or df.fieldname, \
+			doc.get(df.fieldname))
+			if not has_data : has_data = True
+	if sec_on and col_on and has_data:
+		doc_html += section_html + html + "</div></div>"
+	elif sec_on and not col_on and has_data:
+		doc_html += "<div class='col-md-12 col-sm-12'\
+		><div class='col-md-12 col-sm-12'>" \
+		+ section_html + html +"</div></div>"
+	if doc_html:
+		doc_html = "<div class='small'><div class='col-md-12 text-right'><a class='btn btn-default btn-xs' href='#Form/%s/%s'></a></div>" %(doctype, docname) + doc_html + "</div>"
+
+	return {'html': doc_html}