"could not initialize proxy" When Creating a new Coded Concept with answers[SOLVED]

We need to create A Concept set and a coded Concept ,and constrain them to a given range of Concepts from ICD-10-WHO. ie concepts with a code that ranges between say C00.1 to C99.9

I have created the concept set and constrained to the above range of concepts using the logic below

public static Concept CreateWorkingDiagnosisConceptSet() {
		ConceptService service = Context.getConceptService();
		

		ConceptName name = new ConceptName(UCIOnchologyConstants.DIAGNOSIS_CONCEPT_SET_NAME, Locale.ENGLISH);
		
		Concept concept = new Concept();
		concept.addName(name);
		concept.addDescription(new ConceptDescription("Diagnosis For all ICD-0-3 Concepts", null));
		
		ConceptClass concept_class = service.getConceptClassByName("ConvSet");
		ConceptDatatype dataType = service.getConceptDatatypeByName("N/A");
		concept.setDatatype(dataType);
		concept.setConceptClass(concept_class);
		
		for (int i = 0; i < 100; i++) {
			for (int x = 0; x < 10; x += 1) {
				String var = i + "." + x;
				StringBuffer code = new StringBuffer("C00");
				if (var.length() <= 3) {
					code.replace(2, 4, var);
				} else {
					code.replace(1, 4, var);
				}
				
				try {
					Concept icd = service.getConceptByMapping(code.toString(),
					    UCIOnchologyConstants.DIAGNOSIS_CONCEPT_SOURCE);
					if (icd != null) {
						concept.addSetMember(icd);
					}
				}
				catch (Exception e) {
					
				}
			}
		}
		
		return service.saveConcept(concept);
	}

i have also tried out the same Logic to create a Coded Concept , and assign Concept anwers to it like

  public static Concept CreateWorkingDiagnosisConceptCoded() {
		ConceptService service = Context.getConceptService();
	
		ConceptName name = new ConceptName(UCIOnchologyConstants.DIAGNOSIS_CONCEPT, Locale.ENGLISH);
		
		Concept concept = new Concept();
		concept.addName(name);
		concept.addDescription(new ConceptDescription("Diagnosis For all ICD-0-3 Concepts", null));
		
		ConceptClass concept_class = service.getConceptClassByName("Diagnosis");
		ConceptDatatype dataType = service.getConceptDatatypeByName("Coded");
		concept.setDatatype(dataType);
		concept.setConceptClass(concept_class);
		
		for (int i = 0; i < 100; i++) {
			for (int x = 0; x < 10; x += 1) {
				String var = i + "." + x;
				StringBuffer code = new StringBuffer("C00");
				if (var.length() <= 3) {
					code.replace(2, 4, var);
				} else {
					code.replace(1, 4, var);
				}
				
				try {
					Concept icd = service.getConceptByMapping(code.toString(),
					    UCIOnchologyConstants.DIAGNOSIS_CONCEPT_SOURCE);
					if (icd != null) {
						ConceptAnswer ans = new ConceptAnswer(icd);
						concept.addAnswer(ans);
					}
				}
				catch (Exception e) {
					
				}
			}
		}
		
		return service.saveConcept(concept);
	} 

Note ,when i run a test unit against the above methods , the tests run well , and answers get assigned to the coded concept ,

However when i compile and run the code in an OpenMRS instance , the Concept Set gets created with the concepts assinged to the set , But the Coded Concept fails with the error below

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
full error below
https://pastebin.com/556GysyF

. I have failed to figure out why the hibernate session gets closed on assigning a concept Answer to a newly created concept,

could it be that A Coded concept has a limit on answers that can be assigned to it ??

Because in my case over 100 concepts have to be assigned as answers to this concept

cc @ibacher @dkayiwa

Is the module on github?

1 Like

sure its on github , https://github.com/UCI-BAHMNI/openmrs-module-uci/blob/master/api/src/main/java/org/openmrs/module/ucionchology/api/CreateDiagnosisConcepts.java

the “for” loops are basically for generating the the string codes between the given ranges

Your module loaded and started without errors, in my instance.

1 Like

yes it starts without errors and does all other functionalities , but it doesnt create the Coded concept “Working Cancer Diagnosis” ,which we want to constrain to all Cancer diagnosis concepts from ICD-10-WHO between C00.1 to C99.9 .

on trying to debug , i sorrouded that code with a try and catch and printed the error , like

final String DIAGNOSIS_CONCEPT_SOURCE = "ICD-10-WHO";
		final String DIAGNOSIS_CONCEPT_NAME = "Working Cancer Diagnosis";
		final String DIAGNOSIS_CONCEPT_UUID = "7c644f88-e2eb-4a44-8b52-c9b76018cb57";
		
		try {
			ConceptService service = Context.getConceptService();
			ConceptName name = new ConceptName(DIAGNOSIS_CONCEPT_NAME, Locale.ENGLISH);
			
			Concept concept = new Concept();
			concept.addName(name);
			concept.addDescription(new ConceptDescription("Diagnosis For all ICD-0-3 Concepts", Locale.ENGLISH));
			concept.setUuid(DIAGNOSIS_CONCEPT_UUID);
			
			ConceptClass concept_class = service.getConceptClassByName("Diagnosis");
			ConceptDatatype dataType = service.getConceptDatatypeByName("Coded");
			concept.setDatatype(dataType);
			concept.setConceptClass(concept_class);
			for (int i = 0; i < 100; i++) {
				for (int x = 0; x < 10; x += 1) {
					String var = i + "." + x;
					StringBuffer code = new StringBuffer("C00");
					if (var.length() <= 3) {
						code.replace(2, 4, var);
					} else {
						code.replace(1, 4, var);
					}
					
					try {
						Concept icd = service.getConceptByMapping(code.toString(), DIAGNOSIS_CONCEPT_SOURCE);
						if (icd != null) {
							ConceptAnswer ans = new ConceptAnswer(icd);
							concept.addAnswer(ans);
						}
					}
					catch (Exception e) {
						
					}
				}
			}
			
			service.saveConcept(concept);
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
1 Like

Why do you allow the module to start when it has not done the expected?

1 Like

sure thats true , but that was just work in progress

It could still fail in progress.

Can I ask why you are building the concept set in this way? Would it be better to have CIEL define the concept set fo you? Are the ICD-10-WHO codes the only definition of the set? The challenge you have is that those maps may change over time, so that you are not sure what set was actually being used in the past versus now. If you create a value set, you really should version it and label it for a given point in time and a given version of CIEL/ICD-10.

1 Like

@akanter , thats seemed to be the easier way to generate the set with less manual effort .

sure , does that mean this set will be created in CIEL in the next release ?

Other wise we will gladly welcome any help.

we basically want a Set and Coded concept constrained to Cancer Concepts (C00.0 - C99.9) ICD-10-WHO
We also want a Set and a Coded Concept constratined to Diagnosis Symptoms (R00.0 - R99.9) ICD-10-WHO

These indeed will be large sets. It almost seems like these would be better created as a Collection in OCL, but the challenge is that OCL for OMRS does not allow you to group together several collections into a new collection. It might be better to do this using the mapping table as you are doing in the short run, but can you let me know more about why you need this set? Are you creating a lookup list for a UI query, or is this for a report?

we are creating a cancer Diagnosis in take form ,

so we want the cancer diagnosis field , to be constrained to only cancer Diagnoses concepts ,

and also For the “Presenting Complaint” , we want to constrain the field to olny diagnosis Symptoms.

The most challenging part , it seems we would need it both as a set (for use in the < encounterDiagnoses > tag) and as a group of answers assigned to a single Coded Concept (for use in the < obs > tag)

Oh sorry , i think i have been mistaken , i actually dont need to create the Coded concept as above (it was the only throwing erros), i only need the Set , because i can use the set both directly in
< encounterDiagnoses> tag and also in the coded < obs > tag using the answerConceptSetIds atrribute to assign the concepts in the set to any simple coded concept.

:grinning:

so with that , Am unblocked :grinning: