Dataviewjs I am a noob trying to group atomic notes of medical conditions by a specific diagnostic modality

What I’m trying to do

Using dataviewjs, create a list of tables that group each condition by diagnostic modality.

In the attached photo, I want the notes “leiomyoma (ml)” and “adenomyosis” to be grouped under a similar header “transabdominal UTZ”, and “adenomyosis” and “urethral diverticulum” to be grouped under a similar header “transvaginal UTZ”

Things I have tried

The code I used for the picture above is as follows:

let pages = dv.pages('"2023zettelkasten/23.07.30"')
let grps = pages.groupBy(p => p.dxVia)

for (let group of grps.sort(g => g.length, 'asc'))
{ 
	dv.header(3, dv.array(group.key).join(", ")); 
	dv.table(["Differential", "Condition", "Treatment"], group.rows .sort(k => k.file.ctime, 'ascending').map(k => [dv.span(k.differential), dv.header(3, k.file.link), dv.span(k.treatment)]))
} 

I do not have background with javascript and tried incorporating flatMap to get it to flatten the headers but I just end up with the flattened headers and no display. The “best attempt” I have achieved so far is this:

Which uses this code:

let pages = dv.pages('"2023zettelkasten/23.07.30"')
let dlabel = pages.flatMap(p => p.dxVia)
let grps = dlabel.groupBy(p => p)

for (let group of grps.sort(g => g.length, 'asc'))
{ 
	dv.header(3, dv.array(group.key).join(", ")); 
	dv.table(["Differential", "Condition", "Treatment"], group.rows.rows .sort(k => k.file.ctime, 'ascending').map(k => [dv.span(k.differential), dv.header(3, k.file.link), dv.span(k.treatment)]))
} 

Attached is a sample of the frontmatter for the notes leiomyoma (ml) and adenomyosis, respectively:

---
cause: [vitamin D deficiency, hypoxia leading to transformation of smooth muscle cell into myoma, familial tendency]
differential: [adenomyosis, pregnancy, ovarian mass, gestational trophoblastic diseases that cause globular uterus]
feature: "[[WIP - Relational databases as notes#Table 17 - Classification of leiomyoma]]"
location:
treatment:
riskFactor: [after menarche]
dxVia: [physical exam, transvaginal UTZ, transabdominal UTZ]
buzzwords: [most common benign tumor of muscular origin, benign monoclonal tumors of muscle cell origin, myoma, fibromyoma]
---

---
cause: null
differential: null
feature: [<i>endometrial</i> glands and stroma are present within the myometrium also]
location: null
treatment: [hysterectomy, medical management for pain and bleeding (Same as myoma)]
riskFactor:
dxVia: [transvaginal UTZ, transabdominal UTZ, MRI to differentiate from myoma]
buzzwords: null
---

Any insight and help is much appreciated :sweat_smile: :rofl: Cheers!

I have found the answer! For anyone who has a similar problem and would like a copy of the code, I just used this one and changed the variables :sweat_smile:

Cheers and hope this helps anyone who needs it~

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.