Retrieve active Patient allergies from AllergyTable(Resolved)

Hello Friends, Am trying to work on Order Drug pharmacy module, however am kind of getting stuck ,i want to be able to fetch all patient allergies via single click from allergyTable within openmrs which i thought something like

Allergies allergies = patientService.getAllergies(patient);

and display them on existing page Hopefully this controller and view page , which seems to be working as expected however upon testing am encounting this error logs, not exactly sure what am missing out , kindly need your help thanks cc @ibacher @dkayiwa @k.joseph @mozzy

you need to have injected allergyService into your retrieving class!

1 Like

Thanks @k.joseph for suggestion, unfortunately trying to autowire allergy class which i think it inherits allergyService bean but that has not been of help .

how are u doing that?

Hello @k.joseph , Recently i had issues with allergyapi config becuase it couldnot be compatible with version of openmrs and immediately i disabled it from with in pom files, all things worked as expected expect this error so i think to cater for allergyService bean injection i need to depend on allergyapi module which i think its the cause . Let me first try that and see if it works thanks

Depending on allergyApi didnt help however it seems that (“allergyService”) PatientService patientService has got two kind of naming from different packages one from allergyApi and openmrs core @k.joseph is this part of the error, the challenge like how you said is that spring doesnt see allergyService class

<bean id="allergyService"
		<property name="transactionManager">
			<ref bean="transactionManager" />
		<property name="target">
			<bean class="${project.parent.groupId}.${project.parent.artifactId}.api.impl.PatientServiceImpl">
				<property name="dao">
					<bean class="${project.parent.groupId}.${project.parent.artifactId}.api.db.hibernate.HibernatePatientDAO">
						<property name="sessionFactory">
							<ref bean="sessionFactory" />
		<property name="preInterceptors">
			<ref bean="serviceInterceptors" />
		<property name="transactionAttributeSource">
			<ref bean="transactionAttributeSource" />
	<bean parent="serviceContext">
        <property name="moduleService">
            <list merge="true">
                <ref local="allergyService"/>

This should be the right bean to use but depending on allergyapi with same version causes similar error

@sharif Do you still have the allergyapi in your distro? It seems like if you’re moving to 2.x, you should drop the allergyapi module and just rely on the core PatientService class, so swap out:

@SpringBean("allergyService") PatientService patientService


@SpringBean("patientService") PatientService patientService

Thanks @ibacher, No i had removed allergyapi on distro and even as part of dependencies in order drugs module because it could throw errors, thanks let me try it out

Wow thanks @ibacher @k.joseph for your help changing to @springBean(“patientService”) PatientService patientService made it successfully , thanks again for your help