Skip to content

Extend medical providers to include more medicine-related values #1137

Closed

Description

@filipowm

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..

Activity

  1. 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
  2. bodiam commented on Mar 28, 2024

    @bodiam
    Contributor

    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!

  3. bodiam commented on Mar 28, 2024

    @bodiam
    Contributor

    Ps: I'm also fine with moving things around, no problem!

  4. filipowm commented on Mar 29, 2024

    @filipowm
    ContributorAuthor

    Fantastic. So let me play around it a bit in upcoming days/weeks 😉

  5. filipowm commented on Mar 30, 2024

    @filipowm
    ContributorAuthor

    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:

    var medicine = faker.medical().medicineName();
    var symptom = faker.medical().symptoms();
    var blood = faker.bloodtype().bloodGroup();

    To-be

    The new API could look like this

    var medicine = faker.healthcare().medication().drugName(); // well, it might be another long discussion about drug vs medicine ;-)
    var symptom = faker.healthcare().condition().symptom();
    var blood = 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)

    Cons:

    • breaks existing commonly used flat structure
    • well... more typing for the API consumer 😅

    What do you think about that?

  6. snuyanzin commented on Mar 30, 2024

    @snuyanzin
    Collaborator

    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() ?

    Why people should write code

    var medicine = faker.healthcare().medication().drugName(); 

    if

    var medicine = faker.medication().drugName(); 

    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 (int i = 0; i < 1000_000_000; i++) {
    var medicine = 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

    var medication = faker.medication();
    for (int i = 0; i < 1000_000_000; i++) {
    var medicine = medication.drugName(); 
    // whatever other code
    }

    then hash will be calculated only once and it will be executed faster

  7. filipowm commented on Mar 30, 2024

    @filipowm
    ContributorAuthor

    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 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:

    var medication = faker.medication(); // this one is taken from cache
    for (int i = 0; i < 1000_000_000; i++) {
       var medicine = medication.drugName();
       // whatever other code
    }

    would work same way as

    var medication = 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 lookup
    for (int i = 0; i < 1000_000_000; i++) {
       var medicine = 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.

  8. snuyanzin commented on Mar 30, 2024

    @snuyanzin
    Collaborator

    (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

    var faker = new SportFaker();

    and then in autocompletion there will be only sport related providers or food related.
    I would rather go this way and have something like

    var faker = new HealthCareFaker();

    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

  9. filipowm commented on Mar 30, 2024

    @filipowm
    ContributorAuthor

    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

    var faker = new Faker();

    instead of

    var sportFaker = new SportFaker();
    var healthcareFaker = new HealthCareFaker();

    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 !

  10. bodiam commented on Mar 30, 2024

    @bodiam
    Contributor

    @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!

  11. snuyanzin commented on Mar 31, 2024

    @snuyanzin
    Collaborator

    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

    public class MyCustomFaker extends BaseFaker implements FoodProviders, HealthCareProviders {
        public MyCustomFaker() {
        }
    
        public MyCustomFaker(Locale locale) {
            super(locale);
        }
    
        public MyCustomFaker(Random random) {
            super(random);
        }
    
        public MyCustomFaker(Locale locale, Random random) {
            super(locale, random);
        }
    
        public MyCustomFaker(Locale locale, RandomService randomService) {
            super(locale, randomService);
        }
    
        public MyCustomFaker(FakeValuesService fakeValuesService, FakerContext context) {
            super(fakeValuesService, context);
        }
    }

    after that

    var faker = new MyCustomFaker();

    and in autocompletion there will be both food and healthcare related methods

  12. bodiam commented on Apr 23, 2024

    @bodiam
    Contributor

    Closing this issue for now, but feel free to send a pull request for contributing medical fakers, that would be very appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions