forked from Raxa/raxacore
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BS-68 | Create new REST endpoint for Diagnosis Search (#175)
* BS-68 | Siva Reddy | Create New Rest End Point for Diagnosis Search * BS-68 | Siva Reddy | Adding Test Cases for New Rest End Point * BS-68 | Siva Reddy | Updating Global Proerty Name * BS-68 | Siva Reddy | Adding terminology services dependency * BS-68 | Siva Reddy | Updated Rest End Point for Diagnosis Search * BS-68 | Siva Reddy | Publishing SNOMED specific Bahmnicore OMOD * BS-68 | Siva Reddy | Updated Dependencies from terminology services module * Siva Reddy | BS-68 | Updating Rest End Point, TS module dependencies * Siva Reddy | BS-68 | Update Package of FHIR TS module
- Loading branch information
1 parent
f5a20a3
commit bf3796b
Showing
9 changed files
with
339 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...nicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniDiagnosisService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
package org.bahmni.module.bahmnicore.service; | ||
|
||
import org.openmrs.Concept; | ||
import org.openmrs.ConceptSource; | ||
import org.openmrs.module.bahmniemrapi.diagnosis.contract.BahmniDiagnosisRequest; | ||
|
||
import java.text.ParseException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface BahmniDiagnosisService { | ||
void delete(String diagnosisObservationUuid); | ||
List<BahmniDiagnosisRequest> getBahmniDiagnosisByPatientAndVisit(String patientUuid,String visitUuid); | ||
List<BahmniDiagnosisRequest> getBahmniDiagnosisByPatientAndDate(String patientUuid, String date) throws ParseException; | ||
|
||
boolean isExternalTerminologyServerLookupNeeded(); | ||
|
||
Collection<Concept> getDiagnosisSets(); | ||
|
||
List<ConceptSource> getConceptSourcesForDiagnosisSearch(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
.../java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniConceptSearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package org.bahmni.module.bahmnicore.web.v1_0.controller; | ||
|
||
import org.apache.commons.lang3.LocaleUtils; | ||
import org.bahmni.module.bahmnicore.service.BahmniDiagnosisService; | ||
import org.bahmni.module.fhirterminologyservices.api.TerminologyLookupService; | ||
import org.openmrs.Concept; | ||
import org.openmrs.ConceptMap; | ||
import org.openmrs.ConceptName; | ||
import org.openmrs.ConceptReferenceTerm; | ||
import org.openmrs.ConceptSearchResult; | ||
import org.openmrs.ConceptSource; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.emrapi.concept.EmrConceptService; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.web.RestConstants; | ||
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; | ||
import org.openmrs.util.LocaleUtility; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
import static org.springframework.web.bind.annotation.ValueConstants.DEFAULT_NONE; | ||
|
||
@Controller | ||
@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/bahmni/terminologies") | ||
public class BahmniConceptSearchController extends BaseRestController { | ||
|
||
private BahmniDiagnosisService bahmniDiagnosisService; | ||
|
||
private EmrConceptService emrService; | ||
|
||
private TerminologyLookupService terminologyLookupService; | ||
|
||
@Autowired | ||
public BahmniConceptSearchController(BahmniDiagnosisService bahmniDiagnosisService, EmrConceptService emrService, TerminologyLookupService terminologyLookupService) { | ||
this.bahmniDiagnosisService = bahmniDiagnosisService; | ||
this.emrService = emrService; | ||
this.terminologyLookupService = terminologyLookupService; | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "concepts") | ||
@ResponseBody | ||
public Object search(@RequestParam("term") String query, @RequestParam Integer limit, | ||
@RequestParam(required = false, defaultValue = DEFAULT_NONE) String locale) throws Exception { | ||
boolean externalTerminologyServerLookupNeeded = bahmniDiagnosisService.isExternalTerminologyServerLookupNeeded(); | ||
if(externalTerminologyServerLookupNeeded) { | ||
return terminologyLookupService.getResponseList(query, limit, locale); | ||
} else { | ||
return getDiagnosisConcepts(query, limit, locale); | ||
} | ||
} | ||
|
||
private List<SimpleObject> getDiagnosisConcepts(String query, Integer limit, String locale) { | ||
Collection<Concept> diagnosisSets = bahmniDiagnosisService.getDiagnosisSets(); | ||
List<ConceptSource> conceptSources = bahmniDiagnosisService.getConceptSourcesForDiagnosisSearch(); | ||
Locale searchLocale = getSearchLocale(locale); | ||
List<ConceptSearchResult> conceptSearchResults = | ||
emrService.conceptSearch(query, LocaleUtility.getDefaultLocale(), null, diagnosisSets, conceptSources, limit); | ||
ConceptSource conceptSource = conceptSources.isEmpty() ? null: conceptSources.get(0); | ||
return createListResponse(conceptSearchResults, conceptSource, searchLocale); | ||
} | ||
|
||
private List<SimpleObject> createListResponse(List<ConceptSearchResult> resultList, | ||
ConceptSource conceptSource, Locale searchLocale) { | ||
List<SimpleObject> allDiagnoses = new ArrayList<>(); | ||
|
||
for (ConceptSearchResult diagnosis : resultList) { | ||
SimpleObject diagnosisObject = new SimpleObject(); | ||
ConceptName conceptName = diagnosis.getConcept().getName(searchLocale); | ||
if (conceptName == null) { | ||
conceptName = diagnosis.getConcept().getName(); | ||
} | ||
diagnosisObject.add("conceptName", conceptName.getName()); | ||
diagnosisObject.add("conceptUuid", diagnosis.getConcept().getUuid()); | ||
if(diagnosis.getConceptName()!=null) { | ||
diagnosisObject.add("matchedName", diagnosis.getConceptName().getName()); | ||
} | ||
ConceptReferenceTerm term = getConceptReferenceTermByConceptSource(diagnosis.getConcept(), conceptSource); | ||
if(term != null) { | ||
diagnosisObject.add("code", term.getCode()); | ||
} | ||
allDiagnoses.add(diagnosisObject); | ||
} | ||
return allDiagnoses; | ||
} | ||
|
||
private ConceptReferenceTerm getConceptReferenceTermByConceptSource(Concept concept, ConceptSource conceptSource) { | ||
Collection<ConceptMap> conceptMappings = concept.getConceptMappings(); | ||
if(conceptMappings != null && conceptSource != null) { | ||
for (ConceptMap cm : conceptMappings) { | ||
ConceptReferenceTerm term = cm.getConceptReferenceTerm(); | ||
if (conceptSource.equals(term.getConceptSource())) { | ||
return term; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private Locale getSearchLocale(String localeStr) { | ||
if (localeStr == null) { | ||
return Context.getLocale(); | ||
} | ||
Locale locale; | ||
try { | ||
locale = LocaleUtils.toLocale(localeStr); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException(localeErrorMessage("emrapi.conceptSearch.invalidLocale", localeStr)); | ||
} | ||
if (allowedLocale(locale)) { | ||
return locale; | ||
} else { | ||
throw new IllegalArgumentException(localeErrorMessage("emrapi.conceptSearch.unsupportedLocale", localeStr)); | ||
} | ||
} | ||
|
||
private boolean allowedLocale(Locale locale) { | ||
Set<Locale> allowedLocales = new HashSet<>(Context.getAdministrationService().getAllowedLocales()); | ||
return allowedLocales.contains(locale); | ||
} | ||
|
||
private String localeErrorMessage(String msgKey, String localeStr) { | ||
return Context.getMessageSourceService().getMessage(msgKey, new Object[] { localeStr }, Context.getLocale()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.