You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Extend medical providers to include more medicine-related values #1137
Currently medical providers contain only medicine names, disease names, hospitals, symptoms, diagnosis and procedure codes, medical professions. Since I'm working in healthcare space, I would like to leverage more providers for:
medicine codes (like RxNorm)
laboratory results codes (like LOINC)
anatomical sites
allergies
personal characteristics (eg. eye color, hair color)
I would be happy to help and start adding those by myself. Also, due to growing number of medical providers, I would consider extracting existing medical providers from net.datafaker.providers.base.Medical to dedicated net.datafaker.providers.medical.*, where we could have dedicated Medication, Diagnosis, Diagnostics etc..
changed the title [-]Extend medical providers to include more values for medicines[/-][+]Extend medical providers to include more medicine-related values[/+]on Mar 28, 2024
Hi @filipowm , great suggestion, we would absolutely appreciate a contribution from someone who has experience in the healthcare domain, so yes, a PR would be very welcome, and happy to help if you need it!
I started from moving around existing code to suit new structure (and grouping some stuff together), and I started thinking if it wouldn't be worthwhile to a bit "break" how providers are structured and make API more fluent, by providing here intermediate grouping provider.
Details below ↓
The idea
Logically group providers, in this case under healthcareproviders group there will be other providers related to medical stuff.
varmedicine = faker.healthcare().medication().drugName(); // well, it might be another long discussion about drug vs medicine ;-)varsymptom = faker.healthcare().condition().symptom();
varblood = faker.healthcare().blood().group();
Looking at the class diagram, it would simply be about adding grouping providers interface like HealthcareProvidersGroup, that Faker would implement. Treat this as a draft, cause there are still few things I would need to figure out.
classDiagram
Faker ..|> HealthcareProvidersGroup
HealthcareProvidersGroup --|> ProviderRegistration : I'm not sure if this implements would\n make sense here, cause it's just\n grouping of other ProviderRegistration(s)
HealthcareProviders --|> ProviderRegistration
HealthcareProviders --> HealthcareProvidersGroup
Blood --> HealthcareProviders
Medication --> HealthcareProviders
class ProviderRegistration {
<<interface>>
}
class Faker {
}
class HealthcareProvidersGroup {
<<interface>>
+healthcare() HealthcareProviders
}
class HealthcareProviders {
+blood() Blood
+medication() Medication
+...()
}
class Blood {
+group() String
+...()
}
class Medication {
+drugName() String
+...()
}
Loading
Pros & cons
Pros:
better logical grouping of providers, making them more focused and (imo) easier to find relevant ones for the user
potential for reusing provider names, but in different context, eg. Device in healthcare context is different than general Device and I would find it totally fine to have both, but in different contexts
would be a nice introduction to reworking and modularizing existing codebase (eg. grouping finance-related providers, entertainment)
From one side it could make to introduce a group like healthcare or Medical or something similar in case we have enough providers to put in it e.g. > 5.
From the other side I don't understand why should we have this method healthcare() ?
is shorter?
I don't see a benefit and it is hard to persuade people to write something longer if the result is same
Also there is another problem: such approach will break concistency between java api and expressions calls which could be used either in yaml files or in expression methods.
Moreover if you try to generate something 1000_000_000 times or more, you will see that this code
for (inti = 0; i < 1000_000_000; i++) {
varmedicine = faker.medication().drugName();
// whatever other code
}
is suboptimal because each time faker.medication() will lead to hashmap hash calculations.
I would assume that code with healthcare() would be even more suboptimal
more optimal way is something like
varmedication = faker.medication();
for (inti = 0; i < 1000_000_000; i++) {
varmedicine = medication.drugName();
// whatever other code
}
then hash will be calculated only once and it will be executed faster
Actually I see introducing healthcare() (and in future maybe other too) just a handy way to group related providers, and make it easier for users to find what they need, instead of scrolling through ever-growing number of providers. I came with that because I found quite a few new providers around health I would like to add. Right now it makes me a bit frustrated when I'm scrolling through providers under faker to find the relevant one, unless I exactly know what I'm looking for. So yes, it's convenience. The same way I could see introducing grouping for already existing entertainment, food, sport and videogame.
Could you explain more about the consistency you mentioned? Seems like this is something I am missing.
Also good point with the lookup to hashmap and hash calculation, yet in my opinion in scenarios where faker is used (mostly tests I bet) impact of hash calculation is negligible -- after that it will be just 2*O(1) to get the needed provider once it's in cache after first usage.
Same approach with caching providers could work when grouping is used:
varmedication = faker.medication(); // this one is taken from cachefor (inti = 0; i < 1000_000_000; i++) {
varmedicine = medication.drugName();
// whatever other code
}
would work same way as
varmedication = faker.healthcare().medication(); // both healthcare and medication will be taken from cache (I already investigated how to approach that and it's easily doable), but in this case it would be 3x lookupfor (inti = 0; i < 1000_000_000; i++) {
varmedicine = medication.drugName();
// whatever other code
}
So tl;dr; for me its mostly about convenience of usage, and necessarily not only for new users. Other benefits I mentioned are more of a side effect.
(and in future maybe other too) just a handy way to group related providers, and make it easier for users to find what they need, instead of scrolling through ever-growing number of providers.
For that reason there are SportFaker, FoodFaker and others which could be used in a way
varfaker = newSportFaker();
and then in autocompletion there will be only sport related providers or food related.
I would rather go this way and have something like
varfaker = newHealthCareFaker();
we can invoke java code via expressions like mentioned here https://www.datafaker.net/documentation/expressions/#options
and in most cases it is used in yaml configuration. There is an assumption that first there is provider name and then a method name. In case you try to use the construction with healthcare it will not work
Now I get it, thanks! I never used expressions so far, so here came my lack of knowledge 🙃 Certainly expressions would not work, and to make it work would require some changes in FakeValuesService, especially calculation of dotIndex (where there might be multiple for chained calls) and resolveFakerObjectAndMethod to allow chained methods like healthcare.medication.drugName.
Nice hint with dedicated faker instances, but if you need to use multiple (and it's at least how I use it), in my opinion it's anyway more convenient to work with single
Yet this somehow alleviates the need for stricter grouping.
I will move on with how it is now, but I will be happy to revisit grouping in future. If you would like to make that happen, you can count on my help. Thanks again @snuyanzin !
@filipowm thanks for your suggestions, they are certainly good ideas, but breaking the api a little bit is something we do with consideration, breaking the api a lot is something we generally try to avoid. We want to make it easy for people to adopt, and whether they come from Javafaker or a previous version of Datafaker, the migration is generally trivial.
I'm not sure if the proposed change brings the benefit of breaking the API at this moment. But don't let go of this idea, we can change our mind in the future!
but if you need to use multiple (and it's at least how I use it), in my opinion it's anyway more convenient to work with single
for that case there are interfaces BaseProviders, SportProviders, FoodProviders, EntertainmentProviders, VideoGameProviders and you can create a custom faker implementing only certain interfaces,
E.g. in case you need to have only HealthCare and Food you can create custom faker like
Activity
[-]Extend medical providers to include more values for medicines[/-][+]Extend medical providers to include more medicine-related values[/+]bodiam commentedon Mar 28, 2024
Hi @filipowm , great suggestion, we would absolutely appreciate a contribution from someone who has experience in the healthcare domain, so yes, a PR would be very welcome, and happy to help if you need it!
bodiam commentedon Mar 28, 2024
Ps: I'm also fine with moving things around, no problem!
filipowm commentedon Mar 29, 2024
Fantastic. So let me play around it a bit in upcoming days/weeks 😉
filipowm commentedon Mar 30, 2024
I started from moving around existing code to suit new structure (and grouping some stuff together), and I started thinking if it wouldn't be worthwhile to a bit "break" how providers are structured and make API more fluent, by providing here intermediate grouping provider.
Details below ↓
The idea
Logically group providers, in this case under
healthcareproviders group there will be other providers related to medical stuff.As-is
Example code how it works today:
To-be
The new API could look like this
Looking at the class diagram, it would simply be about adding grouping providers interface like
HealthcareProvidersGroup, thatFakerwould implement. Treat this as a draft, cause there are still few things I would need to figure out.classDiagram Faker ..|> HealthcareProvidersGroup HealthcareProvidersGroup --|> ProviderRegistration : I'm not sure if this implements would\n make sense here, cause it's just\n grouping of other ProviderRegistration(s) HealthcareProviders --|> ProviderRegistration HealthcareProviders --> HealthcareProvidersGroup Blood --> HealthcareProviders Medication --> HealthcareProviders class ProviderRegistration { <<interface>> } class Faker { } class HealthcareProvidersGroup { <<interface>> +healthcare() HealthcareProviders } class HealthcareProviders { +blood() Blood +medication() Medication +...() } class Blood { +group() String +...() } class Medication { +drugName() String +...() }Pros & cons
Pros:
Devicein healthcare context is different than generalDeviceand I would find it totally fine to have both, but in different contextsCons:
What do you think about that?
snuyanzin commentedon Mar 30, 2024
From one side it could make to introduce a group like
healthcareorMedicalor something similar in case we have enough providers to put in it e.g. > 5.From the other side I don't understand why should we have this method
healthcare()?Why people should write code
if
is shorter?
I don't see a benefit and it is hard to persuade people to write something longer if the result is same
Also there is another problem: such approach will break concistency between java api and expressions calls which could be used either in
yamlfiles or inexpressionmethods.Moreover if you try to generate something 1000_000_000 times or more, you will see that this code
is suboptimal because each time
faker.medication()will lead to hashmap hash calculations.I would assume that code with
healthcare()would be even more suboptimalmore optimal way is something like
then hash will be calculated only once and it will be executed faster
filipowm commentedon Mar 30, 2024
Thanks @snuyanzin for feedback.
Actually I see introducing
healthcare()(and in future maybe other too) just a handy way to group related providers, and make it easier for users to find what they need, instead of scrolling through ever-growing number of providers. I came with that because I found quite a few new providers around health I would like to add. Right now it makes me a bit frustrated when I'm scrolling through providers underfakerto find the relevant one, unless I exactly know what I'm looking for. So yes, it's convenience. The same way I could see introducing grouping for already existingentertainment,food,sportandvideogame.Could you explain more about the consistency you mentioned? Seems like this is something I am missing.
Also good point with the lookup to hashmap and hash calculation, yet in my opinion in scenarios where faker is used (mostly tests I bet) impact of hash calculation is negligible -- after that it will be just
2*O(1)to get the needed provider once it's in cache after first usage.Same approach with caching providers could work when grouping is used:
would work same way as
So tl;dr; for me its mostly about convenience of usage, and necessarily not only for new users. Other benefits I mentioned are more of a side effect.
snuyanzin commentedon Mar 30, 2024
For that reason there are
SportFaker,FoodFakerand others which could be used in a wayand then in autocompletion there will be only sport related providers or food related.
I would rather go this way and have something like
we can invoke java code via expressions like mentioned here https://www.datafaker.net/documentation/expressions/#options
and in most cases it is used in
yamlconfiguration. There is an assumption that first there is provider name and then a method name. In case you try to use the construction withhealthcareit will not workfilipowm commentedon Mar 30, 2024
Now I get it, thanks! I never used expressions so far, so here came my lack of knowledge 🙃 Certainly expressions would not work, and to make it work would require some changes in
FakeValuesService, especially calculation ofdotIndex(where there might be multiple for chained calls) andresolveFakerObjectAndMethodto allow chained methods likehealthcare.medication.drugName.Nice hint with dedicated faker instances, but if you need to use multiple (and it's at least how I use it), in my opinion it's anyway more convenient to work with single
instead of
Yet this somehow alleviates the need for stricter grouping.
I will move on with how it is now, but I will be happy to revisit grouping in future. If you would like to make that happen, you can count on my help. Thanks again @snuyanzin !
bodiam commentedon Mar 30, 2024
@filipowm thanks for your suggestions, they are certainly good ideas, but breaking the api a little bit is something we do with consideration, breaking the api a lot is something we generally try to avoid. We want to make it easy for people to adopt, and whether they come from Javafaker or a previous version of Datafaker, the migration is generally trivial.
I'm not sure if the proposed change brings the benefit of breaking the API at this moment. But don't let go of this idea, we can change our mind in the future!
snuyanzin commentedon Mar 31, 2024
for that case there are interfaces
BaseProviders,SportProviders,FoodProviders,EntertainmentProviders,VideoGameProvidersand you can create a custom faker implementing only certain interfaces,E.g. in case you need to have only
HealthCareandFoodyou can create custom faker likeafter that
and in autocompletion there will be both food and healthcare related methods
bodiam commentedon Apr 23, 2024
Closing this issue for now, but feel free to send a pull request for contributing medical fakers, that would be very appreciated.
feat: migrate part of existing medical provider under specific health…
feat: migrate disease provider under healthcare providers (datafaker-…