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