It sounds like you have some work to do clarifying your data architecture. If I were in your shoes, I would make sure that was all rock solid before trying to implementation in ERPNext.
In simple language, every DocType should represent a thing in the real world, usually either an entity (a patient, a drug, a hospital, a provider, etc.) or an event (a hospital visit, a prescription, a referral, etc.)
I don’t know enough about your desired workflow to say for certain, but I would assume that the relationship between Patients and Referrals is indeed one-to-many: each Patient (an entity) can have many different Referrals (an event), but each Referral always belongs to exactly one Patient. Presumably, Providers can each have multiple Referrals, too. If Patients only ever have one Referral, you might want to set this up a bit differently.
So, to answer your questions:
Nope, not quite. As a general rule, you don’t want to create “circular references”, where document A has a link field pointing to document B and document B has a link field pointing to document A. Instead, in the database:
- The Referrals should have a field pointing back to Patient (the many point to the one)
- The Patient should not have a field pointing to the Referrals (the one does not point to the many)
To get Referral references for Patient documents, you can use the “Linked Documents” section of either the doctype definition or the Customize Form tool. Referrals gets a field, documents doesn’t.
I think so, though I’m a little confused about the sequencing you want. Under normal circumstances, you create Patients first and then generate referrals for them (with links to Practitioners, presumably). If that’s the case, you can pass along as much or as little information from the patient doctype as you’d like. If you pass data to the referral doctype, it will get “baked in” however it was when created, remaining the same even if the Patient doctype changes in the future. Alternately, you can give Providers access to your Patient doctype. Like I said, this all just comes down to how you want to organize your data.
There are a few ways to do this, but the easiest is probably with Permission Queries via Server Scripts: