|
2 | 2 |
|
3 | 3 | import org.bahmni.module.hip.Config; |
4 | 4 | import org.bahmni.module.hip.web.model.OpenMrsCondition; |
| 5 | +import org.hibernate.Hibernate; |
| 6 | +import org.hibernate.proxy.HibernateProxy; |
5 | 7 | import org.hl7.fhir.r4.model.DiagnosticReport; |
6 | 8 | import org.hl7.fhir.r4.model.Encounter; |
7 | 9 | import org.hl7.fhir.r4.model.CarePlan; |
|
25 | 27 | import org.openmrs.EncounterProvider; |
26 | 28 | import org.openmrs.Obs; |
27 | 29 | import org.openmrs.Order; |
| 30 | +import org.openmrs.Concept; |
28 | 31 | import org.openmrs.module.fhir2.api.translators.MedicationRequestTranslator; |
29 | 32 | import org.openmrs.module.fhir2.api.translators.MedicationTranslator; |
30 | 33 | import org.openmrs.module.fhir2.api.translators.PatientTranslator; |
@@ -216,6 +219,8 @@ public Condition mapToCondition(OpenMrsCondition openMrsCondition, Patient patie |
216 | 219 | } |
217 | 220 |
|
218 | 221 | public Observation mapToObs(Obs obs) { |
| 222 | + Concept concept = initializeEntityAndUnproxy(obs.getConcept()); |
| 223 | + obs.setConcept(concept); |
219 | 224 | return observationTranslator.toFhirResource(obs); |
220 | 225 | } |
221 | 226 |
|
@@ -266,4 +271,15 @@ public Medication mapToMedication(DrugOrder order) { |
266 | 271 | } |
267 | 272 | return medicationTranslator.toFhirResource(order.getDrug()); |
268 | 273 | } |
| 274 | + |
| 275 | + public static <T> T initializeEntityAndUnproxy(T entity) { |
| 276 | + if (entity == null) { |
| 277 | + throw new NullPointerException("Entity passed for initialization is null"); |
| 278 | + } |
| 279 | + Hibernate.initialize(entity); |
| 280 | + if (entity instanceof HibernateProxy) { |
| 281 | + entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation(); |
| 282 | + } |
| 283 | + return entity; |
| 284 | + } |
269 | 285 | } |
0 commit comments