@Override public boolean isCodeSystemSupported(FhirContext theContext, String theSystem) { CodeSystem cs = fetchCodeSystem(theContext, theSystem); return cs != null && cs.getContent() != CodeSystemContentMode.NOTPRESENT; }
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); CodeSystem cs = (CodeSystem) theResource; if (cs != null && isNotBlank(cs.getUrl())) { String codeSystemUrl = cs.getUrl(); if (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == null) { ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", retVal.getIdDt().getValue(), cs.getContentElement().getValueAsString()); Long codeSystemResourcePid = retVal.getId(); TermCodeSystemVersion persCs = myCsvDao.findCurrentVersionForCodeSystemResourcePid(codeSystemResourcePid); if (persCs != null) { ourLog.info("Code system version already exists in database"); } else { persCs = new TermCodeSystemVersion(); persCs.setResource(retVal); persCs.getConcepts().addAll(toPersistedConcepts(cs.getConcept(), persCs)); ourLog.info("Code system has {} concepts", persCs.getConcepts().size()); myTerminologySvc.storeNewCodeSystemVersion(codeSystemResourcePid, codeSystemUrl, cs.getName(), persCs); } } } return retVal; }
private IIdType storeCodeSystem(RequestDetails theRequestDetails, final TermCodeSystemVersion theCodeSystemVersion, CodeSystem theCodeSystem, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) { Validate.isTrue(theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.NOTPRESENT); List<ValueSet> valueSets = ObjectUtils.defaultIfNull(theValueSets, Collections.emptyList()); List<ConceptMap> conceptMaps = ObjectUtils.defaultIfNull(theConceptMaps, Collections.emptyList()); IIdType retVal; myTermSvc.setProcessDeferred(false); if (myTermSvcDstu3 != null) { retVal = myTermSvcDstu3.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps); } else { retVal = myTermSvcR4.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps); } myTermSvc.setProcessDeferred(true); return retVal; }
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); CodeSystem cs = (CodeSystem) theResource; if (cs != null && isNotBlank(cs.getUrl())) { String codeSystemUrl = cs.getUrl(); if (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == null) { ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", retVal.getIdDt().getValue(), cs.getContentElement().getValueAsString()); Long codeSystemResourcePid = retVal.getId(); TermCodeSystemVersion persCs = myCsvDao.findCurrentVersionForCodeSystemResourcePid(codeSystemResourcePid); if (persCs != null) { ourLog.info("Code system version already exists in database"); } else { persCs = new TermCodeSystemVersion(); persCs.setResource(retVal); persCs.getConcepts().addAll(toPersistedConcepts(cs.getConcept(), persCs)); ourLog.info("Code system has {} concepts", persCs.getConcepts().size()); myTerminologySvc.storeNewCodeSystemVersion(codeSystemResourcePid, codeSystemUrl, cs.getName(), persCs); } } } return retVal; }
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, boolean heirarchical) throws ETooCostly, FileNotFoundException, IOException, FHIRException { inc.checkNoModifiers("Compose.include", "expanding"); List<ValueSet> imports = new ArrayList<ValueSet>(); for (UriType imp : inc.getValueSet()) { imports.add(importValueSet(imp.getValue(), params, expParams)); } if (!inc.hasSystem()) { if (imports.isEmpty()) // though this is not supposed to be the case return; ValueSet base = imports.get(0); imports.remove(0); base.checkNoModifiers("Imported ValueSet", "expanding"); copyImportContains(base.getExpansion().getContains(), null, expParams, imports); } else { CodeSystem cs = context.fetchCodeSystem(inc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE)) { doServerIncludeCodes(inc, heirarchical, params, imports, expParams); } else { doInternalIncludeCodes(inc, params, expParams, imports, cs); } } }
if (cs == null) throw new FHIRException("Unsupported system "+c.getSystem()+" - system is not specified or implicit"); if (cs.getContent() != CodeSystemContentMode.COMPLETE) throw new FHIRException("Unable to resolve system "+c.getSystem()+" - system is not complete"); ValidationResult res = validateCode(c, cs);
private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException { exc.checkNoModifiers("Compose.exclude", "expanding"); if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) { excludeSystems.add(exc.getSystem()); } if (exc.hasValueSet()) throw new Error("Processing Value set references in exclude is not yet done in "+ctxt); // importValueSet(imp.getValue(), params, expParams); CodeSystem cs = context.fetchCodeSystem(exc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) { ValueSetExpansionOutcome vse = context.expandVS(exc, false); ValueSet valueset = vse.getValueset(); if (valueset == null) throw new TerminologyServiceException("Error Expanding ValueSet: "+vse.getError()); excludeCodes(valueset.getExpansion(), params); return; } for (ConceptReferenceComponent c : exc.getConcept()) { excludeCode(exc.getSystem(), c.getCode()); } if (exc.getFilter().size() > 0) throw new NotImplementedException("not done yet"); }
private boolean inComponent(ConceptSetComponent vsi, String system, String code, boolean only) throws FHIRException { for (UriType uri : vsi.getValueSet()) { if (inImport(uri.getValue(), system, code)) return true; } if (!vsi.hasSystem()) return false; if (only && system == null) { // whether we know the system or not, we'll accept the stated codes at face value for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code)) return true; } if (!system.equals(vsi.getSystem())) return false; if (vsi.hasFilter()) throw new FHIRException("Filters - not done yet"); CodeSystem def = context.fetchCodeSystem(system); if (def.getContent() != CodeSystemContentMode.COMPLETE) throw new FHIRException("Unable to resolve system "+vsi.getSystem()+" - system is not complete"); List<ConceptDefinitionComponent> list = def.getConcept(); return validateCodeInConceptList(code, def, list); }
public ValidationResult validateCode(Coding code) throws FHIRException { // first, we validate the concept itself String system = code.hasSystem() ? code.getSystem() : getValueSetSystem(); if (system == null && !code.hasDisplay()) { // dealing with just a plain code (enum) system = systemForCodeInValueSet(code.getCode()); } CodeSystem cs = context.fetchCodeSystem(system); if (cs == null) throw new FHIRException("Unable to resolve system "+system+" - system is not specified or implicit"); if (cs.getContent() != CodeSystemContentMode.COMPLETE) throw new FHIRException("Unable to resolve system "+system+" - system is not complete"); ValidationResult res = validateCode(code, cs); // then, if we have a value set, we check it's in the value set if (res.isOk() && valueset != null && !codeInValueSet(system, code.getCode())) res.setMessage("Not in value set "+valueset.getUrl()).setSeverity(IssueSeverity.ERROR); return res; }
if (cs.getContent() != CodeSystemContentMode.COMPLETE) throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete"); if (cs.hasVersion())
@Override public boolean isCodeSystemSupported(FhirContext theContext, String theSystem) { CodeSystem cs = fetchCodeSystem(theContext, theSystem); return cs != null && cs.getContent() != CodeSystemContentMode.NOTPRESENT; }
private IIdType storeCodeSystem(RequestDetails theRequestDetails, final TermCodeSystemVersion theCodeSystemVersion, CodeSystem theCodeSystem, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) { Validate.isTrue(theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.NOTPRESENT); List<ValueSet> valueSets = ObjectUtils.defaultIfNull(theValueSets, Collections.emptyList()); List<ConceptMap> conceptMaps = ObjectUtils.defaultIfNull(theConceptMaps, Collections.emptyList()); IIdType retVal; myTermSvc.setProcessDeferred(false); if (myTermSvcDstu3 != null) { retVal = myTermSvcDstu3.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps); } else { retVal = myTermSvcR4.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps); } myTermSvc.setProcessDeferred(true); return retVal; }
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, boolean heirarchical) throws ETooCostly, FileNotFoundException, IOException, FHIRException { inc.checkNoModifiers("Compose.include", "expanding"); List<ValueSet> imports = new ArrayList<ValueSet>(); for (UriType imp : inc.getValueSet()) { imports.add(importValueSet(imp.getValue(), params, expParams)); } if (!inc.hasSystem()) { if (imports.isEmpty()) // though this is not supposed to be the case return; ValueSet base = imports.get(0); imports.remove(0); base.checkNoModifiers("Imported ValueSet", "expanding"); copyImportContains(base.getExpansion().getContains(), null, expParams, imports); } else { CodeSystem cs = context.fetchCodeSystem(inc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE)) { doServerIncludeCodes(inc, heirarchical, params, imports, expParams); } else { doInternalIncludeCodes(inc, params, expParams, imports, cs); } } }
if (cs == null) throw new FHIRException("Unsupported system "+c.getSystem()+" - system is not specified or implicit"); if (cs.getContent() != CodeSystemContentMode.COMPLETE) throw new FHIRException("Unable to resolve system "+c.getSystem()+" - system is not complete"); ValidationResult res = validateCode(c, cs);
private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException { exc.checkNoModifiers("Compose.exclude", "expanding"); if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) { excludeSystems.add(exc.getSystem()); } if (exc.hasValueSet()) throw new Error("Processing Value set references in exclude is not yet done in "+ctxt); // importValueSet(imp.getValue(), params, expParams); CodeSystem cs = context.fetchCodeSystem(exc.getSystem()); if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) { ValueSetExpansionOutcome vse = context.expandVS(exc, false); ValueSet valueset = vse.getValueset(); if (valueset == null) throw new TerminologyServiceException("Error Expanding ValueSet: "+vse.getError()); excludeCodes(valueset.getExpansion(), params); return; } for (ConceptReferenceComponent c : exc.getConcept()) { excludeCode(exc.getSystem(), c.getCode()); } if (exc.getFilter().size() > 0) throw new NotImplementedException("not done yet"); }
private boolean inComponent(ConceptSetComponent vsi, String system, String code, boolean only) throws FHIRException { for (UriType uri : vsi.getValueSet()) { if (inImport(uri.getValue(), system, code)) return true; } if (!vsi.hasSystem()) return false; if (only && system == null) { // whether we know the system or not, we'll accept the stated codes at face value for (ConceptReferenceComponent cc : vsi.getConcept()) if (cc.getCode().equals(code)) return true; } if (!system.equals(vsi.getSystem())) return false; if (vsi.hasFilter()) throw new FHIRException("Filters - not done yet"); CodeSystem def = context.fetchCodeSystem(system); if (def.getContent() != CodeSystemContentMode.COMPLETE) throw new FHIRException("Unable to resolve system "+vsi.getSystem()+" - system is not complete"); List<ConceptDefinitionComponent> list = def.getConcept(); return validateCodeInConceptList(code, def, list); }
if (src.hasVersionNeeded()) tgt.setVersionNeeded(src.getVersionNeeded()); tgt.setContent(convertCodeSystemContentMode(src.getContent())); if (src.hasCount()) tgt.setCount(src.getCount());
public ValidationResult validateCode(Coding code) throws FHIRException { // first, we validate the concept itself String system = code.hasSystem() ? code.getSystem() : getValueSetSystem(); if (system == null && !code.hasDisplay()) { // dealing with just a plain code (enum) system = systemForCodeInValueSet(code.getCode()); } CodeSystem cs = context.fetchCodeSystem(system); if (cs == null) throw new FHIRException("Unable to resolve system "+system+" - system is not specified or implicit"); if (cs.getContent() != CodeSystemContentMode.COMPLETE) throw new FHIRException("Unable to resolve system "+system+" - system is not complete"); ValidationResult res = validateCode(code, cs); // then, if we have a value set, we check it's in the value set if (res.isOk() && valueset != null && !codeInValueSet(system, code.getCode())) res.setMessage("Not in value set "+valueset.getUrl()).setSeverity(IssueSeverity.ERROR); return res; }
if (cs.getContent() != CodeSystemContentMode.COMPLETE) throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete"); if (cs.hasVersion())
if (src.hasVersionNeeded()) tgt.setVersionNeeded(src.getVersionNeeded()); tgt.setContent(convertCodeSystemContentMode(src.getContent())); if (src.hasCount()) tgt.setCount(src.getCount());