Ejemplo n.º 1
0
    def __processRecord(self, record, container=None):

        # Unlike property names, enforcing global ids for class types.
        #
        # Note - .title() turns PATIENT to Patient. Same is applied in .label
        # of fileInfo but iffy as each doing it independently.
        typeId = FileManInfo.normalizeLabel(record.fileTypeLabel.title(), False) + "-" + record.fileType

        # crecords
        if container != None:
            if self.__idTypeCNodes:  # can decide NOT to type/id cnodes
                resource = OrderedDict([("id", record.id), ("type", typeId)])
            else:
                resource = OrderedDict()
            container.append(resource)
            # NOTE: for JLD - could do @list to indicate order but decided not to
        else:
            resource = OrderedDict([("_id" if self.__useMongoResourceId else "id", record.id), ("type", typeId)])
            resource["label"] = record.label  # only tops get label (may remove)
            self.__json.append(resource)

        # can't use generic record iterator as it separates simple and contained fields
        for field in record.fields():

            qpred = self.__qpred(field, record)

            fieldInfo = record.fieldInfo(field)

            if fieldInfo[1] != "cnodes":  # TODO: encapsulate

                fv = self.__processFieldValue(qpred, record[field])

                # if invalid - skipping (None explicit as value could be <false>)
                if fv != None:
                    resource[qpred] = fv

                continue

            # Won't be bothered by CSTOPs!
            completeCRecords = [crecord for crecord in record[field] if crecord.isComplete]
            if not len(completeCRecords):
                continue
            list = []
            resource[qpred] = list
            for crecord in completeCRecords:
                # Apply Singleton Multiple Map
                cRecordTypeId = (
                    FileManInfo.normalizeLabel(crecord.fileTypeLabel.title(), False) + "-" + crecord.fileType
                )
                if cRecordTypeId in self.__listMultiples:
                    # Instead of implicit: record.isSimpleList(field):
                    # get one and only field name - usually matches field itself but
                    # not always ex/ CHCS 100251_1 has "lab_tests" with "lab_test"
                    ccfield = crecord.fields()[0]
                    cfv = self.__processFieldValue(qpred, crecord[ccfield])
                    if cfv:
                        list.append(cfv)
                    continue
                self.__processRecord(crecord, list)
Ejemplo n.º 2
0
 def calculatePropertyId():
     """
     Property name is unique in the file, lowercase 
     normalized (for JSON-LD etc) and in the context of the file
     (ie/ not unique across all files so must suffix with fileId)
         
     Note: only the quote and the equal sign are excluded, so anything, except " and = are acceptable BUT other schemes are stricter.
     """
     if self.__fieldInfo.isNLabelOwner: # Not just name owner but normalized name owner
         return FileManInfo.normalizeLabel(self.__fieldInfo.label) + "-" + self.__fieldInfo.fileId
     # Not owner so must add the fieldId as well as the fileId to the name!
     return FileManInfo.normalizeLabel(self.__fieldInfo.label) + "-" + self.__fieldInfo.id
Ejemplo n.º 3
0
 def calculatePropertyId():
     """
     Property name is unique in the file, lowercase 
     normalized (for JSON-LD etc) and in the context of the file
     (ie/ not unique across all files so must suffix with fileId)
         
     Note: only the quote and the equal sign are excluded, so anything, except " and = are acceptable BUT other schemes are stricter.
     """
     if self.__fieldInfo.isNLabelOwner:  # Not just name owner but normalized name owner
         return FileManInfo.normalizeLabel(
             self.__fieldInfo.label) + "-" + self.__fieldInfo.fileId
     # Not owner so must add the fieldId as well as the fileId to the name!
     return FileManInfo.normalizeLabel(
         self.__fieldInfo.label) + "-" + self.__fieldInfo.id
Ejemplo n.º 4
0
def loadFileManInfoFromCache(cacheLocation, name, fmType, description=""):
    # TODO: change to get name etc from about
    fis = []
    for replyFile in os.listdir(cacheLocation):
        if not re.search(r'SCHEMA\_', replyFile):
            continue
        reply = json.loads(open(cacheLocation + replyFile).read())
        fi = FileInfo(reply, fmType)
        fis.append(fi)
    fileManInfo = FileManInfo(fis, name, fmType, description)
    if fileManInfo.size == 0:
        raise Exception("No schemas in cache - exiting")
    return fileManInfo
Ejemplo n.º 5
0
 def id(self):    
     """
     ClassId, by default, is <upper case label - fileId>
     
     This and label can be reset in order to make cleaner models
     """
     try:
         return self.__explicitId
     except:
         """
         Represents a Class or Type id for JSON serialization. FMQL JSON is based on these
         ids.
     
         Patient/2 -> Patient-2 ie/ upper case unlike field names -> property names
         """
         return FileManInfo.normalizeLabel(self.__fileInfo.label, False) + "-" + self.__fileInfo.id
Ejemplo n.º 6
0
 def id(self):
     """
     ClassId, by default, is <upper case label - fileId>
     
     This and label can be reset in order to make cleaner models
     """
     try:
         return self.__explicitId
     except:
         """
         Represents a Class or Type id for JSON serialization. FMQL JSON is based on these
         ids.
     
         Patient/2 -> Patient-2 ie/ upper case unlike field names -> property names
         """
         return FileManInfo.normalizeLabel(self.__fileInfo.label,
                                           False) + "-" + self.__fileInfo.id