Java源码示例:org.hl7.fhir.dstu3.model.Coding
示例1
private CodeableConcept inspectCode(CodeableConcept cc, Coding def) {
if (cc != null) {
for (Coding c : cc.getCoding()) {
if ("http://snomed.info/sct".equals(c.getSystem())) {
if ("ASSERTION".equals(c.getCode()))
c.setSystem("http://hl7.org/fhir/v3/ActCode");
}
if ("http://hl7.org/fhir/v3/ActCode".equals(c.getSystem()) && "ASSERTION".equals(c.getCode())) {
if (def == null)
throw new Error("need a default code");
c.setSystem(def.getSystem());
c.setVersion(def.getVersion());
c.setCode(def.getCode());
c.setDisplay(def.getDisplay());
}
}
}
return cc;
}
示例2
private void processSocialHistorySection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
scanSection("Social History", section);
int i = 0;
for (Element c : cda.getChildren(section, "entry")) {
Element o = cda.getChild(c, "observation");
Observation obs = new Observation();
obs.setId(context.baseId+"-smoking-"+(i == 0 ? "" : Integer.toString(i)));
obs.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/observation-daf-smokingstatus-dafsmokingstatus");
i++;
obs.setSubject(context.subjectRef);
obs.setContext(new Reference().setReference("Encounter/"+context.encounter.getId()));
obs.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "code")), new Coding().setSystem("http://loinc.org").setCode("72166-2")));
boolean found = false;
for (Element e : cda.getChildren(o, "id")) {
Identifier id = convert.makeIdentifierFromII(e);
obs.getIdentifier().add(convert.makeIdentifierFromII(e));
}
if (!found) {
obs.setStatus(ObservationStatus.FINAL);
obs.setEffective(convert.makeDateTimeFromTS(cda.getChild(o, "effectiveTime")));
obs.setValue(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "value")), null));
saveResource(obs, "-sh");
}
}
}
示例3
public Coding makeCodingFromCV(Element cd) throws Exception {
if (cd == null || Utilities.noString(cd.getAttribute("code")))
return null;
Coding c = new Coding();
c.setCode(cd.getAttribute("code"));
c.setDisplay(cd.getAttribute("displayName"));
String r = cd.getAttribute("codeSystem");
String uri = getUriForOID(r);
if (uri != null)
c.setSystem(uri);
else if (isGuid(r))
c.setSystem("urn:uuid:"+r);
else if (UriForOid(r) != null)
c.setSystem(UriForOid(r));
else
c.setSystem("urn:oid:"+r);
return c;
}
示例4
@Test
public void convertCondition20() throws IOException {
// condition format of HAPI FHIR 2.0
String oldContent = AllTests.getResourceAsString("/rsc/json/ConditionFormat20.json");
assertFalse(FindingsFormatUtil.isCurrentFindingsFormat(oldContent));
Optional<String> newContent = FindingsFormatUtil.convertToCurrentFindingsFormat(oldContent);
assertTrue(newContent.isPresent());
IBaseResource resource = AllTests.getJsonParser().parseResource(newContent.get());
assertTrue(resource instanceof Condition);
Condition condition = (Condition) resource;
// category changed from diagnosis to problem-list-item
List<CodeableConcept> category = condition.getCategory();
assertFalse(category.isEmpty());
CodeableConcept code = category.get(0);
List<Coding> coding = code.getCoding();
assertFalse(coding.isEmpty());
assertTrue(coding.get(0).getCode().equals(ConditionCategory.PROBLEMLISTITEM.getCode()));
// dateRecorded changed to assertedDate
Date assertedDate = condition.getAssertedDate();
assertNotNull(assertedDate);
}
示例5
@SuppressWarnings("rawtypes")
private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
if (tgt.getParameter().size() < 2)
return null;
Type p1 = tgt.getParameter().get(0).getValue();
Type p2 = tgt.getParameter().get(1).getValue();
if (p1 instanceof IdType || p2 instanceof IdType)
return null;
if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType))
return null;
String uri = ((PrimitiveType) p1).asStringValue();
String code = ((PrimitiveType) p2).asStringValue();
if (Utilities.noString(uri))
throw new FHIRException("Describe Transform, but the uri is blank");
if (Utilities.noString(code))
throw new FHIRException("Describe Transform, but the code is blank");
Coding c = buildCoding(uri, code);
return NarrativeGenerator.describeSystem(c.getSystem())+"#"+c.getCode()+(c.hasDisplay() ? "("+c.getDisplay()+")" : "");
}
示例6
public ConceptMap updateClosure(String name, Coding coding) {
Parameters params = new Parameters();
params.addParameter().setName("name").setValue(new StringType(name));
params.addParameter().setName("concept").setValue(coding);
List<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers);
result.addErrorStatus(410);//gone
result.addErrorStatus(404);//unknown
result.addErrorStatus(405);
result.addErrorStatus(422);//Unprocessable Entity
result.addSuccessStatus(200);
result.addSuccessStatus(201);
if(result.isUnsuccessfulRequest()) {
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
}
return (ConceptMap) result.getPayload();
}
示例7
private ValidationResult verifyCodeExternal(ValueSet vs, Coding coding, boolean tryCache)
throws Exception {
ValidationResult res = vs == null ? null : handleByCache(vs, coding, tryCache);
if (res != null) {
return res;
}
Parameters pin = new Parameters();
pin.addParameter().setName("coding").setValue(coding);
if (vs != null) {
pin.addParameter().setName("valueSet").setResource(vs);
}
res = serverValidateCode(pin, vs == null);
if (vs != null) {
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
cache.put(cacheId(coding), res);
}
return res;
}
示例8
@SuppressWarnings("rawtypes")
private String describeValidationParameters(Parameters pin) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (ParametersParameterComponent p : pin.getParameter()) {
if (p.hasValue() && p.getValue() instanceof PrimitiveType) {
b.append(p.getName() + "=" + ((PrimitiveType) p.getValue()).asStringValue());
} else if (p.hasValue() && p.getValue() instanceof Coding) {
b.append("system=" + ((Coding) p.getValue()).getSystem());
b.append("code=" + ((Coding) p.getValue()).getCode());
b.append("display=" + ((Coding) p.getValue()).getDisplay());
} else if (p.hasValue() && p.getValue() instanceof CodeableConcept) {
if (((CodeableConcept) p.getValue()).hasCoding()) {
Coding c = ((CodeableConcept) p.getValue()).getCodingFirstRep();
b.append("system=" + c.getSystem());
b.append("code=" + c.getCode());
b.append("display=" + c.getDisplay());
} else if (((CodeableConcept) p.getValue()).hasText()) {
b.append("text=" + ((CodeableConcept) p.getValue()).getText());
}
} else if (p.hasResource() && (p.getResource() instanceof ValueSet)) {
b.append("valueset=" + getVSSummary((ValueSet) p.getResource()));
}
}
return b.toString();
}
示例9
@Override
public ValidationResult validateCode(String system, String code, String display, ValueSet vs) {
try {
if (system == null && display == null) {
return verifyCodeInternal(vs, code);
}
if ((codeSystems.containsKey(system) && codeSystems.get(system) != null) || vs
.hasExpansion()) {
return verifyCodeInternal(vs, system, code, display);
} else {
return verifyCodeExternal(vs,
new Coding().setSystem(system).setCode(code).setDisplay(display), true);
}
} catch (Exception e) {
return new ValidationResult(IssueSeverity.FATAL,
"Error validating code \"" + code + "\" in system \"" + system + "\": " + e.getMessage(),
TerminologyServiceErrorClass.SERVER_ERROR);
}
}
示例10
public void setCategory(DomainResource resource, ObservationCategory category){
org.hl7.fhir.dstu3.model.Observation fhirObservation =
(org.hl7.fhir.dstu3.model.Observation) resource;
CodeableConcept categoryCode = new CodeableConcept();
if (category.name().startsWith("SOAP_")) {
// elexis soap categories
categoryCode.setCoding(
Collections.singletonList(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(),
category.getCode(), category.getLocalized())));
} else {
org.hl7.fhir.dstu3.model.codesystems.ObservationCategory fhirCategoryCode =
(org.hl7.fhir.dstu3.model.codesystems.ObservationCategory) categoryMapping
.getFhirEnumValueByEnum(category);
if (fhirCategoryCode != null) {
// lookup matching fhir category
categoryCode
.setCoding(Collections.singletonList(new Coding(fhirCategoryCode.getSystem(),
fhirCategoryCode.toCode(), fhirCategoryCode.getDisplay())));
} else {
throw new IllegalStateException("Unknown observation category " + category);
}
}
if (!categoryCode.getCoding().isEmpty()) {
fhirObservation.setCategory(Collections.singletonList(categoryCode));
}
}
示例11
@Override
public ConceptEntity findAddCode(Quantity quantity) {
Coding code = new Coding().setCode(quantity.getCode()).setSystem(quantity.getSystem());
ConceptEntity conceptEntity = findCode(code);
// 12/Jan/2018 KGM to cope with LOINC codes and depreciated SNOMED codes.
if (conceptEntity == null) {
CodeSystemEntity system = codeSystemRepository.findBySystem(quantity.getSystem());
if (system !=null) {
conceptEntity = new ConceptEntity();
conceptEntity.setCode(quantity.getCode());
conceptEntity.setDescription(quantity.getUnit());
conceptEntity.setDisplay(quantity.getUnit());
conceptEntity.setCodeSystem(system);
em.persist(conceptEntity);
} else {
throw new IllegalArgumentException("Unsupported system "+quantity.getSystem());
}
}
return conceptEntity;
}
示例12
/**
* Helper function to convert a Code into a CodeableConcept. Takes an optional system, which
* replaces the Code.system in the resulting CodeableConcept if not null.
*
* @param from The Code to create a CodeableConcept from.
* @param system The system identifier, such as a URI. Optional; may be null.
* @return The converted CodeableConcept
*/
private static CodeableConcept mapCodeToCodeableConcept(Code from, String system) {
CodeableConcept to = new CodeableConcept();
system = system == null ? null : ExportHelper.getSystemURI(system);
from.system = ExportHelper.getSystemURI(from.system);
if (from.display != null) {
to.setText(from.display);
}
Coding coding = new Coding();
coding.setCode(from.code);
coding.setDisplay(from.display);
if (from.system == null) {
coding.setSystem(system);
} else {
coding.setSystem(from.system);
}
to.addCoding(coding);
return to;
}
示例13
private void processClass(Element cls, Map<String, ConceptDefinitionComponent> concepts, CodeSystem define) throws FHIRFormatError {
ConceptDefinitionComponent concept = new ConceptDefinitionComponent();
concept.setCode(cls.getAttribute("code"));
concept.setDefinition(getRubric(cls, "preferred"));
String s = getRubric(cls, "shortTitle");
if (s != null && !s.equals(concept.getDefinition()))
concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("shortTitle")).setValue(s);
s = getRubric(cls, "inclusion");
if (s != null)
concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("inclusion")).setValue(s);
s = getRubric(cls, "exclusion");
if (s != null)
concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("exclusion")).setValue(s);
s = getRubric(cls, "criteria");
if (s != null)
concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("criteria")).setValue(s);
s = getRubric(cls, "consider");
if (s != null)
concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("consider")).setValue(s);
s = getRubric(cls, "note");
if (s != null)
concept.addDesignation().setUse(new Coding().setSystem("http://hl7.org/fhir/sid/icpc2/rubrics").setCode("note")).setValue(s);
concepts.put(concept.getCode(), concept);
List<Element> children = new ArrayList<Element>();
XMLUtil.getNamedChildren(cls, "SubClass", children);
if (children.size() > 0)
CodeSystemUtilities.setNotSelectable(define, concept);
Element parent = XMLUtil.getNamedChild(cls, "SuperClass");
if (parent == null) {
define.addConcept(concept);
} else {
ConceptDefinitionComponent p = concepts.get(parent.getAttribute("code"));
p.getConcept().add(concept);
}
}
示例14
public static void main(String[] args) {
try {
ArgonautConverter c = new ArgonautConverter(new UcumEssenceService(UCUM_PATH), Utilities.path(SRC_PATH, "validation.xml.zip"));
c.destFolder = "C:\\work\\com.healthintersections.fhir\\argonaut\\fhir";
c.convert("C:\\work\\com.healthintersections.fhir\\argonaut\\cda\\file_emergency", new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("EMER"));
c.convert("C:\\work\\com.healthintersections.fhir\\argonaut\\cda\\file_ed", new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("IMP"));
c.convert("C:\\work\\com.healthintersections.fhir\\argonaut\\cda\\fileX", new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("AMB"));
c.printSectionSummaries();
c.closeZips();
System.out.println("All done. "+Integer.toString(c.getErrors())+" errors, "+Integer.toString(c.getWarnings())+" warnings");
} catch (Exception e) {
e.printStackTrace();
}
}
示例15
private Coding convertTextToCoding(String v) {
v = v.toLowerCase();
if (v.equals("inpatient"))
return new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("IMP");
if (v.equals("emergency department") ||v.equals("emergency department admit decision"))
return new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("EMER");
if (v.equals("x-ray exam"))
return new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("AMB");
if (v.equals("outpatient"))
return new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("AMB");
throw new Error("unknown encounter type "+v);
}
示例16
private void count(Coding c, Map<String, Integer> map) {
String s = c.getSystem()+"::"+c.getCode();
if (map.containsKey(s))
map.put(s, map.get(s)+1);
else
map.put(s, 1);
}
示例17
public static Coding readAsCoding(Element item) {
Coding c = new Coding();
c.setSystem(item.getNamedChildValue("system"));
c.setVersion(item.getNamedChildValue("version"));
c.setCode(item.getNamedChildValue("code"));
c.setDisplay(item.getNamedChildValue("display"));
return c;
}
示例18
private CodeableConcept makeUnits(String text, String ucum) {
if (Utilities.noString(text) && Utilities.noString(ucum))
return null;
CodeableConcept cc = new CodeableConcept();
cc.setText(text);
cc.getCoding().add(new Coding().setCode(ucum).setSystem("http://unitsofmeasure.org"));
return cc;
}
示例19
protected void decorateCoding(Complex t, Coding element) {
if (!element.hasSystem())
return;
if ("http://snomed.info/sct".equals(element.getSystem())) {
t.prefix("sct", "http://snomed.info/sct/");
t.predicate("a", "sct:"+element.getCode());
} else if ("http://snomed.info/sct".equals(element.getSystem())) {
t.prefix("loinc", "http://loinc.org/rdf#");
t.predicate("a", "loinc:"+element.getCode());
}
}
示例20
private boolean hasDescription(Type fixed) {
if (fixed instanceof Coding) {
return ((Coding) fixed).hasDisplay();
} else if (fixed instanceof CodeableConcept) {
CodeableConcept cc = (CodeableConcept) fixed;
if (cc.hasText())
return true;
for (Coding c : cc.getCoding())
if (c.hasDisplay())
return true;
} // (fixed instanceof CodeType) || (fixed instanceof Quantity);
return false;
}
示例21
private String summariseCoding(Coding value) {
String uri = value.getSystem();
String system = NarrativeGenerator.describeSystem(uri);
if (Utilities.isURL(system)) {
if (system.equals("http://cap.org/protocols"))
system = "CAP Code";
}
return system+" "+value.getCode();
}
示例22
private List<Coding> mergeCodings(List<Coding> left, List<Coding> right) {
List<Coding> result = new ArrayList<Coding>();
result.addAll(left);
for (Coding c : right) {
boolean found = false;
for (Coding ct : left)
if (Utilities.equals(c.getSystem(), ct.getSystem()) && Utilities.equals(c.getCode(), ct.getCode()))
found = true;
if (!found)
result.add(c);
}
return result;
}
示例23
private Coding buildCoding(String uri, String code) throws FHIRException {
// if we can get this as a valueSet, we will
String system = null;
String display = null;
ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri);
if (vs != null) {
ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false);
if (vse.getError() != null)
throw new FHIRException(vse.getError());
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) {
if (t.hasCode())
b.append(t.getCode());
if (code.equals(t.getCode()) && t.hasSystem()) {
system = t.getSystem();
display = t.getDisplay();
break;
}
if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
system = t.getSystem();
display = t.getDisplay();
break;
}
}
if (system == null)
throw new FHIRException("The code '"+code+"' is not in the value set '"+uri+"' (valid codes: "+b.toString()+"; also checked displays)");
} else
system = uri;
ValidationResult vr = worker.validateCode(system, code, null);
if (vr != null && vr.getDisplay() != null)
display = vr.getDisplay();
return new Coding().setSystem(system).setCode(code).setDisplay(display);
}
示例24
public static void setExtension(Element focus, String url, Coding c) {
for (Extension e : focus.getExtension())
if (e.getUrl().equals(url)) {
e.setValue(c);
return;
}
focus.getExtension().add(new Extension().setUrl(url).setValue(c));
}
示例25
public static List<ICoding> getCodingsFromConcept(CodeableConcept codeableConcept){
ArrayList<ICoding> ret = new ArrayList<>();
List<Coding> coding = codeableConcept.getCoding();
for (Coding code : coding) {
ret.add(new CodingWrapper(code));
}
return ret;
}
示例26
private void renderCoding(Coding c, XhtmlNode x, boolean showCodeDetails) {
String s = "";
if (c.hasDisplayElement())
s = c.getDisplay();
if (Utilities.noString(s))
s = lookupCode(c.getSystem(), c.getCode());
if (Utilities.noString(s))
s = c.getCode();
if (showCodeDetails) {
x.addText(s+" (Details: "+describeSystem(c.getSystem())+" code "+c.getCode()+" = '"+lookupCode(c.getSystem(), c.getCode())+"', stated as '"+c.getDisplay()+"')");
} else
x.span(null, "{"+c.getSystem()+" "+c.getCode()+"}").addText(s);
}
示例27
private String getCodingReference(Coding cc, String system) {
if (cc.getSystem().equals(system))
return "#"+cc.getCode();
if (cc.getSystem().equals("http://snomed.info/sct"))
return "http://snomed.info/sct/"+cc.getCode();
if (cc.getSystem().equals("http://loinc.org"))
return "http://s.details.loinc.org/LOINC/"+cc.getCode()+".html";
return null;
}
示例28
public String genType(Type type) throws DefinitionException {
if (type instanceof Coding)
return gen((Coding) type);
if (type instanceof CodeableConcept)
return displayCodeableConcept((CodeableConcept) type);
if (type instanceof Quantity)
return displayQuantity((Quantity) type);
if (type instanceof Range)
return displayRange((Range) type);
return null;
}
示例29
private String gen(Extension extension) throws DefinitionException {
if (extension.getValue() instanceof CodeType)
return ((CodeType) extension.getValue()).getValue();
if (extension.getValue() instanceof Coding)
return gen((Coding) extension.getValue());
throw new DefinitionException("Unhandled type "+extension.getValue().getClass().getName());
}
示例30
public String gen(Coding code) {
if (code == null)
return null;
if (code.hasDisplayElement())
return code.getDisplay();
if (code.hasCodeElement())
return code.getCode();
return null;
}