Skip to content

Commit

Permalink
Merge pull request #1175 from usnistgov/feature/multiple-fixes-pre-de…
Browse files Browse the repository at this point in the history
…ployment

Feature/multiple fixes pre deployment
  • Loading branch information
Abdelghani90 authored Oct 22, 2020
2 parents da84702 + 2a18264 commit b2a5ce2
Show file tree
Hide file tree
Showing 58 changed files with 3,095 additions and 2,444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import ca.uhn.fhir.context.FhirContext;
import gov.nist.hit.hl7.igamt.bootstrap.data.CodeFixer;
import gov.nist.hit.hl7.igamt.bootstrap.data.ConformanceStatementFixer;
import gov.nist.hit.hl7.igamt.bootstrap.data.DynamicMappingFixer;
import gov.nist.hit.hl7.igamt.bootstrap.data.IgFixer;
import gov.nist.hit.hl7.igamt.bootstrap.data.TablesFixes;
import gov.nist.hit.hl7.igamt.bootstrap.factory.BindingCollector;
Expand Down Expand Up @@ -133,6 +135,8 @@ public static void main(String[] args) {

@Autowired
private PredicateRepository predicateRepository;
@Autowired
DynamicMappingFixer dynamicMappingFixer;

// @Autowired
// RelationShipService testCache;
Expand Down Expand Up @@ -176,6 +180,8 @@ public static void main(String[] args) {

@Autowired
ConformanceStatementFixer conformanceStatementFixer;
@Autowired
CodeFixer codeFixer;


@Bean
Expand Down Expand Up @@ -993,4 +999,14 @@ void fixConformanceStatements() throws IGUpdateException, CoConstraintGroupNotFo

}

// @PostConstruct
void addDynamicMappingInfo() {
codeFixer.fixTableHL70125();
dynamicMappingFixer.processSegments();
}

// @PostConstruct
void fixHl70125() throws FileNotFoundException {
codeFixer.fixFromCSV();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* This software was developed at the National Institute of Standards and Technology by employees of
* the Federal Government in the course of their official duties. Pursuant to title 17 Section 105
* of the United States Code this software is not subject to copyright protection and is in the
* public domain. This is an experimental system. NIST assumes no responsibility whatsoever for its
* use by other parties, and makes no guarantees, expressed or implied, about its quality,
* reliability, or any other characteristic. We would appreciate acknowledgement if the software is
* used. This software can be redistributed and/or modified freely provided that any derivative
* works bear some notice that they are derived from it, and any modified versions bear some notice
* that they have been modified.
*/
package gov.nist.hit.hl7.igamt.bootstrap.data;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;

import com.opencsv.CSVReader;

import gov.nist.hit.hl7.igamt.common.base.domain.Scope;
import gov.nist.hit.hl7.igamt.datatype.repository.DatatypeRepository;
import gov.nist.hit.hl7.igamt.valueset.domain.Valueset;
import gov.nist.hit.hl7.igamt.valueset.service.ValuesetService;

/**
* @author Abdelghani El Ouakili
*
*/
@Service
public class CodeFixer {

@Autowired
private DatatypeRepository datatypeRepository;

@Autowired
private ValuesetService valueSetService;

public void fixTableHL70125() {
List<Valueset> vss = valueSetService.findByDomainInfoScopeAndBindingIdentifier(Scope.HL7STANDARD.toString(), "HL70125");

for(Valueset vs: vss) {
vs.getCodes().removeIf((x) -> !datatypeRepository.existsByNameAndDomainInfoScopeAndDomainInfoVersion(x.getValue(), Scope.HL7STANDARD, vs.getDomainInfo().getVersion()));
vs.setNumberOfCodes(vs.getCodes().size());
valueSetService.save(vs);

}
}

public void fixFromCSV() throws FileNotFoundException {

File file = ResourceUtils.getFile("classpath:deprecatedCodes.csv");
System.out.println(file.exists());
CSVReader reader = null;
Map<String, Set<String>> map = new HashMap<String, Set<String>>();
try {
reader = new CSVReader(new FileReader(file));
String[] line1= reader.readNext();
while ((line1 = reader.readNext()) != null) {
String id = line1[1]+"V"+line1[0].replaceAll("\\.", "-");
if(map.containsKey(id)) {
Set<String> codes = map.get(id);
if(codes != null) {
codes.add(line1[2]);
}

}else {
Set<String> codes = new HashSet<String>();
codes.add(line1[2]);
map.put(id, codes);
}

}
fix(map);
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* @param map
*/
private void fix(Map<String, Set<String>> map) {
// TODO Auto-generated method stub
List<Valueset> valuesets= valueSetService.findByIdIn(map.keySet());

valuesets.forEach(x -> {
x.getCodes().forEach((c) -> {
if(map.get(x.getId()).contains(c.getValue())) {
c.setDeprecated(true);
}
});
valueSetService.save(x);
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* This software was developed at the National Institute of Standards and Technology by employees of
* the Federal Government in the course of their official duties. Pursuant to title 17 Section 105
* of the United States Code this software is not subject to copyright protection and is in the
* public domain. This is an experimental system. NIST assumes no responsibility whatsoever for its
* use by other parties, and makes no guarantees, expressed or implied, about its quality,
* reliability, or any other characteristic. We would appreciate acknowledgement if the software is
* used. This software can be redistributed and/or modified freely provided that any derivative
* works bear some notice that they are derived from it, and any modified versions bear some notice
* that they have been modified.
*/
package gov.nist.hit.hl7.igamt.bootstrap.data;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import gov.nist.hit.hl7.igamt.common.base.domain.Scope;
import gov.nist.hit.hl7.igamt.common.base.domain.ValuesetBinding;
import gov.nist.hit.hl7.igamt.common.binding.domain.StructureElementBinding;
import gov.nist.hit.hl7.igamt.datatype.domain.Datatype;
import gov.nist.hit.hl7.igamt.datatype.service.DatatypeService;
import gov.nist.hit.hl7.igamt.segment.domain.DynamicMappingInfo;
import gov.nist.hit.hl7.igamt.segment.domain.DynamicMappingItem;
import gov.nist.hit.hl7.igamt.segment.domain.Segment;
import gov.nist.hit.hl7.igamt.segment.service.SegmentService;
import gov.nist.hit.hl7.igamt.valueset.domain.Code;
import gov.nist.hit.hl7.igamt.valueset.domain.Valueset;
import gov.nist.hit.hl7.igamt.valueset.service.ValuesetService;

/**
* @author Abdelghani El Ouakili
*
*/
@Service
public class DynamicMappingFixer {

@Autowired
SegmentService segmentsService;

@Autowired
ValuesetService valueSetService;

@Autowired
DatatypeService datatypeService;


public void processSegments() {
List<Segment> obxs = segmentsService.findByName("OBX");
obxs.forEach((x) -> {processSegment(x);});
}


/**
* @param x
*/
private void processSegment(Segment s) {
// TODO Auto-generated method stub
s.setDynamicMappingInfo(new DynamicMappingInfo("2", "5", null));
String vsId = findObx2VsId(s);

if(vsId != null) {
Valueset vs = valueSetService.findById(vsId);
for(Code c : vs.getCodes()) {
if(c.getValue() !=null) {
Datatype d = datatypeService.findOneByNameAndVersionAndScope(c.getValue(),s.getDomainInfo().getVersion(), Scope.HL7STANDARD.toString());
if(d != null) {
s.getDynamicMappingInfo().addItem(new DynamicMappingItem(d.getId(), c.getValue()));
}
}
}
}
segmentsService.save(s);
}


/**
* @param s
* @return
*/
private String findObx2VsId(Segment s) {
// TODO Auto-generated method stub
if(s.getBinding() != null && s.getBinding().getChildren() != null) {
for(StructureElementBinding child : s.getBinding().getChildren()) {
if(child.getLocationInfo() != null && child.getLocationInfo().getPosition() ==2) {
if(child.getValuesetBindings() != null) {
Optional<ValuesetBinding> vs = child.getValuesetBindings().stream().findAny();
if(vs.isPresent() && vs.get().getValueSets() !=null && !vs.get().getValueSets().isEmpty()) {
return vs.get().getValueSets().get(0);
}

}
}
}
}

return null;
}


}
Loading

0 comments on commit b2a5ce2

Please sign in to comment.